diff --git a/.mailmap b/.mailmap index a50901cc11d6f..48772a771b43d 100644 --- a/.mailmap +++ b/.mailmap @@ -1,7 +1,7 @@ Adrian-Constantin Popescu Alex Blewitt -Alex Hoppen -Alex Hoppen +Alex Hoppen +Alex Hoppen Alexis Beingessner Alper Çugun Amr Aboelela diff --git a/CMakeLists.txt b/CMakeLists.txt index 18303183a6060..3d018d76484ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -148,7 +148,7 @@ set(SWIFT_ANALYZE_CODE_COVERAGE FALSE CACHE STRING # SWIFT_VERSION is deliberately /not/ cached so that an existing build directory # can be reused when a new version of Swift comes out (assuming the user hasn't # manually set it as part of their own CMake configuration). -set(SWIFT_VERSION "5.4") +set(SWIFT_VERSION "5.5") set(SWIFT_VENDOR "" CACHE STRING "The vendor name of the Swift compiler") @@ -196,13 +196,6 @@ if(SWIFT_PROFDATA_FILE AND EXISTS ${SWIFT_PROFDATA_FILE}) add_definitions("-fprofile-instr-use=${SWIFT_PROFDATA_FILE}") endif() -option(USE_SWIFT_ASYNC_LOWERING - "Indicates if Swiftc should use async-specific lowering for async - functions if it is supported for the target. The runtime also checks - this setting before using async-specific attributes. This only applies - to the async calling convention and not to the async context attribute." - TRUE) - # # User-configurable Swift Standard Library specific options. # diff --git a/docs/ABI/Mangling.rst b/docs/ABI/Mangling.rst index 218046be87805..6baabdb704fe8 100644 --- a/docs/ABI/Mangling.rst +++ b/docs/ABI/Mangling.rst @@ -147,6 +147,9 @@ Globals // TODO check this:: global ::= mangled-name 'TA' // partial application forwarder global ::= mangled-name 'Ta' // ObjC partial application forwarder + global ::= mangled-name 'Tw' index // async partial apply thunk for a non-constant function + global ::= mangled-name 'TQ' index // Async await continuation partial function + global ::= mangled-name 'TY' index // Async suspend continuation partial function global ::= type 'w' VALUE-WITNESS-KIND // value witness @@ -209,7 +212,7 @@ types where the metadata itself has unknown layout.) global ::= global 'TD' // dynamic dispatch thunk global ::= global 'Td' // direct method reference thunk global ::= global 'TI' // implementation of a dynamic_replaceable function - global :== global 'Tu' // async function pointer of a function + global ::= global 'Tu' // async function pointer of a function global ::= global 'TX' // function pointer of a dynamic_replaceable function global ::= entity entity 'TV' // vtable override thunk, derived followed by base global ::= type label-list? 'D' // type mangling for the debugger with label list for function types. diff --git a/include/swift/ABI/Executor.h b/include/swift/ABI/Executor.h index a35c5126ae314..41c63b30eec66 100644 --- a/include/swift/ABI/Executor.h +++ b/include/swift/ABI/Executor.h @@ -114,11 +114,11 @@ class ExecutorRef { using JobInvokeFunction = SWIFT_CC(swiftasync) - void (Job *, ExecutorRef); + void (Job *); using TaskContinuationFunction = SWIFT_CC(swiftasync) - void (AsyncTask *, ExecutorRef, SWIFT_ASYNC_CONTEXT AsyncContext *); + void (SWIFT_ASYNC_CONTEXT AsyncContext *); template class AsyncFunctionPointer; diff --git a/include/swift/ABI/Task.h b/include/swift/ABI/Task.h index 24b76eca44411..504970e82735e 100644 --- a/include/swift/ABI/Task.h +++ b/include/swift/ABI/Task.h @@ -87,13 +87,13 @@ class alignas(2 * alignof(void*)) Job : public HeapObject { /// Given that we've fully established the job context in the current /// thread, actually start running this job. To establish the context /// correctly, call swift_job_run or runJobInExecutorContext. - void runInFullyEstablishedContext(ExecutorRef currentExecutor); + void runInFullyEstablishedContext(); /// Given that we've fully established the job context in the /// current thread, and that the job is a simple (non-task) job, /// actually start running this job. - void runSimpleInFullyEstablishedContext(ExecutorRef currentExecutor) { - RunJob(this, currentExecutor); + void runSimpleInFullyEstablishedContext() { + RunJob(this); } }; @@ -193,8 +193,8 @@ class AsyncTask : public Job { /// in the current thread, start running this task. To establish /// the job context correctly, call swift_job_run or /// runInExecutorContext. - void runInFullyEstablishedContext(ExecutorRef currentExecutor) { - ResumeTask(this, currentExecutor, ResumeContext); + void runInFullyEstablishedContext() { + ResumeTask(ResumeContext); } /// Check whether this task has been cancelled. @@ -390,7 +390,7 @@ class AsyncTask : public Job { } /// Retrieve the error. - SwiftError *&getError() { return *&error; } + SwiftError *&getError() { return error; } /// Compute the offset of the storage from the base of the future /// fragment. @@ -433,7 +433,7 @@ class AsyncTask : public Job { /// /// Upon completion, any waiting tasks will be scheduled on the given /// executor. - void completeFuture(AsyncContext *context, ExecutorRef executor); + void completeFuture(AsyncContext *context); // ==== ---------------------------------------------------------------------- @@ -456,11 +456,11 @@ static_assert(sizeof(AsyncTask) == 14 * sizeof(void*), static_assert(alignof(AsyncTask) == 2 * alignof(void*), "AsyncTask alignment is wrong"); -inline void Job::runInFullyEstablishedContext(ExecutorRef currentExecutor) { +inline void Job::runInFullyEstablishedContext() { if (auto task = dyn_cast(this)) - task->runInFullyEstablishedContext(currentExecutor); + task->runInFullyEstablishedContext(); else - runSimpleInFullyEstablishedContext(currentExecutor); + runSimpleInFullyEstablishedContext(); } /// An asynchronous context within a task. Generally contexts are @@ -484,6 +484,7 @@ class alignas(MaximumAlignment) AsyncContext { ResumeParent; /// The executor that the parent needs to be resumed on. + /// FIXME: remove this ExecutorRef ResumeParentExecutor; /// Flags describing this context. @@ -496,10 +497,9 @@ class alignas(MaximumAlignment) AsyncContext { AsyncContext(AsyncContextFlags flags, TaskContinuationFunction *resumeParent, - ExecutorRef resumeParentExecutor, AsyncContext *parent) : Parent(parent), ResumeParent(resumeParent), - ResumeParentExecutor(resumeParentExecutor), + ResumeParentExecutor(ExecutorRef::generic()), Flags(flags) {} AsyncContext(const AsyncContext &) = delete; @@ -509,10 +509,10 @@ class alignas(MaximumAlignment) AsyncContext { /// /// Generally this should be tail-called. SWIFT_CC(swiftasync) - void resumeParent(AsyncTask *task, ExecutorRef executor) { + void resumeParent() { // TODO: destroy context before returning? // FIXME: force tail call - return ResumeParent(task, executor, Parent); + return ResumeParent(Parent); } }; @@ -529,11 +529,10 @@ class YieldingAsyncContext : public AsyncContext { YieldingAsyncContext(AsyncContextFlags flags, TaskContinuationFunction *resumeParent, - ExecutorRef resumeParentExecutor, TaskContinuationFunction *yieldToParent, ExecutorRef yieldToParentExecutor, AsyncContext *parent) - : AsyncContext(flags, resumeParent, resumeParentExecutor, parent), + : AsyncContext(flags, resumeParent, parent), YieldToParent(yieldToParent), YieldToParentExecutor(yieldToParentExecutor) {} @@ -550,19 +549,47 @@ class YieldingAsyncContext : public AsyncContext { /// futures. class FutureAsyncContext : public AsyncContext { public: - SwiftError **errorResult = nullptr; - OpaqueValue *indirectResult; - using AsyncContext::AsyncContext; }; -/// An asynchronous context within a task that describes a general "Future" -/// task that was started with a closure context. -class FutureClosureAsyncContext : public FutureAsyncContext { +/// This matches the ABI of a closure `() async throws -> ()` +using AsyncVoidClosureEntryPoint = + SWIFT_CC(swiftasync) + void (SWIFT_ASYNC_CONTEXT AsyncContext *, SWIFT_CONTEXT HeapObject *); + +/// This matches the ABI of a closure `() async throws -> T` +using AsyncGenericClosureEntryPoint = + SWIFT_CC(swiftasync) + void(OpaqueValue *, + SWIFT_ASYNC_CONTEXT AsyncContext *, SWIFT_CONTEXT HeapObject *); + +/// This matches the ABI of the resume function of a closure +/// `() async throws -> ()`. +using AsyncVoidClosureResumeEntryPoint = + SWIFT_CC(swiftasync) + void(SWIFT_ASYNC_CONTEXT AsyncContext *, SWIFT_CONTEXT SwiftError *); + +class AsyncContextPrefix { +public: + // Async closure entry point adhering to compiler calling conv (e.g directly + // passing the closure context instead of via the async context) + AsyncVoidClosureEntryPoint *__ptrauth_swift_task_resume_function + asyncEntryPoint; + HeapObject *closureContext; + SwiftError *errorResult; +}; + +/// Storage that is allocated before the AsyncContext to be used by an adapter +/// of Swift's async convention and the ResumeTask interface. +class FutureAsyncContextPrefix { public: + OpaqueValue *indirectResult; + // Async closure entry point adhering to compiler calling conv (e.g directly + // passing the closure context instead of via the async context) + AsyncGenericClosureEntryPoint *__ptrauth_swift_task_resume_function + asyncEntryPoint; HeapObject *closureContext; - - using FutureAsyncContext::FutureAsyncContext; + SwiftError *errorResult; }; } // end namespace swift diff --git a/include/swift/ABI/TaskGroup.h b/include/swift/ABI/TaskGroup.h index 9cb126e530c30..ed96780bd81de 100644 --- a/include/swift/ABI/TaskGroup.h +++ b/include/swift/ABI/TaskGroup.h @@ -38,7 +38,7 @@ class alignas(Alignment_TaskGroup) TaskGroup { void *PrivateData[NumWords_TaskGroup]; /// Upon a future task's completion, offer it to the task group it belongs to. - void offer(AsyncTask *completed, AsyncContext *context, ExecutorRef executor); + void offer(AsyncTask *completed, AsyncContext *context); }; } // end namespace swift diff --git a/tools/swift-api-digester/ModuleAnalyzerNodes.h b/include/swift/APIDigester/ModuleAnalyzerNodes.h similarity index 100% rename from tools/swift-api-digester/ModuleAnalyzerNodes.h rename to include/swift/APIDigester/ModuleAnalyzerNodes.h diff --git a/tools/swift-api-digester/ModuleDiagsConsumer.h b/include/swift/APIDigester/ModuleDiagsConsumer.h similarity index 100% rename from tools/swift-api-digester/ModuleDiagsConsumer.h rename to include/swift/APIDigester/ModuleDiagsConsumer.h diff --git a/include/swift/AST/ASTDemangler.h b/include/swift/AST/ASTDemangler.h index f3e055ccdb3ab..c789a4a2e4825 100644 --- a/include/swift/AST/ASTDemangler.h +++ b/include/swift/AST/ASTDemangler.h @@ -59,6 +59,8 @@ class ASTBuilder { using BuiltType = swift::Type; using BuiltTypeDecl = swift::GenericTypeDecl *; // nominal or type alias using BuiltProtocolDecl = swift::ProtocolDecl *; + using BuiltSubstitution = std::pair; + using BuiltRequirement = swift::Requirement; explicit ASTBuilder(ASTContext &ctx) : Ctx(ctx) {} ASTContext &getASTContext() { return Ctx; } @@ -99,11 +101,14 @@ class ASTBuilder { Type output, FunctionTypeFlags flags); Type createImplFunctionType( - Demangle::ImplParameterConvention calleeConvention, - ArrayRef> params, - ArrayRef> results, - Optional> errorResult, - ImplFunctionTypeFlags flags); + Demangle::ImplParameterConvention calleeConvention, + BuiltRequirement *witnessMethodConformanceRequirement, + ArrayRef GenericParameters, + ArrayRef Requirements, + ArrayRef> params, + ArrayRef> results, + Optional> errorResult, + ImplFunctionTypeFlags flags); Type createProtocolCompositionType(ArrayRef protocols, Type superclass, @@ -128,8 +133,6 @@ class ASTBuilder { Type createSILBoxType(Type base); using BuiltSILBoxField = llvm::PointerIntPair; - using BuiltSubstitution = std::pair; - using BuiltRequirement = swift::Requirement; using BuiltLayoutConstraint = swift::LayoutConstraint; Type createSILBoxTypeWithLayout(ArrayRef Fields, ArrayRef Substitutions, diff --git a/include/swift/AST/AnyFunctionRef.h b/include/swift/AST/AnyFunctionRef.h index 67e0c3523cecd..b2f5c02b10b51 100644 --- a/include/swift/AST/AnyFunctionRef.h +++ b/include/swift/AST/AnyFunctionRef.h @@ -179,12 +179,6 @@ class AnyFunctionRef { return TheFunction.dyn_cast(); } - bool isDeferBody() const { - if (auto *fd = dyn_cast_or_null(getAbstractFunctionDecl())) - return fd->isDeferBody(); - return false; - } - /// Return true if this closure is passed as an argument to a function and is /// known not to escape from that function. In this case, captures can be /// more efficient. diff --git a/include/swift/AST/Attr.h b/include/swift/AST/Attr.h index a452b8ae4c756..d738f5084701a 100644 --- a/include/swift/AST/Attr.h +++ b/include/swift/AST/Attr.h @@ -37,6 +37,7 @@ #include "swift/AST/Requirement.h" #include "swift/AST/StorageImpl.h" #include "swift/AST/TrailingCallArguments.h" +#include "llvm/ADT/iterator_range.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/ErrorHandling.h" @@ -47,6 +48,7 @@ namespace swift { class ASTPrinter; class ASTContext; struct PrintOptions; +class CustomAttr; class Decl; class AbstractFunctionDecl; class FuncDecl; @@ -58,133 +60,6 @@ class PatternBindingInitializer; class TrailingWhereClause; class TypeExpr; -/// TypeAttributes - These are attributes that may be applied to types. -class TypeAttributes { - // Get a SourceLoc for every possible attribute that can be parsed in source. - // the presence of the attribute is indicated by its location being set. - SourceLoc AttrLocs[TAK_Count]; -public: - /// AtLoc - This is the location of the first '@' in the attribute specifier. - /// If this is an empty attribute specifier, then this will be an invalid loc. - SourceLoc AtLoc; - - struct Convention { - StringRef Name = {}; - DeclNameRef WitnessMethodProtocol = {}; - Located ClangType = Located(StringRef(), {}); - /// Convenience factory function to create a Swift convention. - /// - /// Don't use this function if you are creating a C convention as you - /// probably need a ClangType field as well. - static Convention makeSwiftConvention(StringRef name) { - return {name, DeclNameRef(), Located("", {})}; - } - }; - - Optional ConventionArguments; - - // Indicates whether the type's '@differentiable' attribute has a 'linear' - // argument. - DifferentiabilityKind differentiabilityKind = - DifferentiabilityKind::NonDifferentiable; - - // For an opened existential type, the known ID. - Optional OpenedID; - - // For a reference to an opaque return type, the mangled name and argument - // index into the generic signature. - struct OpaqueReturnTypeRef { - StringRef mangledName; - unsigned index; - }; - Optional OpaqueReturnTypeOf; - - TypeAttributes() {} - - bool isValid() const { return AtLoc.isValid(); } - - void clearAttribute(TypeAttrKind A) { - AttrLocs[A] = SourceLoc(); - } - - bool has(TypeAttrKind A) const { - return getLoc(A).isValid(); - } - - SourceLoc getLoc(TypeAttrKind A) const { - return AttrLocs[A]; - } - - void setOpaqueReturnTypeOf(StringRef mangling, unsigned index) { - OpaqueReturnTypeOf = OpaqueReturnTypeRef{mangling, index}; - } - - void setAttr(TypeAttrKind A, SourceLoc L) { - assert(!L.isInvalid() && "Cannot clear attribute with this method"); - AttrLocs[A] = L; - } - - void getAttrLocs(SmallVectorImpl &Locs) const { - for (auto Loc : AttrLocs) { - if (Loc.isValid()) - Locs.push_back(Loc); - } - } - - // This attribute list is empty if no attributes are specified. Note that - // the presence of the leading @ is not enough to tell, because we want - // clients to be able to remove attributes they process until they get to - // an empty list. - bool empty() const { - for (SourceLoc elt : AttrLocs) - if (elt.isValid()) - return false; - - return true; - } - - bool hasConvention() const { return ConventionArguments.hasValue(); } - - /// Returns the primary calling convention string. - /// - /// Note: For C conventions, this may not represent the full convention. - StringRef getConventionName() const { - return ConventionArguments.getValue().Name; - } - - /// Show the string enclosed between @convention(..)'s parentheses. - /// - /// For example, @convention(foo, bar) will give the string "foo, bar". - void getConventionArguments(SmallVectorImpl &buffer) const; - - bool hasOwnership() const { - return getOwnership() != ReferenceOwnership::Strong; - } - ReferenceOwnership getOwnership() const { -#define REF_STORAGE(Name, name, ...) \ - if (has(TAK_sil_##name)) return ReferenceOwnership::Name; -#include "swift/AST/ReferenceStorage.def" - return ReferenceOwnership::Strong; - } - - void clearOwnership() { -#define REF_STORAGE(Name, name, ...) \ - clearAttribute(TAK_sil_##name); -#include "swift/AST/ReferenceStorage.def" - } - - bool hasOpenedID() const { return OpenedID.hasValue(); } - UUID getOpenedID() const { return *OpenedID; } - - /// Given a name like "autoclosure", return the type attribute ID that - /// corresponds to it. This returns TAK_Count on failure. - /// - static TypeAttrKind getAttrKindFromString(StringRef Str); - - /// Return the name (like "autoclosure") for an attribute ID. - static const char *getAttrName(TypeAttrKind kind); -}; - class alignas(1 << AttrAlignInBits) AttributeBase { public: /// The location of the '@'. @@ -229,6 +104,7 @@ enum class DeclKind : uint8_t; /// Represents one declaration attribute. class DeclAttribute : public AttributeBase { friend class DeclAttributes; + friend class TypeAttributes; protected: union { @@ -2409,6 +2285,170 @@ class DeclAttributes { SourceLoc getStartLoc(bool forModifiers = false) const; }; +/// TypeAttributes - These are attributes that may be applied to types. +class TypeAttributes { + // Get a SourceLoc for every possible attribute that can be parsed in source. + // the presence of the attribute is indicated by its location being set. + SourceLoc AttrLocs[TAK_Count]; + + /// The custom attributes, in a linked list. + CustomAttr *CustomAttrs = nullptr; + +public: + /// AtLoc - This is the location of the first '@' in the attribute specifier. + /// If this is an empty attribute specifier, then this will be an invalid loc. + SourceLoc AtLoc; + + struct Convention { + StringRef Name = {}; + DeclNameRef WitnessMethodProtocol = {}; + Located ClangType = Located(StringRef(), {}); + /// Convenience factory function to create a Swift convention. + /// + /// Don't use this function if you are creating a C convention as you + /// probably need a ClangType field as well. + static Convention makeSwiftConvention(StringRef name) { + return {name, DeclNameRef(), Located("", {})}; + } + }; + + Optional ConventionArguments; + + // Indicates whether the type's '@differentiable' attribute has a 'linear' + // argument. + DifferentiabilityKind differentiabilityKind = + DifferentiabilityKind::NonDifferentiable; + + // For an opened existential type, the known ID. + Optional OpenedID; + + // For a reference to an opaque return type, the mangled name and argument + // index into the generic signature. + struct OpaqueReturnTypeRef { + StringRef mangledName; + unsigned index; + }; + Optional OpaqueReturnTypeOf; + + TypeAttributes() {} + + bool isValid() const { return AtLoc.isValid(); } + + void clearAttribute(TypeAttrKind A) { + AttrLocs[A] = SourceLoc(); + } + + bool has(TypeAttrKind A) const { + return getLoc(A).isValid(); + } + + SourceLoc getLoc(TypeAttrKind A) const { + return AttrLocs[A]; + } + + void setOpaqueReturnTypeOf(StringRef mangling, unsigned index) { + OpaqueReturnTypeOf = OpaqueReturnTypeRef{mangling, index}; + } + + void setAttr(TypeAttrKind A, SourceLoc L) { + assert(!L.isInvalid() && "Cannot clear attribute with this method"); + AttrLocs[A] = L; + } + + void getAttrLocs(SmallVectorImpl &Locs) const { + for (auto Loc : AttrLocs) { + if (Loc.isValid()) + Locs.push_back(Loc); + } + } + + // This attribute list is empty if no attributes are specified. Note that + // the presence of the leading @ is not enough to tell, because we want + // clients to be able to remove attributes they process until they get to + // an empty list. + bool empty() const { + if (CustomAttrs) + return false; + + for (SourceLoc elt : AttrLocs) + if (elt.isValid()) + return false; + + return true; + } + + bool hasConvention() const { return ConventionArguments.hasValue(); } + + /// Returns the primary calling convention string. + /// + /// Note: For C conventions, this may not represent the full convention. + StringRef getConventionName() const { + return ConventionArguments.getValue().Name; + } + + /// Show the string enclosed between @convention(..)'s parentheses. + /// + /// For example, @convention(foo, bar) will give the string "foo, bar". + void getConventionArguments(SmallVectorImpl &buffer) const; + + bool hasOwnership() const { + return getOwnership() != ReferenceOwnership::Strong; + } + ReferenceOwnership getOwnership() const { +#define REF_STORAGE(Name, name, ...) \ + if (has(TAK_sil_##name)) return ReferenceOwnership::Name; +#include "swift/AST/ReferenceStorage.def" + return ReferenceOwnership::Strong; + } + + void clearOwnership() { +#define REF_STORAGE(Name, name, ...) \ + clearAttribute(TAK_sil_##name); +#include "swift/AST/ReferenceStorage.def" + } + + bool hasOpenedID() const { return OpenedID.hasValue(); } + UUID getOpenedID() const { return *OpenedID; } + + /// Given a name like "autoclosure", return the type attribute ID that + /// corresponds to it. This returns TAK_Count on failure. + /// + static TypeAttrKind getAttrKindFromString(StringRef Str); + + /// Return the name (like "autoclosure") for an attribute ID. + static const char *getAttrName(TypeAttrKind kind); + + void addCustomAttr(CustomAttr *attr) { + attr->Next = CustomAttrs; + CustomAttrs = attr; + } + + // Iterator for the custom type attributes. + class iterator + : public std::iterator { + CustomAttr *attr; + + public: + iterator() : attr(nullptr) { } + explicit iterator(CustomAttr *attr) : attr(attr) { } + + iterator &operator++() { + attr = static_cast(attr->Next); + return *this; + } + + bool operator==(iterator x) const { return x.attr == attr; } + bool operator!=(iterator x) const { return x.attr != attr; } + + CustomAttr *operator*() const { return attr; } + CustomAttr &operator->() const { return *attr; } + }; + + llvm::iterator_range getCustomAttrs() const { + return llvm::make_range(iterator(CustomAttrs), iterator()); + } +}; + void simple_display(llvm::raw_ostream &out, const DeclAttribute *attr); inline SourceLoc extractNearestSourceLoc(const DeclAttribute *attr) { diff --git a/include/swift/AST/DiagnosticsSIL.def b/include/swift/AST/DiagnosticsSIL.def index 2d7807da11f18..33fe0af27319b 100644 --- a/include/swift/AST/DiagnosticsSIL.def +++ b/include/swift/AST/DiagnosticsSIL.def @@ -103,8 +103,6 @@ ERROR(objc_selector_malformed,none,"the type ObjectiveC.Selector is malformed", // Capture before declaration diagnostics. ERROR(capture_before_declaration,none, "closure captures %0 before it is declared", (Identifier)) -ERROR(capture_before_declaration_defer,none, - "'defer' block captures %0 before it is declared", (Identifier)) NOTE(captured_value_declared_here,none, "captured value declared here", ()) diff --git a/include/swift/AST/DiagnosticsSema.def b/include/swift/AST/DiagnosticsSema.def index 47bb6ab8df33c..122ec4efcac15 100644 --- a/include/swift/AST/DiagnosticsSema.def +++ b/include/swift/AST/DiagnosticsSema.def @@ -3843,6 +3843,9 @@ ERROR(converting_noattrfunc_to_type,none, "may %select{allow it to escape|introduce data races}0", (unsigned, Type)) +ERROR(converting_func_loses_global_actor,none, + "converting function value of type %0 to %1 loses global actor %2", + (Type, Type, Type)) ERROR(capture_across_type_decl,none, "%0 declaration cannot close over value %1 defined in outer scope", (DescriptiveDeclKind, Identifier)) @@ -4499,10 +4502,6 @@ ERROR(global_actor_non_unsafe_init,none, ERROR(actor_isolation_multiple_attr,none, "%0 %1 has multiple actor-isolation attributes ('%2' and '%3')", (DescriptiveDeclKind, DeclName, StringRef, StringRef)) -ERROR(global_actor_isolated_synchronous_closure,none, - "closure isolated to global actor %0 must be 'async'", - (Type)) - ERROR(actor_isolation_override_mismatch,none, "%0 %1 %2 has different actor isolation from %3 overridden declaration", (ActorIsolation, DescriptiveDeclKind, DeclName, ActorIsolation)) @@ -5404,21 +5403,17 @@ ERROR(specialize_missing_where_clause,none, ERROR(specialize_empty_where_clause,none, "empty 'where' clause in '_specialize' attribute", ()) ERROR(specialize_attr_non_concrete_same_type_req,none, - "Only concrete type same-type requirements are supported by '_specialize' attribute", ()) + "only concrete type same-type requirements are supported by '_specialize' attribute", ()) ERROR(specialize_attr_only_generic_param_req,none, - "Only requirements on generic parameters are supported by '_specialize' attribute", ()) -ERROR(specialize_attr_only_one_concrete_same_type_req,none, - "Only one concrete type should be used in the same-type requirement in '_specialize' attribute", ()) -ERROR(specialize_attr_non_protocol_type_constraint_req,none, - "Only conformances to protocol types are supported by '_specialize' attribute", ()) + "only requirements on generic parameters are supported by '_specialize' attribute", ()) ERROR(specialize_attr_type_parameter_count_mismatch,none, - "%select{too many|too few}2 type parameters are specified " - "in '_specialize' attribute (got %1, but expected %0)", - (unsigned, unsigned, bool)) -ERROR(specialize_attr_missing_constraint,none, - "Missing constraint for %0 in '_specialize' attribute", (DeclName)) + "too few generic parameters are specified " + "in '_specialize' attribute (got %0, but expected %1)", + (unsigned, unsigned)) +NOTE(specialize_attr_missing_constraint,none, + "missing constraint for %0 in '_specialize' attribute", (DeclName)) ERROR(specialize_attr_unsupported_kind_of_req,none, - "Only same-type and layout requirements are supported by '_specialize' attribute", ()) + "only same-type and layout requirements are supported by '_specialize' attribute", ()) ERROR(specialize_target_function_not_found, none, "target function %0 could not be found", (DeclNameRef)) ERROR(specialize_target_function_of_type_not_found, none, diff --git a/include/swift/AST/ExtInfo.h b/include/swift/AST/ExtInfo.h index 4a17f5d33d628..c53f1c0e937fc 100644 --- a/include/swift/AST/ExtInfo.h +++ b/include/swift/AST/ExtInfo.h @@ -309,33 +309,38 @@ class ASTExtInfoBuilder { unsigned bits; // Naturally sized for speed. ClangTypeInfo clangTypeInfo; + Type globalActor; using Representation = FunctionTypeRepresentation; - ASTExtInfoBuilder(unsigned bits, ClangTypeInfo clangTypeInfo) - : bits(bits), clangTypeInfo(clangTypeInfo) {} + ASTExtInfoBuilder( + unsigned bits, ClangTypeInfo clangTypeInfo, Type globalActor + ) : bits(bits), clangTypeInfo(clangTypeInfo), globalActor(globalActor) {} public: /// An ExtInfoBuilder for a typical Swift function: @convention(swift), /// @escaping, non-throwing, non-differentiable. ASTExtInfoBuilder() : ASTExtInfoBuilder(Representation::Swift, false, false, - DifferentiabilityKind::NonDifferentiable, nullptr) {} + DifferentiabilityKind::NonDifferentiable, nullptr, + Type()) {} // Constructor for polymorphic type. ASTExtInfoBuilder(Representation rep, bool throws) : ASTExtInfoBuilder(rep, false, throws, - DifferentiabilityKind::NonDifferentiable, nullptr) {} + DifferentiabilityKind::NonDifferentiable, nullptr, + Type()) {} // Constructor with no defaults. ASTExtInfoBuilder(Representation rep, bool isNoEscape, bool throws, - DifferentiabilityKind diffKind, const clang::Type *type) + DifferentiabilityKind diffKind, const clang::Type *type, + Type globalActor) : ASTExtInfoBuilder( ((unsigned)rep) | (isNoEscape ? NoEscapeMask : 0) | (throws ? ThrowsMask : 0) | (((unsigned)diffKind << DifferentiabilityMaskOffset) & DifferentiabilityMask), - ClangTypeInfo(type)) {} + ClangTypeInfo(type), globalActor) {} void checkInvariants() const; @@ -374,6 +379,8 @@ class ASTExtInfoBuilder { return SILFunctionTypeRepresentation(rawRep); } + Type getGlobalActor() const { return globalActor; } + constexpr bool hasSelfParam() const { switch (getSILRepresentation()) { case SILFunctionTypeRepresentation::Thick: @@ -401,30 +408,32 @@ class ASTExtInfoBuilder { ASTExtInfoBuilder withRepresentation(Representation rep) const { return ASTExtInfoBuilder((bits & ~RepresentationMask) | (unsigned)rep, shouldStoreClangType(rep) ? clangTypeInfo - : ClangTypeInfo()); + : ClangTypeInfo(), + globalActor); } LLVM_NODISCARD ASTExtInfoBuilder withNoEscape(bool noEscape = true) const { return ASTExtInfoBuilder(noEscape ? (bits | NoEscapeMask) : (bits & ~NoEscapeMask), - clangTypeInfo); + clangTypeInfo, globalActor); } LLVM_NODISCARD ASTExtInfoBuilder withConcurrent(bool concurrent = true) const { return ASTExtInfoBuilder(concurrent ? (bits | ConcurrentMask) : (bits & ~ConcurrentMask), - clangTypeInfo); + clangTypeInfo, globalActor); } LLVM_NODISCARD ASTExtInfoBuilder withAsync(bool async = true) const { return ASTExtInfoBuilder(async ? (bits | AsyncMask) : (bits & ~AsyncMask), - clangTypeInfo); + clangTypeInfo, globalActor); } LLVM_NODISCARD ASTExtInfoBuilder withThrows(bool throws = true) const { return ASTExtInfoBuilder( - throws ? (bits | ThrowsMask) : (bits & ~ThrowsMask), clangTypeInfo); + throws ? (bits | ThrowsMask) : (bits & ~ThrowsMask), clangTypeInfo, + globalActor); } LLVM_NODISCARD ASTExtInfoBuilder @@ -432,11 +441,11 @@ class ASTExtInfoBuilder { return ASTExtInfoBuilder( (bits & ~DifferentiabilityMask) | ((unsigned)differentiability << DifferentiabilityMaskOffset), - clangTypeInfo); + clangTypeInfo, globalActor); } LLVM_NODISCARD ASTExtInfoBuilder withClangFunctionType(const clang::Type *type) const { - return ASTExtInfoBuilder(bits, ClangTypeInfo(type)); + return ASTExtInfoBuilder(bits, ClangTypeInfo(type), globalActor); } /// Put a SIL representation in the ExtInfo. @@ -449,16 +458,25 @@ class ASTExtInfoBuilder { withSILRepresentation(SILFunctionTypeRepresentation rep) const { return ASTExtInfoBuilder((bits & ~RepresentationMask) | (unsigned)rep, shouldStoreClangType(rep) ? clangTypeInfo - : ClangTypeInfo()); + : ClangTypeInfo(), + globalActor); + } + + LLVM_NODISCARD + ASTExtInfoBuilder withGlobalActor(Type globalActor) const { + return ASTExtInfoBuilder(bits, clangTypeInfo, globalActor); } bool isEqualTo(ASTExtInfoBuilder other, bool useClangTypes) const { return bits == other.bits && - (useClangTypes ? (clangTypeInfo == other.clangTypeInfo) : true); + (useClangTypes ? (clangTypeInfo == other.clangTypeInfo) : true) && + globalActor.getPointer() == other.globalActor.getPointer(); } - constexpr std::pair getFuncAttrKey() const { - return std::make_pair(bits, clangTypeInfo.getType()); + constexpr std::tuple + getFuncAttrKey() const { + return std::make_tuple( + bits, clangTypeInfo.getType(), globalActor.getPointer()); } }; // end ASTExtInfoBuilder @@ -479,8 +497,8 @@ class ASTExtInfo { // Only for use by ASTExtInfoBuilder::build. Don't use it elsewhere! ASTExtInfo(ASTExtInfoBuilder builder) : builder(builder) {} - ASTExtInfo(unsigned bits, ClangTypeInfo clangTypeInfo) - : builder(bits, clangTypeInfo) { + ASTExtInfo(unsigned bits, ClangTypeInfo clangTypeInfo, Type globalActor) + : builder(bits, clangTypeInfo, globalActor) { builder.checkInvariants(); }; @@ -524,6 +542,8 @@ class ASTExtInfo { constexpr bool hasContext() const { return builder.hasContext(); } + Type getGlobalActor() const { return builder.getGlobalActor(); } + /// Helper method for changing the representation. /// /// Prefer using \c ASTExtInfoBuilder::withRepresentation for chaining. @@ -564,11 +584,17 @@ class ASTExtInfo { return builder.withAsync(async).build(); } + LLVM_NODISCARD + ASTExtInfo withGlobalActor(Type globalActor) const { + return builder.withGlobalActor(globalActor).build(); + } + bool isEqualTo(ASTExtInfo other, bool useClangTypes) const { return builder.isEqualTo(other.builder, useClangTypes); } - constexpr std::pair getFuncAttrKey() const { + constexpr std::tuple + getFuncAttrKey() const { return builder.getFuncAttrKey(); } }; // end ASTExtInfo diff --git a/include/swift/AST/GenericSignatureBuilder.h b/include/swift/AST/GenericSignatureBuilder.h index b994e8e9f5c93..37da79a97abab 100644 --- a/include/swift/AST/GenericSignatureBuilder.h +++ b/include/swift/AST/GenericSignatureBuilder.h @@ -620,7 +620,8 @@ class GenericSignatureBuilder { /// generic signature builder no longer has valid state. GenericSignature computeGenericSignature( bool allowConcreteGenericParams = false, - bool allowBuilderToMove = true) &&; + bool buildingRequirementSignature = false, + bool rebuildingWithoutRedundantConformances = false) &&; /// Compute the requirement signature for the given protocol. static GenericSignature computeRequirementSignature(ProtocolDecl *proto); @@ -645,6 +646,8 @@ class GenericSignatureBuilder { private: void computeRedundantRequirements(); + bool hasExplicitConformancesImpliedByConcrete() const; + /// Describes the relationship between a given constraint and /// the canonical constraint of the equivalence class. enum class ConstraintRelation { @@ -1422,6 +1425,9 @@ class GenericSignatureBuilder::FloatingRequirementSource { /// Whether this is an explicitly-stated requirement. bool isExplicit() const; + /// Whether this is a derived requirement. + bool isDerived() const; + /// Whether this is a top-level requirement written in source. /// FIXME: This is a hack because expandConformanceRequirement() /// is too eager; we should remove this once we fix it properly. @@ -1431,9 +1437,8 @@ class GenericSignatureBuilder::FloatingRequirementSource { /// inferred. FloatingRequirementSource asInferred(const TypeRepr *typeRepr) const; - /// Whether this requirement source is recursive when composed with - /// the given type. - bool isRecursive(Type rootType, GenericSignatureBuilder &builder) const; + /// Whether this requirement source is recursive. + bool isRecursive(GenericSignatureBuilder &builder) const; }; /// Describes a specific constraint on a particular type. diff --git a/include/swift/AST/IRGenOptions.h b/include/swift/AST/IRGenOptions.h index 298eb8f8ff553..8980f0b48eca1 100644 --- a/include/swift/AST/IRGenOptions.h +++ b/include/swift/AST/IRGenOptions.h @@ -341,10 +341,6 @@ class IRGenOptions { /// Pointer authentication. PointerAuthOptions PointerAuth; - /// Use async-specific lowering for async functions if it is supported for - /// the target. - bool UseAsyncLowering = USE_SWIFT_ASYNC_LOWERING; - /// The different modes for dumping IRGen type info. enum class TypeInfoDumpFilter { All, diff --git a/include/swift/AST/Types.h b/include/swift/AST/Types.h index 0e2efd5a239fd..f36844646ffe7 100644 --- a/include/swift/AST/Types.h +++ b/include/swift/AST/Types.h @@ -348,12 +348,13 @@ class alignas(1 << TypeAlignInBits) TypeBase { Flags : NumFlagBits ); - SWIFT_INLINE_BITFIELD_FULL(AnyFunctionType, TypeBase, NumAFTExtInfoBits+1+1+16, + SWIFT_INLINE_BITFIELD_FULL(AnyFunctionType, TypeBase, NumAFTExtInfoBits+1+1+1+16, /// Extra information which affects how the function is called, like /// regparm and the calling convention. ExtInfoBits : NumAFTExtInfoBits, HasExtInfo : 1, HasClangTypeInfo : 1, + HasGlobalActor : 1, : NumPadBits, NumParams : 16 ); @@ -2933,6 +2934,8 @@ class AnyFunctionType : public TypeBase { Bits.AnyFunctionType.ExtInfoBits = Info.getValue().getBits(); Bits.AnyFunctionType.HasClangTypeInfo = !Info.getValue().getClangTypeInfo().empty(); + Bits.AnyFunctionType.HasGlobalActor = + !Info.getValue().getGlobalActor().isNull(); // The use of both assert() and static_assert() is intentional. assert(Bits.AnyFunctionType.ExtInfoBits == Info.getValue().getBits() && "Bits were dropped!"); @@ -2943,6 +2946,7 @@ class AnyFunctionType : public TypeBase { Bits.AnyFunctionType.HasExtInfo = false; Bits.AnyFunctionType.HasClangTypeInfo = false; Bits.AnyFunctionType.ExtInfoBits = 0; + Bits.AnyFunctionType.HasGlobalActor = false; } Bits.AnyFunctionType.NumParams = NumParams; assert(Bits.AnyFunctionType.NumParams == NumParams && "Params dropped!"); @@ -2985,9 +2989,15 @@ class AnyFunctionType : public TypeBase { return Bits.AnyFunctionType.HasClangTypeInfo; } + bool hasGlobalActor() const { + return Bits.AnyFunctionType.HasGlobalActor; + } + ClangTypeInfo getClangTypeInfo() const; ClangTypeInfo getCanonicalClangTypeInfo() const; + Type getGlobalActor() const; + /// Returns true if the function type stores a Clang type that cannot /// be derived from its Swift type. Returns false otherwise, including if /// the function type is not @convention(c) or @convention(block). @@ -3010,7 +3020,8 @@ class AnyFunctionType : public TypeBase { ExtInfo getExtInfo() const { assert(hasExtInfo()); - return ExtInfo(Bits.AnyFunctionType.ExtInfoBits, getClangTypeInfo()); + return ExtInfo(Bits.AnyFunctionType.ExtInfoBits, getClangTypeInfo(), + getGlobalActor()); } /// Get the canonical ExtInfo for the function type. @@ -3019,9 +3030,13 @@ class AnyFunctionType : public TypeBase { /// In the future, we will always use the canonical clang function type. ExtInfo getCanonicalExtInfo(bool useClangFunctionType) const { assert(hasExtInfo()); + Type globalActor = getGlobalActor(); + if (globalActor) + globalActor = globalActor->getCanonicalType(); return ExtInfo(Bits.AnyFunctionType.ExtInfoBits, useClangFunctionType ? getCanonicalClangTypeInfo() - : ClangTypeInfo()); + : ClangTypeInfo(), + globalActor); } bool hasSameExtInfoAs(const AnyFunctionType *otherFn); @@ -3236,7 +3251,7 @@ class FunctionType final : public AnyFunctionType, public llvm::FoldingSetNode, private llvm::TrailingObjects { + ClangTypeInfo, Type> { friend TrailingObjects; @@ -3248,6 +3263,10 @@ class FunctionType final return hasClangTypeInfo() ? 1 : 0; } + size_t numTrailingObjects(OverloadToken) const { + return hasGlobalActor() ? 1 : 0; + } + public: /// 'Constructor' Factory Function static FunctionType *get(ArrayRef params, Type result, @@ -3267,6 +3286,12 @@ class FunctionType final return *info; } + Type getGlobalActor() const { + if (!hasGlobalActor()) + return Type(); + return *getTrailingObjects(); + } + void Profile(llvm::FoldingSetNodeID &ID) { Optional info = None; if (hasExtInfo()) @@ -3345,11 +3370,20 @@ std::string getParamListAsString(ArrayRef parameters); /// generic parameters. class GenericFunctionType final : public AnyFunctionType, public llvm::FoldingSetNode, - private llvm::TrailingObjects { + private llvm::TrailingObjects { friend TrailingObjects; GenericSignature Signature; + size_t numTrailingObjects(OverloadToken) const { + return getNumParams(); + } + + size_t numTrailingObjects(OverloadToken) const { + return hasGlobalActor() ? 1 : 0; + } + /// Construct a new generic function type. GenericFunctionType(GenericSignature sig, ArrayRef params, @@ -3357,7 +3391,7 @@ class GenericFunctionType final : public AnyFunctionType, Optional info, const ASTContext *ctx, RecursiveTypeProperties properties); - + public: /// Create a new generic function type. static GenericFunctionType *get(GenericSignature sig, @@ -3369,7 +3403,13 @@ class GenericFunctionType final : public AnyFunctionType, ArrayRef getParams() const { return {getTrailingObjects(), getNumParams()}; } - + + Type getGlobalActor() const { + if (!hasGlobalActor()) + return Type(); + return *getTrailingObjects(); + } + /// Retrieve the generic signature of this function type. GenericSignature getGenericSignature() const { return Signature; diff --git a/include/swift/Config.h.in b/include/swift/Config.h.in index c414f682e4866..b4e46a98b7b79 100644 --- a/include/swift/Config.h.in +++ b/include/swift/Config.h.in @@ -8,6 +8,4 @@ #cmakedefine HAVE_PROC_PID_RUSAGE 1 -#cmakedefine01 USE_SWIFT_ASYNC_LOWERING - #endif // SWIFT_CONFIG_H diff --git a/include/swift/Demangling/DemangleNodes.def b/include/swift/Demangling/DemangleNodes.def index 4a5e96213d4a5..10840749ddc63 100644 --- a/include/swift/Demangling/DemangleNodes.def +++ b/include/swift/Demangling/DemangleNodes.def @@ -316,6 +316,9 @@ NODE(AutoDiffSubsetParametersThunk) NODE(AutoDiffDerivativeVTableThunk) NODE(DifferentiabilityWitness) NODE(IndexSubset) +NODE(AsyncNonconstantPartialApplyThunk) +NODE(AsyncAwaitResumePartialFunction) +NODE(AsyncSuspendResumePartialFunction) #undef CONTEXT_NODE #undef NODE diff --git a/include/swift/Demangling/TypeDecoder.h b/include/swift/Demangling/TypeDecoder.h index 22a0e11697b87..4e537cbc11dad 100644 --- a/include/swift/Demangling/TypeDecoder.h +++ b/include/swift/Demangling/TypeDecoder.h @@ -799,9 +799,12 @@ class TypeDecoder { } case NodeKind::ImplFunctionType: { auto calleeConvention = ImplParameterConvention::Direct_Unowned; + BuiltRequirement *witnessMethodConformanceRequirement = nullptr; llvm::SmallVector, 8> parameters; llvm::SmallVector, 8> results; llvm::SmallVector, 8> errorResults; + llvm::SmallVector genericParameters; + llvm::SmallVector requirements; ImplFunctionTypeFlags flags; for (unsigned i = 0; i < Node->getNumChildren(); i++) { @@ -834,6 +837,9 @@ class TypeDecoder { } else if (text == "block") { flags = flags.withRepresentation(ImplFunctionRepresentation::Block); + } else if (text == "witness_method") { + flags = flags.withRepresentation( + ImplFunctionRepresentation::WitnessMethod); } } else if (child->getKind() == NodeKind::ImplFunctionAttribute) { if (!child->hasText()) @@ -871,6 +877,27 @@ class TypeDecoder { if (decodeImplFunctionPart(child, errorResults)) return MAKE_NODE_TYPE_ERROR0(child, "failed to decode function part"); + } else if (child->getKind() == NodeKind::DependentGenericSignature) { + llvm::SmallVector genericParamsAtDepth; + + if (auto error = decodeDependentGenericSignatureNode( + child, requirements, genericParamsAtDepth)) + return *error; + if (flags.getRepresentation() == + ImplFunctionRepresentation::WitnessMethod) { + // By convention, the first requirement of a witness method is the + // conformance of Self to the protocol. + witnessMethodConformanceRequirement = &requirements[0]; + } + + for (unsigned long depth = 0, depths = genericParamsAtDepth.size(); + depth < depths; ++depth) { + for (unsigned index = 0; index < genericParamsAtDepth[depth]; + ++index) { + genericParameters.emplace_back( + Builder.createGenericTypeParameterType(depth, index)); + } + } } else { return MAKE_NODE_TYPE_ERROR0(child, "unexpected kind"); } @@ -891,11 +918,11 @@ class TypeDecoder { // TODO: Some cases not handled above, but *probably* they cannot // appear as the types of values in SIL (yet?): // - functions with yield returns - // - functions with generic signatures // - foreign error conventions - return Builder.createImplFunctionType(calleeConvention, - parameters, results, - errorResult, flags); + return Builder.createImplFunctionType( + calleeConvention, witnessMethodConformanceRequirement, + genericParameters, requirements, parameters, results, errorResult, + flags); } case NodeKind::ArgumentTuple: @@ -1066,35 +1093,12 @@ class TypeDecoder { return MAKE_NODE_TYPE_ERROR0(substNode, "expected type list"); auto *dependentGenericSignatureNode = Node->getChild(1); - if (dependentGenericSignatureNode->getKind() != - NodeKind::DependentGenericSignature) - return MAKE_NODE_TYPE_ERROR0(dependentGenericSignatureNode, - "expected dependent generic signature"); - if (dependentGenericSignatureNode->getNumChildren() < 1) - return MAKE_NODE_TYPE_ERROR( - dependentGenericSignatureNode, - "fewer children (%zu) than required (1)", - dependentGenericSignatureNode->getNumChildren()); - decodeRequirement( - dependentGenericSignatureNode, requirements, Builder/*, - [&](NodePointer Node) -> BuiltType { - return decodeMangledType(Node).getType(); - }, - [&](LayoutConstraintKind Kind) -> BuiltLayoutConstraint { - return {}; // Not implemented! - }, - [&](LayoutConstraintKind Kind, unsigned SizeInBits, - unsigned Alignment) -> BuiltLayoutConstraint { - return {}; // Not Implemented! - }*/); - // The number of generic parameters at each depth are in a mini - // state machine and come first. llvm::SmallVector genericParamsAtDepth; - for (auto *reqNode : *dependentGenericSignatureNode) - if (reqNode->getKind() == NodeKind::DependentGenericParamCount) - if (reqNode->hasIndex()) - genericParamsAtDepth.push_back(reqNode->getIndex()); + if (auto error = decodeDependentGenericSignatureNode( + dependentGenericSignatureNode, requirements, + genericParamsAtDepth)) + return *error; + unsigned depth = 0; unsigned index = 0; for (auto *subst : *substNode) { @@ -1444,6 +1448,43 @@ class TypeDecoder { params.push_back(std::move(param)); return true; } + + llvm::Optional decodeDependentGenericSignatureNode( + NodePointer dependentGenericSignatureNode, + llvm::SmallVectorImpl &requirements, + llvm::SmallVectorImpl &genericParamsAtDepth) { + using NodeKind = Demangle::Node::Kind; + if (dependentGenericSignatureNode->getKind() != + NodeKind::DependentGenericSignature) + return llvm::Optional( + MAKE_NODE_TYPE_ERROR0(dependentGenericSignatureNode, + "expected dependent generic signature")); + if (dependentGenericSignatureNode->getNumChildren() < 1) + return llvm::Optional(MAKE_NODE_TYPE_ERROR( + dependentGenericSignatureNode, + "fewer children (%zu) than required (1)", + dependentGenericSignatureNode->getNumChildren())); + decodeRequirement(dependentGenericSignatureNode, requirements, + Builder /*, +[&](NodePointer Node) -> BuiltType { +return decodeMangledType(Node).getType(); +}, +[&](LayoutConstraintKind Kind) -> BuiltLayoutConstraint { +return {}; // Not implemented! +}, +[&](LayoutConstraintKind Kind, unsigned SizeInBits, +unsigned Alignment) -> BuiltLayoutConstraint { +return {}; // Not Implemented! +}*/); + // The number of generic parameters at each depth are in a mini + // state machine and come first. + for (auto *reqNode : *dependentGenericSignatureNode) + if (reqNode->getKind() == NodeKind::DependentGenericParamCount) + if (reqNode->hasIndex()) + genericParamsAtDepth.push_back(reqNode->getIndex()); + return llvm::None; + } }; template diff --git a/include/swift/Driver/Driver.h b/include/swift/Driver/Driver.h index 167395da9c073..8e0849ebbcd56 100644 --- a/include/swift/Driver/Driver.h +++ b/include/swift/Driver/Driver.h @@ -167,7 +167,8 @@ class Driver { AutolinkExtract, // swift-autolink-extract SwiftIndent, // swift-indent SymbolGraph, // swift-symbolgraph - APIExtract // swift-api-extract + APIExtract, // swift-api-extract + APIDigester // swift-api-digester }; class InputInfoMap; @@ -200,6 +201,11 @@ class Driver { /// Indicates whether the driver should check that the input files exist. bool CheckInputFilesExist = true; + /// Indicates that this driver never actually executes any commands but is + /// just set up to retrieve the swift-frontend invocation that would be + /// executed during compilation. + bool IsDummyDriverForFrontendInvocation = false; + public: Driver(StringRef DriverExecutable, StringRef Name, ArrayRef Args, DiagnosticEngine &Diags); @@ -226,6 +232,14 @@ class Driver { void setCheckInputFilesExist(bool Value) { CheckInputFilesExist = Value; } + bool isDummyDriverForFrontendInvocation() const { + return IsDummyDriverForFrontendInvocation; + } + + void setIsDummyDriverForFrontendInvocation(bool Value) { + IsDummyDriverForFrontendInvocation = Value; + } + /// Creates an appropriate ToolChain for a given driver, given the target /// specified in \p Args (or the default target). Sets the value of \c /// DefaultTargetTriple from \p Args as a side effect. diff --git a/include/swift/IRGen/IRGenSILPasses.h b/include/swift/IRGen/IRGenSILPasses.h index 06f9e410a9e46..04bd872d3a76a 100644 --- a/include/swift/IRGen/IRGenSILPasses.h +++ b/include/swift/IRGen/IRGenSILPasses.h @@ -19,6 +19,7 @@ namespace irgen { /// Create a pass to hoist alloc_stack instructions with non-fixed size. SILTransform *createAllocStackHoisting(); SILTransform *createLoadableByAddress(); +SILTransform *createPartialApplyLowering(); } // end namespace irgen } // end namespace swift diff --git a/include/swift/IRGen/Linking.h b/include/swift/IRGen/Linking.h index 529cbad781d83..d4ffae4f4c10d 100644 --- a/include/swift/IRGen/Linking.h +++ b/include/swift/IRGen/Linking.h @@ -447,6 +447,15 @@ class LinkEntity { /// context. /// The pointer is a SILFunction*. AsyncFunctionPointer, + + /// The thunk provided for partially applying a function at some values + /// which are captured. + /// The pointer is an llvm::Function*. + PartialApplyForwarder, + + /// An async function pointer to a partial apply forwarder. + /// The pointer is the llvm::Function* for a partial apply forwarder. + PartialApplyForwarderAsyncFunctionPointer, }; friend struct llvm::DenseMapInfo; @@ -1170,6 +1179,10 @@ class LinkEntity { entity.Data = LINKENTITY_SET_FIELD( Kind, unsigned(LinkEntity::Kind::DispatchThunkAllocatorAsyncFunctionPointer)); break; + case LinkEntity::Kind::PartialApplyForwarder: + entity.Data = LINKENTITY_SET_FIELD( + Kind, unsigned(LinkEntity::Kind::PartialApplyForwarderAsyncFunctionPointer)); + break; default: llvm_unreachable("Link entity kind cannot have an async function pointer"); @@ -1210,6 +1223,11 @@ class LinkEntity { Kind, unsigned(LinkEntity::Kind::DispatchThunkAllocator)); break; + case LinkEntity::Kind::PartialApplyForwarderAsyncFunctionPointer: + entity.Data = LINKENTITY_SET_FIELD( + Kind, unsigned(LinkEntity::Kind::PartialApplyForwarder)); + break; + default: llvm_unreachable("Link entity is not an async function pointer"); } @@ -1217,6 +1235,15 @@ class LinkEntity { return entity; } + static LinkEntity forPartialApplyForwarder(llvm::Function *function) { + LinkEntity entity; + entity.Pointer = function; + entity.SecondaryPointer = nullptr; + entity.Data = + LINKENTITY_SET_FIELD(Kind, unsigned(Kind::PartialApplyForwarder)); + return entity; + } + void mangle(llvm::raw_ostream &out) const; void mangle(SmallVectorImpl &buffer) const; std::string mangleAsString() const; diff --git a/include/swift/Option/Options.h b/include/swift/Option/Options.h index f846bc55d61a3..4bd2c81a36a14 100644 --- a/include/swift/Option/Options.h +++ b/include/swift/Option/Options.h @@ -39,6 +39,7 @@ namespace options { SupplementaryOutput = (1 << 14), SwiftAPIExtractOption = (1 << 15), SwiftSymbolGraphExtractOption = (1 << 16), + SwiftMergeModuleSummaryOption = (1 << 17), }; enum ID { diff --git a/include/swift/Option/Options.td b/include/swift/Option/Options.td index d50410f08c6a8..5079366ac461d 100644 --- a/include/swift/Option/Options.td +++ b/include/swift/Option/Options.td @@ -61,6 +61,8 @@ def SwiftAPIExtractOption : OptionFlag; // The option should be accepted by swift-symbolgraph-extract. def SwiftSymbolGraphExtractOption : OptionFlag; +def SwiftMergeModuleSummaryOption : OptionFlag; + ///////// // Options @@ -177,6 +179,7 @@ def driver_mode : Joined<["--"], "driver-mode=">, Flags<[HelpHidden]>, def help : Flag<["-", "--"], "help">, Flags<[FrontendOption, AutolinkExtractOption, ModuleWrapOption, SwiftIndentOption, SwiftAPIExtractOption, + SwiftMergeModuleSummaryOption, SwiftSymbolGraphExtractOption]>, HelpText<"Display available options">; def h : Flag<["-"], "h">, Alias; @@ -200,6 +203,7 @@ def _DASH_DASH : Option<["--"], "", KIND_REMAINING_ARGS>, def o : JoinedOrSeparate<["-"], "o">, Flags<[FrontendOption, AutolinkExtractOption, ModuleWrapOption, NoInteractiveOption, SwiftIndentOption, ArgumentIsPath, + SwiftMergeModuleSummaryOption, SwiftAPIExtractOption]>, HelpText<"Write output to ">, MetaVarName<"">; @@ -1043,7 +1047,7 @@ def Xclang_linker : Separate<["-"], "Xclang-linker">, Flags<[HelpHidden]>, MetaVarName<"">, HelpText<"Pass to Clang when it is use for linking.">; def Xllvm : Separate<["-"], "Xllvm">, - Flags<[FrontendOption, HelpHidden]>, + Flags<[FrontendOption, HelpHidden, SwiftMergeModuleSummaryOption]>, MetaVarName<"">, HelpText<"Pass to LLVM.">; def resource_dir : Separate<["-"], "resource-dir">, diff --git a/include/swift/Parse/ParsedRawSyntaxNode.h b/include/swift/Parse/ParsedRawSyntaxNode.h index 7fc6209dbf728..5133ad6769df9 100644 --- a/include/swift/Parse/ParsedRawSyntaxNode.h +++ b/include/swift/Parse/ParsedRawSyntaxNode.h @@ -33,7 +33,6 @@ namespace swift { -typedef const void *OpaqueSyntaxNode; class SyntaxParsingContext; /// Represents a raw syntax node formed by the parser. diff --git a/include/swift/Parse/ParsedRawSyntaxRecorder.h b/include/swift/Parse/ParsedRawSyntaxRecorder.h index ae2e7086e7b06..f300c0c642f9e 100644 --- a/include/swift/Parse/ParsedRawSyntaxRecorder.h +++ b/include/swift/Parse/ParsedRawSyntaxRecorder.h @@ -21,8 +21,24 @@ #include "swift/Basic/LLVM.h" #include "swift/Parse/ParsedRawSyntaxNode.h" +#include "swift/Parse/SyntaxParseActions.h" +#include "swift/SyntaxParse/SyntaxTreeCreator.h" #include +/// Define a macro that creates a \c ParsedRawSyntaxNode. If \c +/// PARSEDRAWSYNTAXNODE_VERIFY_RANGES is defined, it passes the \c Range +/// parameter, otherwise it ignores it at the pre-processor level, which means +/// that \c Range can be an invalid expression. +#ifdef PARSEDRAWSYNTAXNODE_VERIFY_RANGES +#define makeParsedRawSyntaxNode(Opaque, SynKind, TokKind, DataKind, IsMissing, \ + Range) \ + ParsedRawSyntaxNode(Opaque, SynKind, TokKind, DataKind, IsMissing, Range) +#else +#define makeParsedRawSyntaxNode(Opaque, SynKind, TokKind, DataKind, IsMissing, \ + Range) \ + ParsedRawSyntaxNode(Opaque, SynKind, TokKind, DataKind, IsMissing) +#endif + namespace swift { class CharSourceRange; @@ -57,18 +73,50 @@ class ParsedRawSyntaxRecorder final { /// return the recorded node. /// This consumes the data from \c node, which is unusable after it has been /// recorded. The returned node should be used afterwards instead. - ParsedRawSyntaxNode recordDeferredNode(ParsedRawSyntaxNode &node); + ParsedRawSyntaxNode recordDeferredNode(ParsedRawSyntaxNode &node) { + switch (node.getDataKind()) { + case RecordedOrDeferredNode::Kind::Null: + case RecordedOrDeferredNode::Kind::Recorded: + llvm_unreachable("Not deferred"); + case RecordedOrDeferredNode::Kind::DeferredLayout: { + OpaqueSyntaxNode Data = SPActions->recordDeferredLayout(node.takeData()); + return makeParsedRawSyntaxNode(Data, node.getKind(), node.getTokenKind(), + ParsedRawSyntaxNode::DataKind::Recorded, + node.isMissing(), node.getRange()); + } + case RecordedOrDeferredNode::Kind::DeferredToken: { + OpaqueSyntaxNode Data = SPActions->recordDeferredToken(node.takeData()); + return makeParsedRawSyntaxNode(Data, node.getKind(), node.getTokenKind(), + ParsedRawSyntaxNode::DataKind::Recorded, + node.isMissing(), node.getRange()); + } + } + } public: explicit ParsedRawSyntaxRecorder(std::shared_ptr spActions) : SPActions(std::move(spActions)) {} ParsedRawSyntaxNode recordToken(const Token &tok, StringRef leadingTrivia, - StringRef trailingTrivia); + StringRef trailingTrivia) { + return recordToken(tok.getKind(), tok.getRange(), leadingTrivia, + trailingTrivia); + } ParsedRawSyntaxNode recordToken(tok tokenKind, CharSourceRange tokenRange, StringRef leadingTrivia, - StringRef trailingTrivia); + StringRef trailingTrivia) { + SourceLoc offset = + tokenRange.getStart().getAdvancedLoc(-leadingTrivia.size()); + unsigned length = leadingTrivia.size() + tokenRange.getByteLength() + + trailingTrivia.size(); + CharSourceRange range(offset, length); + OpaqueSyntaxNode n = + SPActions->recordToken(tokenKind, leadingTrivia, trailingTrivia, range); + return makeParsedRawSyntaxNode(n, syntax::SyntaxKind::Token, tokenKind, + ParsedRawSyntaxNode::DataKind::Recorded, + /*IsMissing=*/false, range); + } /// Record a missing token. \p loc can be invalid or an approximate location /// of where the token would be if not missing. @@ -77,8 +125,39 @@ class ParsedRawSyntaxRecorder final { /// The provided \p elements are an exact layout appropriate for the syntax /// \p kind. Missing optional elements are represented with a null /// ParsedRawSyntaxNode object. - ParsedRawSyntaxNode recordRawSyntax(syntax::SyntaxKind kind, - MutableArrayRef elements); + ParsedRawSyntaxNode + recordRawSyntax(syntax::SyntaxKind kind, + MutableArrayRef elements) { + assert(kind != syntax::SyntaxKind::Token && + "Use recordToken to record a token"); +#ifdef PARSEDRAWSYNTAXNODE_VERIFY_RANGES + auto range = ParsedRawSyntaxRecorder::verifyElementRanges(elements); +#endif + + SmallVector subnodes; + if (!elements.empty()) { + for (auto &subnode : elements) { + switch (subnode.getDataKind()) { + case RecordedOrDeferredNode::Kind::Null: + subnodes.push_back(nullptr); + break; + case RecordedOrDeferredNode::Kind::Recorded: + subnodes.push_back(subnode.takeData()); + break; + case RecordedOrDeferredNode::Kind::DeferredLayout: + case RecordedOrDeferredNode::Kind::DeferredToken: { + auto recorded = recordDeferredNode(subnode); + subnodes.push_back(recorded.takeData()); + break; + } + } + } + } + OpaqueSyntaxNode n = SPActions->recordRawSyntax(kind, subnodes); + return makeParsedRawSyntaxNode(n, kind, tok::NUM_TOKENS, + ParsedRawSyntaxNode::DataKind::Recorded, + /*IsMissing=*/false, range); + } /// Record a raw syntax collecton without eny elements. \p loc can be invalid /// or an approximate location of where an element of the collection would be @@ -94,11 +173,38 @@ class ParsedRawSyntaxRecorder final { ParsedRawSyntaxNode makeDeferred(syntax::SyntaxKind k, MutableArrayRef deferredNodes, - SyntaxParsingContext &ctx); + SyntaxParsingContext &ctx) { +#ifdef PARSEDRAWSYNTAXNODE_VERIFY_RANGES + auto range = ParsedRawSyntaxRecorder::verifyElementRanges(deferredNodes); +#endif + + assert(llvm::none_of(deferredNodes, [](const ParsedRawSyntaxNode &node) { + return node.isRecorded(); + }) && "Cannot create a deferred layout node that has recorded children"); + + auto data = + SPActions->makeDeferredLayout(k, /*IsMissing=*/false, deferredNodes); + return makeParsedRawSyntaxNode( + data, k, tok::NUM_TOKENS, ParsedRawSyntaxNode::DataKind::DeferredLayout, + /*IsMissing=*/false, range); + } /// Form a deferred token node. ParsedRawSyntaxNode makeDeferred(Token tok, StringRef leadingTrivia, - StringRef trailingTrivia); + StringRef trailingTrivia) { + CharSourceRange tokRange = tok.getRange(); + CharSourceRange RangeWithTrivia = CharSourceRange( + tokRange.getStart().getAdvancedLoc(-leadingTrivia.size()), + (unsigned)leadingTrivia.size() + tokRange.getByteLength() + + (unsigned)trailingTrivia.size()); + auto Data = SPActions->makeDeferredToken(tok.getKind(), leadingTrivia, + trailingTrivia, RangeWithTrivia, + /*IsMissing=*/false); + return makeParsedRawSyntaxNode(Data, syntax::SyntaxKind::Token, + tok.getKind(), + ParsedRawSyntaxNode::DataKind::DeferredToken, + /*IsMissing=*/false, RangeWithTrivia); + } /// Form a deferred missing token node. ParsedRawSyntaxNode makeDeferredMissing(tok tokKind, SourceLoc loc); diff --git a/include/swift/Parse/Parser.h b/include/swift/Parse/Parser.h index 5b22a24f0540b..b77602cbc3692 100644 --- a/include/swift/Parse/Parser.h +++ b/include/swift/Parse/Parser.h @@ -656,7 +656,7 @@ class Parser { /// Read tokens until we get to one of the specified tokens, then /// return without consuming it. Because we cannot guarantee that the token /// will ever occur, this skips to some likely good stopping point. - void skipUntil(tok T1, tok T2 = tok::NUM_TOKENS); + ParserStatus skipUntil(tok T1, tok T2 = tok::NUM_TOKENS); void skipUntilAnyOperator(); /// Skip until a token that starts with '>', and consume it if found. @@ -680,7 +680,10 @@ class Parser { /// Note: this does \em not match angle brackets ("<" and ">")! These are /// matched in the source when they refer to a generic type, /// but not when used as comparison operators. - void skipSingle(); + /// + /// Returns a parser status that can capture whether a code completion token + /// was returned. + ParserStatus skipSingle(); /// Skip until the next '#else', '#endif' or until eof. void skipUntilConditionalBlockClose(); @@ -1061,8 +1064,23 @@ class Parser { /// Parse a specific attribute. ParserStatus parseDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc, + PatternBindingInitializer *&initContext, bool isFromClangAttribute = false); + bool isCustomAttributeArgument(); + bool canParseCustomAttribute(); + + /// Parse a custom attribute after the initial '@'. + /// + /// \param atLoc The location of the already-parsed '@'. + /// + /// \param initContext A reference to the initializer context used + /// for the set of custom attributes. This should start as nullptr, and + /// will get filled in by this function. The same variable should be provided + /// for every custom attribute within the same attribute list. + ParserResult parseCustomAttribute( + SourceLoc atLoc, PatternBindingInitializer *&initContext); + bool parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc, DeclAttrKind DK, bool isFromClangAttribute = false); @@ -1090,6 +1108,7 @@ class Parser { TypeAttributes::Convention &convention); bool parseTypeAttribute(TypeAttributes &Attributes, SourceLoc AtLoc, + PatternBindingInitializer *&initContext, bool justChecking = false); diff --git a/include/swift/Parse/SyntaxParseActions.h b/include/swift/Parse/SyntaxParseActions.h index 03a6023b270a7..969096ca758cc 100644 --- a/include/swift/Parse/SyntaxParseActions.h +++ b/include/swift/Parse/SyntaxParseActions.h @@ -20,6 +20,8 @@ #include "swift/Basic/LLVM.h" #include "swift/Basic/SourceLoc.h" +#include "swift/Subsystems.h" +#include "llvm/ADT/PointerIntPair.h" #include "llvm/Support/Allocator.h" namespace swift { @@ -28,14 +30,13 @@ class ParsedTriviaPiece; class SourceFile; class SourceLoc; enum class tok : uint8_t; +class ParsedRawSyntaxNode; namespace syntax { class SourceFileSyntax; enum class SyntaxKind : uint16_t; } -typedef const void *OpaqueSyntaxNode; - // MARK: - Helper types /// A syntax node that can either be deferred or recorded. The actual data is @@ -51,15 +52,14 @@ class RecordedOrDeferredNode { }; private: - OpaqueSyntaxNode Opaque; - Kind NodeKind; + llvm::PointerIntPair Data; public: RecordedOrDeferredNode(OpaqueSyntaxNode Node, Kind NodeKind) - : Opaque(Node), NodeKind(NodeKind) {} + : Data(Node, NodeKind) {} - OpaqueSyntaxNode getOpaque() const { return Opaque; } - Kind getKind() const { return NodeKind; } + OpaqueSyntaxNode getOpaque() const { return Data.getPointer(); } + Kind getKind() const { return Data.getInt(); } }; /// Data returned from \c getDeferredChild. This is enough data to construct @@ -113,9 +113,11 @@ class SyntaxParseActions { /// Create a deferred layout node that may or may not be recorded later using /// \c recordDeferredLayout. The \c SyntaxParseAction is responsible for /// keeping the deferred token alive until it is destructed. + /// From all nodes in \p children, the underlying opaque data will be *taken* + /// which resets the nodes. virtual OpaqueSyntaxNode makeDeferredLayout(syntax::SyntaxKind k, bool isMissing, - const ArrayRef &children) = 0; + const MutableArrayRef &children) = 0; /// Record a deferred token node that was previously created using \c /// makeDeferredToken. The deferred data will never be used again, so it can diff --git a/include/swift/Reflection/TypeRefBuilder.h b/include/swift/Reflection/TypeRefBuilder.h index 1a54fbea88943..cffcbec1e7820 100644 --- a/include/swift/Reflection/TypeRefBuilder.h +++ b/include/swift/Reflection/TypeRefBuilder.h @@ -417,9 +417,14 @@ class TypeRefBuilder { const TypeRef *result, FunctionTypeFlags flags) { return FunctionTypeRef::create(*this, params, result, flags); } + using BuiltSubstitution = std::pair; + using BuiltRequirement = TypeRefRequirement; const FunctionTypeRef *createImplFunctionType( Demangle::ImplParameterConvention calleeConvention, + BuiltRequirement *witnessMethodConformanceRequirement, + const llvm::SmallVectorImpl &genericParameters, + const llvm::SmallVectorImpl &requirements, llvm::ArrayRef> params, llvm::ArrayRef> results, llvm::Optional> errorResult, @@ -519,8 +524,6 @@ class TypeRefBuilder { } using BuiltSILBoxField = typename SILBoxTypeWithLayoutTypeRef::Field; - using BuiltSubstitution = std::pair; - using BuiltRequirement = TypeRefRequirement; using BuiltLayoutConstraint = TypeRefLayoutConstraint; BuiltLayoutConstraint getLayoutConstraint(LayoutConstraintKind kind) { // FIXME: Implement this. diff --git a/include/swift/Runtime/CMakeConfig.h.in b/include/swift/Runtime/CMakeConfig.h.in index 5640423850504..e24e5c3fe7db8 100644 --- a/include/swift/Runtime/CMakeConfig.h.in +++ b/include/swift/Runtime/CMakeConfig.h.in @@ -7,6 +7,4 @@ #cmakedefine01 SWIFT_BNI_OS_BUILD #cmakedefine01 SWIFT_BNI_XCODE_BUILD -#cmakedefine01 USE_SWIFT_ASYNC_LOWERING - #endif diff --git a/include/swift/Runtime/Concurrency.h b/include/swift/Runtime/Concurrency.h index 2282c2dca7785..ca06c97a3507f 100644 --- a/include/swift/Runtime/Concurrency.h +++ b/include/swift/Runtime/Concurrency.h @@ -20,6 +20,9 @@ #include "swift/ABI/TaskGroup.h" #include "swift/ABI/TaskStatus.h" +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wreturn-type-c-linkage" + namespace swift { class DefaultActor; @@ -34,7 +37,6 @@ struct AsyncTaskAndContext { /// function. SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift) AsyncTaskAndContext swift_task_create_f(JobFlags flags, - AsyncTask *parent, ThinNullaryAsyncSignature::FunctionType *function, size_t initialContextSize); @@ -47,7 +49,7 @@ using FutureAsyncSignature = /// closure. SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift) AsyncTaskAndContext swift_task_create_future( - JobFlags flags, AsyncTask *parent, const Metadata *futureResultType, + JobFlags flags, const Metadata *futureResultType, void *closureEntryPoint, HeapObject * /* +1 */ closureContext); @@ -55,7 +57,7 @@ AsyncTaskAndContext swift_task_create_future( /// function. SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift) AsyncTaskAndContext swift_task_create_future_f( - JobFlags flags, AsyncTask *parent, const Metadata *futureResultType, + JobFlags flags, const Metadata *futureResultType, FutureAsyncSignature::FunctionType *function, size_t initialContextSize); @@ -63,8 +65,7 @@ AsyncTaskAndContext swift_task_create_future_f( /// closure, and offer its result to the task group SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift) AsyncTaskAndContext swift_task_create_group_future( - JobFlags flags, - AsyncTask *parent, TaskGroup *group, + JobFlags flags, TaskGroup *group, const Metadata *futureResultType, void *closureEntryPoint, HeapObject * /* +1 */ closureContext); @@ -73,8 +74,7 @@ AsyncTaskAndContext swift_task_create_group_future( /// function, and offer its result to the task group SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift) AsyncTaskAndContext swift_task_create_group_future_f( - JobFlags flags, - AsyncTask *parent, TaskGroup *group, + JobFlags flags, TaskGroup *group, const Metadata *futureResultType, FutureAsyncSignature::FunctionType *function, size_t initialContextSize); @@ -85,7 +85,7 @@ AsyncTaskAndContext swift_task_create_group_future_f( /// /// All allocations will be rounded to a multiple of MAX_ALIGNMENT. SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift) -void *swift_task_alloc(AsyncTask *task, size_t size); +void *swift_task_alloc(size_t size); /// Deallocate memory in a task. /// @@ -93,7 +93,7 @@ void *swift_task_alloc(AsyncTask *task, size_t size); /// this task that has not yet been deallocated; that is, memory /// must be allocated and deallocated in a strict stack discipline. SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift) -void swift_task_dealloc(AsyncTask *task, void *ptr); +void swift_task_dealloc(void *ptr); /// Cancel a task and all of its child tasks. /// @@ -103,9 +103,9 @@ void swift_task_dealloc(AsyncTask *task, void *ptr); SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift) void swift_task_cancel(AsyncTask *task); -/// Cancel all child tasks of `parent` that belong to the `group`. +/// Cancel all the child tasks that belong to the `group`. SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift) -void swift_task_cancel_group_child_tasks(AsyncTask *task, TaskGroup *group); +void swift_task_cancel_group_child_tasks(TaskGroup *group); /// Escalate the priority of a task and all of its child tasks. /// @@ -117,8 +117,11 @@ SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift) JobPriority swift_task_escalate(AsyncTask *task, JobPriority newPriority); +/// This matches the ABI of a closure `(Builtin.NativeObject) async -> T` using TaskFutureWaitSignature = - AsyncSignature; + SWIFT_CC(swiftasync) + void(OpaqueValue *, + SWIFT_ASYNC_CONTEXT AsyncContext *, AsyncTask *, Metadata *); /// Wait for a non-throwing future task to complete. /// @@ -129,11 +132,13 @@ using TaskFutureWaitSignature = /// -> Success /// \endcode SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swiftasync) -TaskFutureWaitSignature::FunctionType -swift_task_future_wait; +void swift_task_future_wait(OpaqueValue *, + SWIFT_ASYNC_CONTEXT AsyncContext *, AsyncTask *, Metadata *); using TaskFutureWaitThrowingSignature = - AsyncSignature; + SWIFT_CC(swiftasync) + void(OpaqueValue *, + SWIFT_ASYNC_CONTEXT AsyncContext *, AsyncTask *, Metadata *); /// Wait for a potentially-throwing future task to complete. /// @@ -144,11 +149,15 @@ using TaskFutureWaitThrowingSignature = /// async throws -> Success /// \endcode SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swiftasync) -TaskFutureWaitThrowingSignature::FunctionType -swift_task_future_wait_throwing; +void swift_task_future_wait_throwing(OpaqueValue *, + SWIFT_ASYNC_CONTEXT AsyncContext *, + AsyncTask *, Metadata *); using TaskGroupFutureWaitThrowingSignature = - AsyncSignature; +SWIFT_CC(swiftasync) + void(OpaqueValue *, + SWIFT_ASYNC_CONTEXT AsyncContext *, AsyncTask *, TaskGroup *, + const Metadata *successType); /// Wait for a readyQueue of a Channel to become non empty. /// @@ -160,9 +169,11 @@ using TaskGroupFutureWaitThrowingSignature = /// group: UnsafeRawPointer /// ) async -> T /// \endcode -SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swiftasync) -TaskGroupFutureWaitThrowingSignature::FunctionType -swift_taskGroup_wait_next_throwing; +SWIFT_EXPORT_FROM(swift_Concurrency) +SWIFT_CC(swiftasync) +void swift_taskGroup_wait_next_throwing( + OpaqueValue *resultPointer, SWIFT_ASYNC_CONTEXT AsyncContext *rawContext, + TaskGroup *group, const Metadata *successType); /// Create a new `TaskGroup`. /// The caller is responsible for retaining and managing the group's lifecycle. @@ -170,12 +181,10 @@ swift_taskGroup_wait_next_throwing; /// Its Swift signature is /// /// \code -/// func swift_taskGroup_create( -/// _ task: Builtin.NativeObject -/// ) -> Builtin.RawPointer +/// func swift_taskGroup_create() -> Builtin.RawPointer /// \endcode SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift) -TaskGroup* swift_taskGroup_create(AsyncTask *task); // TODO: probably remove this call, and just use the initialize always +TaskGroup* swift_taskGroup_create(); // TODO: probably remove this call, and just use the initialize always /// Initialize a `TaskGroup` in the passed `group` memory location. /// The caller is responsible for retaining and managing the group's lifecycle. @@ -183,13 +192,11 @@ TaskGroup* swift_taskGroup_create(AsyncTask *task); // TODO: probably remove thi /// Its Swift signature is /// /// \code -/// func swift_taskGroup_initialize( -/// _ task: Builtin.NativeObject, -/// group: Builtin.RawPointer, +/// func swift_taskGroup_initialize(group: Builtin.RawPointer /// ) /// \endcode SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift) -void swift_taskGroup_initialize(AsyncTask *task, TaskGroup *group); +void swift_taskGroup_initialize(TaskGroup *group); /// Attach a child task to the parent task's task group record. /// @@ -215,13 +222,10 @@ void swift_taskGroup_attachChild(TaskGroup *group, AsyncTask *child); /// This function MUST be called from the AsyncTask running the task group. /// /// \code -/// func swift_taskGroup_destroy( -/// _ task: Builtin.NativeObject, -/// _ group: UnsafeRawPointer -/// ) +/// func swift_taskGroup_destroy(_ group: UnsafeRawPointer) /// \endcode SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift) -void swift_taskGroup_destroy(AsyncTask *task, TaskGroup *group); +void swift_taskGroup_destroy(TaskGroup *group); /// Before starting a task group child task, inform the group that there is one /// more 'pending' child to account for. @@ -247,13 +251,10 @@ bool swift_taskGroup_addPending(TaskGroup *group); /// Its Swift signature is /// /// \code -/// func swift_taskGroup_cancelAll( -/// task: Builtin.NativeObject, -/// group: UnsafeRawPointer -/// ) +/// func swift_taskGroup_cancelAll(group: UnsafeRawPointer) /// \endcode SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift) -void swift_taskGroup_cancelAll(AsyncTask *task, TaskGroup *group); +void swift_taskGroup_cancelAll(TaskGroup *group); /// Check ONLY if the group was explicitly cancelled, e.g. by `cancelAll`. /// @@ -263,13 +264,10 @@ void swift_taskGroup_cancelAll(AsyncTask *task, TaskGroup *group); /// This can be called from any thread. Its Swift signature is /// /// \code -/// func swift_taskGroup_isCancelled( -/// task: Builtin.NativeObject, -/// group: UnsafeRawPointer -/// ) +/// func swift_taskGroup_isCancelled(group: UnsafeRawPointer) /// \endcode SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift) -bool swift_taskGroup_isCancelled(AsyncTask *task, TaskGroup *group); +bool swift_taskGroup_isCancelled(TaskGroup *group); /// Check the readyQueue of a task group, return true if it has no pending tasks. /// @@ -291,8 +289,7 @@ bool swift_taskGroup_isEmpty(TaskGroup *group); /// If the task is already cancelled, returns `false` but still adds /// the status record. SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift) -bool swift_task_addStatusRecord(AsyncTask *task, - TaskStatusRecord *record); +bool swift_task_addStatusRecord(TaskStatusRecord *record); /// Add a status record to a task if the task has not already /// been cancelled. The record should not be modified while it is @@ -303,8 +300,7 @@ bool swift_task_addStatusRecord(AsyncTask *task, /// If the task is already cancelled, returns `false` and does not /// add the status record. SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift) -bool swift_task_tryAddStatusRecord(AsyncTask *task, - TaskStatusRecord *record); +bool swift_task_tryAddStatusRecord(TaskStatusRecord *record); /// Remove a status record from a task. After this call returns, /// the record's memory can be freely modified or deallocated. @@ -317,7 +313,7 @@ bool swift_task_tryAddStatusRecord(AsyncTask *task, ///s /// Returns false if the task has been cancelled. SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift) -bool swift_task_removeStatusRecord(AsyncTask *task, TaskStatusRecord *record); +bool swift_task_removeStatusRecord(TaskStatusRecord *record); /// Attach a child task to its parent task and return the newly created /// `ChildTaskStatusRecord`. @@ -326,11 +322,11 @@ bool swift_task_removeStatusRecord(AsyncTask *task, TaskStatusRecord *record); /// `swift_task_detachChild` when the child has completed. SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift) ChildTaskStatusRecord* -swift_task_attachChild(AsyncTask *parent, AsyncTask *child); +swift_task_attachChild(AsyncTask *child); /// Remove a child task from the parent tracking it. SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift) -void swift_task_detachChild(AsyncTask *parent, ChildTaskStatusRecord *record); +void swift_task_detachChild(ChildTaskStatusRecord *record); SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift) size_t swift_task_getJobFlags(AsyncTask* task); @@ -342,12 +338,12 @@ bool swift_task_isCancelled(AsyncTask* task); SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift) CancellationNotificationStatusRecord* swift_task_addCancellationHandler( - AsyncTask *task, CancellationNotificationStatusRecord::FunctionType handler); + CancellationNotificationStatusRecord::FunctionType handler); /// Remove the passed cancellation record from the task. SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift) void swift_task_removeCancellationHandler( - AsyncTask *task, CancellationNotificationStatusRecord *record); + CancellationNotificationStatusRecord *record); /// Get a task local value from the passed in task. Its Swift signature is /// @@ -446,8 +442,8 @@ void swift_task_runAndBlockThread(const void *function, /// generally be tail-called, as it may continue executing the task /// synchronously if possible. SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swiftasync) -void swift_task_switch(AsyncTask *task, - ExecutorRef currentExecutor, +void swift_task_switch(SWIFT_ASYNC_CONTEXT AsyncContext *resumeToContext, + TaskContinuationFunction *resumeFunction, ExecutorRef newExecutor); /// Enqueue the given job to run asynchronously on the given executor. @@ -552,6 +548,12 @@ void swift_job_run(Job *job, ExecutorRef executor); SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift) AsyncTask *swift_task_getCurrent(void); +/// Return the current thread's active executor reference. +SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift) +ExecutorRef swift_task_getCurrentExecutor(void); + } +#pragma clang diagnostic pop + #endif diff --git a/include/swift/Runtime/Config.h b/include/swift/Runtime/Config.h index 015c548ad6e49..f46756b7a3ed8 100644 --- a/include/swift/Runtime/Config.h +++ b/include/swift/Runtime/Config.h @@ -184,8 +184,7 @@ extern uintptr_t __COMPATIBILITY_LIBRARIES_CANNOT_CHECK_THE_IS_SWIFT_BIT_DIRECTL // SWIFT_CC(swiftasync) is the Swift async calling convention. // We assume that it supports mandatory tail call elimination. -#if __has_feature(swiftasynccc) && USE_SWIFT_ASYNC_LOWERING && \ - __has_attribute(swiftasynccall) +#if __has_feature(swiftasynccc) && __has_attribute(swiftasynccall) #define SWIFT_CC_swiftasync __attribute__((swiftasynccall)) #else #define SWIFT_CC_swiftasync SWIFT_CC_swift diff --git a/include/swift/Runtime/RuntimeFunctions.def b/include/swift/Runtime/RuntimeFunctions.def index 528bbc18448fc..9855782ee7174 100644 --- a/include/swift/Runtime/RuntimeFunctions.def +++ b/include/swift/Runtime/RuntimeFunctions.def @@ -1478,20 +1478,28 @@ FUNCTION(GetTypeByMangledNameInContextInMetadataState, Int8PtrPtrTy), ATTRS(NoUnwind, ArgMemOnly)) -// void *swift_task_alloc(AsyncTask *task, size_t size); +// AsyncTask *swift_task_getCurrent();s +FUNCTION(GetCurrentTask, + swift_task_getCurrent, SwiftCC, + ConcurrencyAvailability, + RETURNS(SwiftTaskPtrTy), + ARGS(), + ATTRS(NoUnwind, ReadNone)) + +// void *swift_task_alloc(size_t size); FUNCTION(TaskAlloc, swift_task_alloc, SwiftCC, ConcurrencyAvailability, RETURNS(Int8PtrTy), - ARGS(SwiftTaskPtrTy, SizeTy), + ARGS(SizeTy), ATTRS(NoUnwind, ArgMemOnly)) -// void swift_task_dealloc(AsyncTask *task, void *ptr); +// void swift_task_dealloc(void *ptr); FUNCTION(TaskDealloc, swift_task_dealloc, SwiftCC, ConcurrencyAvailability, RETURNS(VoidTy), - ARGS(SwiftTaskPtrTy, Int8PtrTy), + ARGS(Int8PtrTy), ATTRS(NoUnwind, ArgMemOnly)) // void swift_task_cancel(AsyncTask *task); @@ -1503,74 +1511,74 @@ FUNCTION(TaskCancel, ATTRS(NoUnwind, ArgMemOnly)) // AsyncTaskAndContext swift_task_create_f( -// size_t flags, AsyncTask *task, +// size_t flags, // TaskContinuationFunction* function, // size_t contextSize); FUNCTION(TaskCreateFunc, swift_task_create_f, SwiftCC, ConcurrencyAvailability, RETURNS(AsyncTaskAndContextTy), - ARGS(SizeTy, SwiftTaskPtrTy, TaskContinuationFunctionPtrTy, SizeTy), + ARGS(SizeTy, TaskContinuationFunctionPtrTy, SizeTy), ATTRS(NoUnwind, ArgMemOnly)) // AsyncTaskAndContext swift_task_create_future( -// size_t flags, AsyncTask *task, +// size_t flags, // const Metadata *futureResultType, // void *closureEntry, HeapObject *closureContext); FUNCTION(TaskCreateFuture, swift_task_create_future, SwiftCC, ConcurrencyAvailability, RETURNS(AsyncTaskAndContextTy), - ARGS(SizeTy, SwiftTaskPtrTy, TypeMetadataPtrTy, + ARGS(SizeTy, TypeMetadataPtrTy, Int8PtrTy, RefCountedPtrTy), ATTRS(NoUnwind, ArgMemOnly)) // AsyncTaskAndContext swift_task_create_future_f( -// size_t flags, AsyncTask *task, +// size_t flags, // const Metadata *futureResultType, // TaskContinuationFunction *function, size_t contextSize); FUNCTION(TaskCreateFutureFunc, swift_task_create_future_f, SwiftCC, ConcurrencyAvailability, RETURNS(AsyncTaskAndContextTy), - ARGS(SizeTy, SwiftTaskPtrTy, TypeMetadataPtrTy, + ARGS(SizeTy, TypeMetadataPtrTy, TaskContinuationFunctionPtrTy, SizeTy), ATTRS(NoUnwind, ArgMemOnly)) // AsyncTaskAndContext swift_task_create_group_future( -// size_t flags, AsyncTask *task, TaskGroup *group, +// size_t flags, TaskGroup *group, // const Metadata *futureResultType, // void *closureEntry, HeapObject *closureContext); FUNCTION(TaskCreateGroupFuture, swift_task_create_group_future, SwiftCC, ConcurrencyAvailability, RETURNS(AsyncTaskAndContextTy), - ARGS(SizeTy, SwiftTaskPtrTy, SwiftTaskGroupPtrTy, + ARGS(SizeTy, SwiftTaskGroupPtrTy, TypeMetadataPtrTy, Int8PtrTy, RefCountedPtrTy), ATTRS(NoUnwind, ArgMemOnly)) // AsyncTaskAndContext swift_task_create_group_future_f( -// size_t flags, AsyncTask *task, TaskGroup *group, +// size_t flags, TaskGroup *group, // const Metadata *futureResultType, // TaskContinuationFunction *function, size_t contextSize); FUNCTION(TaskCreateGroupFutureFunc, swift_task_create_group_future_f, SwiftCC, ConcurrencyAvailability, RETURNS(AsyncTaskAndContextTy), - ARGS(SizeTy, SwiftTaskPtrTy, SwiftTaskGroupPtrTy, + ARGS(SizeTy, SwiftTaskGroupPtrTy, TypeMetadataPtrTy, TaskContinuationFunctionPtrTy, SizeTy), ATTRS(NoUnwind, ArgMemOnly)) -// void swift_task_switch(AsyncTask *task, -// ExecutorRef currentExecutor, +// void swift_task_switch(AsyncContext *resumeContext, +// TaskContinuationFunction *resumeFunction, // ExecutorRef newExecutor); FUNCTION(TaskSwitchFunc, swift_task_switch, SwiftAsyncCC, ConcurrencyAvailability, RETURNS(VoidTy), - ARGS(SwiftTaskPtrTy, SwiftExecutorPtrTy, SwiftExecutorPtrTy), + ARGS(SwiftContextPtrTy, Int8PtrTy, SwiftExecutorPtrTy), ATTRS(NoUnwind)) // void swift_defaultActor_initialize(DefaultActor *actor); diff --git a/include/swift/SIL/SILInstructionWorklist.h b/include/swift/SIL/SILInstructionWorklist.h index 6df8e06cc0d5b..e829f64c28d84 100644 --- a/include/swift/SIL/SILInstructionWorklist.h +++ b/include/swift/SIL/SILInstructionWorklist.h @@ -215,7 +215,7 @@ class SILInstructionWorklist : SILInstructionWorklistBase { return newInstruction; } - // This method is to be used when an instruction is found to be dead, + // This method is to be used when an instruction is found to be dead or // replaceable with another preexisting expression. Here we add all uses of // instruction to the worklist, and replace all uses of instruction with the // new value. diff --git a/include/swift/SILOptimizer/PassManager/Passes.def b/include/swift/SILOptimizer/PassManager/Passes.def index 01c568a52dd7a..f0c304002cdce 100644 --- a/include/swift/SILOptimizer/PassManager/Passes.def +++ b/include/swift/SILOptimizer/PassManager/Passes.def @@ -298,6 +298,8 @@ IRGEN_PASS(LoadableByAddress, "loadable-address", "SIL Large Loadable type by-address lowering.") PASS(MandatorySILLinker, "mandatory-linker", "Deserialize all referenced SIL functions that are shared or transparent") +IRGEN_PASS(PartialApplyLowering, "partial-apply-lowering", + "Partial Apply Lowering") PASS(PerformanceSILLinker, "performance-linker", "Deserialize all referenced SIL functions") PASS(RawSILInstLowering, "raw-sil-inst-lowering", diff --git a/include/swift/Sema/CSFix.h b/include/swift/Sema/CSFix.h index 8672f1992bf77..8c24d40308482 100644 --- a/include/swift/Sema/CSFix.h +++ b/include/swift/Sema/CSFix.h @@ -74,6 +74,9 @@ enum class FixKind : uint8_t { /// Mark function type as explicitly '@escaping'. ExplicitlyEscaping, + /// Mark function type as having a particular global actor. + MarkGlobalActorFunction, + /// Arguments have labeling failures - missing/extraneous or incorrect /// labels attached to the, fix it by suggesting proper labels. RelabelArguments, @@ -628,6 +631,23 @@ class MarkExplicitlyEscaping final : public ContextualMismatch { Type rhs, ConstraintLocator *locator); }; +/// Mark function type as being part of a global actor. +class MarkGlobalActorFunction final : public ContextualMismatch { + MarkGlobalActorFunction(ConstraintSystem &cs, Type lhs, Type rhs, + ConstraintLocator *locator) + : ContextualMismatch(cs, FixKind::MarkGlobalActorFunction, lhs, rhs, + locator) { + } + +public: + std::string getName() const override { return "add @escaping"; } + + bool diagnose(const Solution &solution, bool asNote = false) const override; + + static MarkGlobalActorFunction *create(ConstraintSystem &cs, Type lhs, + Type rhs, ConstraintLocator *locator); +}; + /// Introduce a '!' to force an optional unwrap. class ForceOptional final : public ContextualMismatch { ForceOptional(ConstraintSystem &cs, Type fromType, Type toType, diff --git a/include/swift/Sema/ConstraintLocator.h b/include/swift/Sema/ConstraintLocator.h index 8688ceac95ae0..c97baacdd03cb 100644 --- a/include/swift/Sema/ConstraintLocator.h +++ b/include/swift/Sema/ConstraintLocator.h @@ -200,9 +200,13 @@ class ConstraintLocator : public llvm::FoldingSetNode { /// via key path dynamic member lookup. bool isForKeyPathDynamicMemberLookup() const; - /// Determine whether this locator points to one of the key path - /// components. - bool isForKeyPathComponent() const; + /// Determine whether this locator points to element inside + /// of a key path component. + bool isInKeyPathComponent() const; + + /// Determine whether this locator points to a result type of + /// a key path component. + bool isForKeyPathComponentResult() const; /// Determine whether this locator points to the generic parameter. bool isForGenericParameter() const; @@ -743,7 +747,7 @@ class LocatorPathElt::PatternMatch final : public StoredPointerElement class LocatorPathElt::ArgumentAttribute final : public StoredIntegerElement<1> { public: - enum Attribute : uint8_t { InOut, Escaping, Concurrent }; + enum Attribute : uint8_t { InOut, Escaping, Concurrent, GlobalActor }; private: ArgumentAttribute(Attribute attr) @@ -764,6 +768,10 @@ class LocatorPathElt::ArgumentAttribute final : public StoredIntegerElement<1> { return ArgumentAttribute(Attribute::Concurrent); } + static ArgumentAttribute forGlobalActor() { + return ArgumentAttribute(Attribute::GlobalActor); + } + static bool classof(const LocatorPathElt *elt) { return elt->getKind() == ConstraintLocator::ArgumentAttribute; } diff --git a/include/swift/Subsystems.h b/include/swift/Subsystems.h index 1ab41b036fbb4..4dc369ca883d5 100644 --- a/include/swift/Subsystems.h +++ b/include/swift/Subsystems.h @@ -53,6 +53,12 @@ namespace swift { class IRGenOptions; class LangOptions; class ModuleDecl; + /// A opaque syntax node created by a \c SyntaxParseAction, whose contents + /// must be interpreted by the \c SyntaxParseAction which created it. + /// Requires the two low bits to be 0, so that it can be stored in an + /// \c llvm::PointerIntPair. This is in particular guaranteed for pointers + /// to C/C++ objects and for pointers that were generated by Swift and passed + /// to the compiler via a C API (in particular \c CLibParseActions ). typedef const void *OpaqueSyntaxNode; class Parser; class SerializationOptions; diff --git a/include/swift/SyntaxParse/SyntaxTreeCreator.h b/include/swift/SyntaxParse/SyntaxTreeCreator.h index ec7311f1d0ae8..a44cf1be52c3c 100644 --- a/include/swift/SyntaxParse/SyntaxTreeCreator.h +++ b/include/swift/SyntaxParse/SyntaxTreeCreator.h @@ -76,9 +76,9 @@ class SyntaxTreeCreator final : public SyntaxParseActions { CharSourceRange range, bool isMissing) override; - OpaqueSyntaxNode - makeDeferredLayout(syntax::SyntaxKind k, bool IsMissing, - const ArrayRef &children) override; + OpaqueSyntaxNode makeDeferredLayout( + syntax::SyntaxKind k, bool IsMissing, + const MutableArrayRef &children) override; OpaqueSyntaxNode recordDeferredToken(OpaqueSyntaxNode deferred) override; OpaqueSyntaxNode recordDeferredLayout(OpaqueSyntaxNode deferred) override; diff --git a/lib/APIDigester/CMakeLists.txt b/lib/APIDigester/CMakeLists.txt new file mode 100644 index 0000000000000..203cc07bbf96c --- /dev/null +++ b/lib/APIDigester/CMakeLists.txt @@ -0,0 +1,10 @@ +set_swift_llvm_is_available() + +add_swift_host_library(swiftAPIDigester STATIC + ModuleAnalyzerNodes.cpp + ModuleDiagsConsumer.cpp) + +target_link_libraries(swiftAPIDigester PRIVATE + swiftFrontend + swiftSIL + swiftIDE) diff --git a/tools/swift-api-digester/ModuleAnalyzerNodes.cpp b/lib/APIDigester/ModuleAnalyzerNodes.cpp similarity index 99% rename from tools/swift-api-digester/ModuleAnalyzerNodes.cpp rename to lib/APIDigester/ModuleAnalyzerNodes.cpp index c5d9739ad0e5f..d991219662bc4 100644 --- a/tools/swift-api-digester/ModuleAnalyzerNodes.cpp +++ b/lib/APIDigester/ModuleAnalyzerNodes.cpp @@ -1,7 +1,7 @@ #include "llvm/ADT/STLExtras.h" #include "swift/Basic/Defer.h" #include "swift/SIL/SILDeclRef.h" -#include +#include #include using namespace swift; diff --git a/tools/swift-api-digester/ModuleDiagsConsumer.cpp b/lib/APIDigester/ModuleDiagsConsumer.cpp similarity index 99% rename from tools/swift-api-digester/ModuleDiagsConsumer.cpp rename to lib/APIDigester/ModuleDiagsConsumer.cpp index 7ded7259b744e..044c9d05926d9 100644 --- a/tools/swift-api-digester/ModuleDiagsConsumer.cpp +++ b/lib/APIDigester/ModuleDiagsConsumer.cpp @@ -17,7 +17,7 @@ #include "swift/AST/DiagnosticEngine.h" #include "swift/AST/DiagnosticsModuleDiffer.h" -#include "ModuleDiagsConsumer.h" +#include "swift/APIDigester/ModuleDiagsConsumer.h" using namespace swift; diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index c773962c04a02..4bd00bb940f9d 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -3254,8 +3254,9 @@ void FunctionType::Profile(llvm::FoldingSetNodeID &ID, ID.AddPointer(result.getPointer()); if (info.hasValue()) { auto infoKey = info.getValue().getFuncAttrKey(); - ID.AddInteger(infoKey.first); - ID.AddPointer(infoKey.second); + ID.AddInteger(std::get<0>(infoKey)); + ID.AddPointer(std::get<1>(infoKey)); + ID.AddPointer(std::get<2>(infoKey)); } } @@ -3283,8 +3284,13 @@ FunctionType *FunctionType::get(ArrayRef params, bool hasClangInfo = info.hasValue() && !info.getValue().getClangTypeInfo().empty(); - size_t allocSize = totalSizeToAlloc( - params.size(), hasClangInfo ? 1 : 0); + Type globalActor; + if (info.hasValue()) + globalActor = info->getGlobalActor(); + + size_t allocSize = totalSizeToAlloc< + AnyFunctionType::Param, ClangTypeInfo, Type + >(params.size(), hasClangInfo ? 1 : 0, globalActor ? 1 : 0); void *mem = ctx.Allocate(allocSize, alignof(FunctionType), arena); bool isCanonical = isFunctionTypeCanonical(params, result); @@ -3295,6 +3301,9 @@ FunctionType *FunctionType::get(ArrayRef params, isCanonical = false; } + if (globalActor && !globalActor->isCanonical()) + isCanonical = false; + auto funcTy = new (mem) FunctionType(params, result, info, isCanonical ? &ctx : nullptr, properties); @@ -3314,6 +3323,8 @@ FunctionType::FunctionType(ArrayRef params, Type output, auto clangTypeInfo = info.getValue().getClangTypeInfo(); if (!clangTypeInfo.empty()) *getTrailingObjects() = clangTypeInfo; + if (Type globalActor = info->getGlobalActor()) + *getTrailingObjects() = globalActor; } } @@ -3326,8 +3337,9 @@ void GenericFunctionType::Profile(llvm::FoldingSetNodeID &ID, ID.AddPointer(result.getPointer()); if (info.hasValue()) { auto infoKey = info.getValue().getFuncAttrKey(); - ID.AddInteger(infoKey.first); - ID.AddPointer(infoKey.second); + ID.AddInteger(std::get<0>(infoKey)); + ID.AddPointer(std::get<1>(infoKey)); + ID.AddPointer(std::get<2>(infoKey)); } } @@ -3364,8 +3376,16 @@ GenericFunctionType *GenericFunctionType::get(GenericSignature sig, = ctx.getImpl().GenericFunctionTypes.FindNodeOrInsertPos(id, insertPos)) { return funcTy; } - - size_t allocSize = totalSizeToAlloc(params.size()); + + Type globalActor; + if (info.hasValue()) + globalActor = info->getGlobalActor(); + + if (globalActor && !globalActor->isCanonical()) + isCanonical = false; + + size_t allocSize = totalSizeToAlloc( + params.size(), globalActor ? 1 : 0); void *mem = ctx.Allocate(allocSize, alignof(GenericFunctionType)); auto properties = getGenericFunctionRecursiveProperties(params, result); @@ -3388,6 +3408,10 @@ GenericFunctionType::GenericFunctionType( properties, params.size(), info), Signature(sig) { std::uninitialized_copy(params.begin(), params.end(), getTrailingObjects()); + if (info) { + if (Type globalActor = info->getGlobalActor()) + *getTrailingObjects() = globalActor; + } } GenericTypeParamType *GenericTypeParamType::get(unsigned depth, unsigned index, diff --git a/lib/AST/ASTDemangler.cpp b/lib/AST/ASTDemangler.cpp index ed72d1ebdde90..f8900593b729f 100644 --- a/lib/AST/ASTDemangler.cpp +++ b/lib/AST/ASTDemangler.cpp @@ -406,9 +406,12 @@ Type ASTBuilder::createFunctionType( clangFunctionType = Ctx.getClangFunctionType(funcParams, output, representation); + Type globalActor; + // FIXME: Demangle global actors. + auto einfo = FunctionType::ExtInfoBuilder(representation, noescape, flags.isThrowing(), - diffKind, clangFunctionType) + diffKind, clangFunctionType, globalActor) .withAsync(flags.isAsync()) .build(); @@ -478,11 +481,24 @@ getResultDifferentiability(ImplResultDifferentiability diffKind) { Type ASTBuilder::createImplFunctionType( Demangle::ImplParameterConvention calleeConvention, + BuiltRequirement *witnessMethodConformanceRequirement, + ArrayRef GenericParameters, + ArrayRef Requirements, ArrayRef> params, ArrayRef> results, Optional> errorResult, ImplFunctionTypeFlags flags) { GenericSignature genericSig; + if (GenericParameters.size() > 0) { + llvm::SmallVector CastGenericParameters; + for (auto Parameter : GenericParameters) { + CastGenericParameters.push_back( + Parameter->castTo()); + } + genericSig = GenericSignature::get(CastGenericParameters, Requirements); + } else { + assert(Requirements.size() == 0); + } SILCoroutineKind funcCoroutineKind = SILCoroutineKind::None; ParameterConvention funcCalleeConvention = @@ -567,11 +583,15 @@ Type ASTBuilder::createImplFunctionType( representation, flags.isPseudogeneric(), !flags.isEscaping(), flags.isConcurrent(), flags.isAsync(), diffKind, clangFnType) .build(); - - return SILFunctionType::get(genericSig, einfo, funcCoroutineKind, - funcCalleeConvention, funcParams, funcYields, - funcResults, funcErrorResult, - SubstitutionMap(), SubstitutionMap(), Ctx); + auto witnessMethodConformance = + witnessMethodConformanceRequirement + ? ProtocolConformanceRef( + witnessMethodConformanceRequirement->getProtocolDecl()) + : ProtocolConformanceRef(); + return SILFunctionType::get( + genericSig, einfo, funcCoroutineKind, funcCalleeConvention, funcParams, + funcYields, funcResults, funcErrorResult, + SubstitutionMap(), SubstitutionMap(), Ctx, witnessMethodConformance); } Type ASTBuilder::createProtocolCompositionType( diff --git a/lib/AST/ASTDumper.cpp b/lib/AST/ASTDumper.cpp index 2ca611409d434..ac242c82bc7bc 100644 --- a/lib/AST/ASTDumper.cpp +++ b/lib/AST/ASTDumper.cpp @@ -3837,6 +3837,11 @@ namespace { T->getClangTypeInfo().dump(os, ctx); printField("clang_type", os.str()); } + + if (Type globalActor = T->getGlobalActor()) { + printField("global_actor", globalActor.getString()); + } + printAnyFunctionParams(T->getParams(), "input"); Indent -=2; printRec("output", T->getResult()); diff --git a/lib/AST/ASTMangler.cpp b/lib/AST/ASTMangler.cpp index 7e3ee7904368f..de6b0312833af 100644 --- a/lib/AST/ASTMangler.cpp +++ b/lib/AST/ASTMangler.cpp @@ -2857,10 +2857,21 @@ CanType ASTMangler::getDeclTypeForMangling( return C.TheErrorType; } + Type ty = decl->getInterfaceType()->getReferenceStorageReferent(); + + // Strip the global actor out of the mangling. + ty = ty.transform([](Type type) { + if (auto fnType = type->getAs()) { + if (fnType->getGlobalActor()) { + return Type(fnType->withExtInfo( + fnType->getExtInfo().withGlobalActor(Type()))); + } + } + + return type; + }); - auto canTy = decl->getInterfaceType() - ->getReferenceStorageReferent() - ->getCanonicalType(); + auto canTy = ty->getCanonicalType(); if (auto gft = dyn_cast(canTy)) { genericSig = gft.getGenericSignature(); diff --git a/lib/AST/ASTPrinter.cpp b/lib/AST/ASTPrinter.cpp index 8a69baea5ef05..662bce29fc251 100644 --- a/lib/AST/ASTPrinter.cpp +++ b/lib/AST/ASTPrinter.cpp @@ -2479,6 +2479,12 @@ static bool usesFeatureMarkerProtocol(Decl *decl) { if (proto->isMarkerProtocol()) return true; + // Swift.Error and Swift.CodingKey "don't" use the marker protocol. + if (proto->isSpecificProtocol(KnownProtocolKind::Error) || + proto->isSpecificProtocol(KnownProtocolKind::CodingKey)) { + return false; + } + if (checkInherited(proto->getInherited())) return true; @@ -4579,6 +4585,12 @@ class TypePrinter : public TypeVisitor { } } + if (Type globalActor = info.getGlobalActor()) { + Printer << "@"; + visit(globalActor); + Printer << " "; + } + if (!Options.excludeAttrKind(TAK_concurrent) && info.isConcurrent()) { Printer << "@concurrent "; diff --git a/lib/AST/Builtins.cpp b/lib/AST/Builtins.cpp index a51e4d3cb18d9..cb9de1eac4c96 100644 --- a/lib/AST/Builtins.cpp +++ b/lib/AST/Builtins.cpp @@ -1361,8 +1361,6 @@ static ValueDecl *getCreateAsyncTaskFuture(ASTContext &ctx, Identifier id) { auto genericParam = makeGenericParam().build(builder); builder.addParameter( makeConcrete(ctx.getIntDecl()->getDeclaredInterfaceType())); - builder.addParameter( - makeConcrete(OptionalType::get(ctx.TheNativeObjectType))); auto extInfo = ASTExtInfoBuilder().withAsync().withThrows().build(); builder.addParameter( makeConcrete(FunctionType::get({ }, genericParam, extInfo))); @@ -1375,8 +1373,6 @@ static ValueDecl *getCreateAsyncTaskGroupFuture(ASTContext &ctx, Identifier id) auto genericParam = makeGenericParam().build(builder); builder.addParameter( makeConcrete(ctx.getIntDecl()->getDeclaredInterfaceType())); // flags - builder.addParameter( - makeConcrete(OptionalType::get(ctx.TheNativeObjectType))); // parent builder.addParameter( makeConcrete(OptionalType::get(ctx.TheRawPointerType))); // group auto extInfo = ASTExtInfoBuilder().withAsync().withThrows().build(); diff --git a/lib/AST/GenericSignatureBuilder.cpp b/lib/AST/GenericSignatureBuilder.cpp index a06036b0f0d56..3bb67ca828d44 100644 --- a/lib/AST/GenericSignatureBuilder.cpp +++ b/lib/AST/GenericSignatureBuilder.cpp @@ -124,6 +124,8 @@ STATISTIC(NumRewriteRhsSimplifiedToLhs, "# of rewrite rule right-hand sides simplified to lhs (and removed)"); STATISTIC(NumRewriteRulesRedundant, "# of rewrite rules that are redundant (and removed)"); +STATISTIC(NumSignaturesRebuiltWithoutRedundantRequirements, + "# of generic signatures which had a concretized conformance requirement"); namespace { @@ -616,6 +618,11 @@ class GenericSignatureBuilder::ExplicitRequirement { return true; } + + friend bool operator!=(const ExplicitRequirement &lhs, + const ExplicitRequirement &rhs) { + return !(lhs == rhs); + } }; namespace llvm { @@ -690,8 +697,13 @@ struct GenericSignatureBuilder::Implementation { /// Whether there were any errors. bool HadAnyError = false; - /// The set of computed redundant explicit requirements. - llvm::DenseSet RedundantRequirements; + /// A mapping of redundant explicit requirements to the best root requirement + /// that implies them. + using RedundantRequirementMap = + llvm::DenseMap>; + + RedundantRequirementMap RedundantRequirements; #ifndef NDEBUG /// Whether we've already computed redundant requiremnts. @@ -1758,6 +1770,37 @@ SourceLoc FloatingRequirementSource::getLoc() const { return SourceLoc(); } +bool FloatingRequirementSource::isDerived() const { + switch (kind) { + case Explicit: + case Inferred: + case NestedTypeNameMatch: + return false; + + case AbstractProtocol: + switch (storage.get()->kind) { + case RequirementSource::RequirementSignatureSelf: + return false; + + case RequirementSource::Concrete: + case RequirementSource::Explicit: + case RequirementSource::Inferred: + case RequirementSource::NestedTypeNameMatch: + case RequirementSource::Parent: + case RequirementSource::ProtocolRequirement: + case RequirementSource::InferredProtocolRequirement: + case RequirementSource::Superclass: + case RequirementSource::Layout: + case RequirementSource::EquivalentType: + return true; + } + + case Resolved: + return storage.get()->isDerivedRequirement(); + } + llvm_unreachable("unhandled kind"); +} + bool FloatingRequirementSource::isExplicit() const { switch (kind) { case Explicit: @@ -1834,7 +1877,6 @@ FloatingRequirementSource FloatingRequirementSource::asInferred( } bool FloatingRequirementSource::isRecursive( - Type rootType, GenericSignatureBuilder &builder) const { llvm::SmallSet, 32> visitedAssocReqs; for (auto storedSource = storage.dyn_cast(); @@ -2556,9 +2598,20 @@ GenericSignatureBuilder::resolveConcreteConformance(ResolvedType type, } else { concreteSource = concreteSource->viaConcrete(*this, conformance); equivClass->recordConformanceConstraint(*this, type, proto, concreteSource); - if (addConditionalRequirements(conformance, /*inferForModule=*/nullptr, - concreteSource->getLoc())) - return nullptr; + + // Only infer conditional requirements from explicit sources. + bool hasExplicitSource = llvm::any_of( + equivClass->concreteTypeConstraints, + [](const ConcreteConstraint &constraint) { + return (!constraint.source->isDerivedRequirement() && + constraint.source->getLoc().isValid()); + }); + + if (hasExplicitSource) { + if (addConditionalRequirements(conformance, /*inferForModule=*/nullptr, + concreteSource->getLoc())) + return nullptr; + } } return concreteSource; @@ -2590,9 +2643,20 @@ const RequirementSource *GenericSignatureBuilder::resolveSuperConformance( superclassSource = superclassSource->viaSuperclass(*this, conformance); equivClass->recordConformanceConstraint(*this, type, proto, superclassSource); - if (addConditionalRequirements(conformance, /*inferForModule=*/nullptr, - superclassSource->getLoc())) - return nullptr; + + // Only infer conditional requirements from explicit sources. + bool hasExplicitSource = llvm::any_of( + equivClass->superclassConstraints, + [](const ConcreteConstraint &constraint) { + return (!constraint.source->isDerivedRequirement() && + constraint.source->getLoc().isValid()); + }); + + if (hasExplicitSource) { + if (addConditionalRequirements(conformance, /*inferForModule=*/nullptr, + superclassSource->getLoc())) + return nullptr; + } return superclassSource; } @@ -3930,12 +3994,12 @@ auto GenericSignatureBuilder::resolve(UnresolvedType paOrT, return ResolvedType(pa); // Determine what kind of resolution we want. - Type type = paOrT.get(); ArchetypeResolutionKind resolutionKind = ArchetypeResolutionKind::WellFormed; - if (!source.isExplicit() && source.isRecursive(type, *this)) + if (!source.isExplicit() && source.isRecursive(*this)) resolutionKind = ArchetypeResolutionKind::AlreadyKnown; + Type type = paOrT.get(); return maybeResolveEquivalenceClass(type, resolutionKind, /*wantExactPotentialArchetype=*/true); } @@ -4583,7 +4647,7 @@ ConstraintResult GenericSignatureBuilder::addTypeRequirement( unresolvedHandling); } - // If the resolved subject is a type, there may be things we can infer (if it + // If the resolved subject is concrete, there may be things we can infer (if it // conditionally conforms to the protocol), and we can probably perform // diagnostics here. if (auto subjectType = resolvedSubject.getAsConcreteType()) { @@ -4599,9 +4663,12 @@ ConstraintResult GenericSignatureBuilder::addTypeRequirement( // FIXME: diagnose if there's no conformance. if (conformance) { - if (addConditionalRequirements(conformance, inferForModule, - source.getLoc())) - return ConstraintResult::Conflicting; + // Only infer conditional requirements from explicit sources. + if (!source.isDerived()) { + if (addConditionalRequirements(conformance, inferForModule, + source.getLoc())) + return ConstraintResult::Conflicting; + } } } } @@ -5036,7 +5103,9 @@ ConstraintResult GenericSignatureBuilder::addSameTypeRequirement( return addSameTypeRequirement(paOrT1, paOrT2, source, unresolvedHandling, [&](Type type1, Type type2) { Impl->HadAnyError = true; - if (source.getLoc().isValid()) { + if (source.getLoc().isValid() && + !type1->hasError() && + !type2->hasError()) { Diags.diagnose(source.getLoc(), diag::requires_same_concrete_type, type1, type2); } @@ -5217,7 +5286,9 @@ GenericSignatureBuilder::addRequirement(const Requirement &req, UnresolvedHandlingKind::GenerateConstraints, [&](Type type1, Type type2) { Impl->HadAnyError = true; - if (source.getLoc().isValid()) { + if (source.getLoc().isValid() && + !type1->hasError() && + !type2->hasError()) { Diags.diagnose(source.getLoc(), diag::requires_same_concrete_type, type1, type2); } @@ -5569,8 +5640,8 @@ class RedundantRequirementGraph { SmallVector vertices; - ComponentID nextComponent = 0; - VertexID nextIndex = 0; + ComponentID componentCount = 0; + VertexID vertexCount = 0; SmallVector stack; @@ -5729,11 +5800,11 @@ class RedundantRequirementGraph { void strongConnect(VertexID v) { // Set the depth index for v to the smallest unused index. assert(vertices[v].index == Vertex::UndefinedIndex); - vertices[v].index = nextIndex; + vertices[v].index = vertexCount; assert(vertices[v].lowLink == Vertex::UndefinedIndex); - vertices[v].lowLink = nextIndex; + vertices[v].lowLink = vertexCount; - nextIndex++; + vertexCount++; stack.push_back(v); assert(!vertices[v].onStack); @@ -5771,40 +5842,60 @@ class RedundantRequirementGraph { vertices[w].onStack = false; assert(vertices[w].component == Vertex::UndefinedComponent); - vertices[w].component = nextComponent; + vertices[w].component = componentCount; } while (v != w); - nextComponent++; + componentCount++; } } public: + using RedundantRequirementMap = + llvm::DenseMap>; + void computeRedundantRequirements(SourceManager &SM, - llvm::DenseSet &redundant) { + RedundantRequirementMap &redundant) { // First, compute SCCs. computeSCCs(); - // The number of edges from other connected components to this one. - SmallVector inboundComponentEdges; - inboundComponentEdges.resize(nextComponent); + // The set of edges pointing to each connected component. + SmallVector, 2> inboundComponentEdges; + inboundComponentEdges.resize(componentCount); + + // The set of edges originating from this connected component. + SmallVector, 2> outboundComponentEdges; + outboundComponentEdges.resize(componentCount); - // Visit all vertices and count inter-component edges. + // Visit all vertices and build the adjacency sets for the connected + // component graph. for (const auto &vertex : vertices) { assert(vertex.component != Vertex::UndefinedComponent); for (auto successor : vertex.successors) { ComponentID otherComponent = vertices[successor].component; - if (vertex.component != otherComponent) - ++inboundComponentEdges[otherComponent]; + if (vertex.component != otherComponent) { + inboundComponentEdges[otherComponent].push_back(vertex.component); + outboundComponentEdges[vertex.component].push_back(otherComponent); + } } } - // The best explicit requirement for each root SCC. + auto isRootComponent = [&](ComponentID component) -> bool { + return inboundComponentEdges[component].empty(); + }; + + // The set of root components. + llvm::SmallDenseSet rootComponents; + + // The best explicit requirement for each root component. SmallVector, 2> bestExplicitReq; - bestExplicitReq.resize(nextComponent); + bestExplicitReq.resize(componentCount); - // Visit all vertices and find the best requirement for each root SCC. + // Visit all vertices and find the best requirement for each root component. for (const auto &vertex : vertices) { - if (inboundComponentEdges[vertex.component] == 0) { + if (isRootComponent(vertex.component)) { + rootComponents.insert(vertex.component); + // If this vertex is part of a root SCC, see if the requirement is // better than the one we have so far. auto &best = bestExplicitReq[vertex.component]; @@ -5813,26 +5904,61 @@ class RedundantRequirementGraph { } } - // Compute the set of redundant requirements. - for (const auto &vertex : vertices) { - if (inboundComponentEdges[vertex.component] == 0) { - // We have a root SCC. This requirement is redundant unless - // it is the best requirement for this SCC. - auto best = bestExplicitReq[vertex.component]; - assert(best.hasValue() && - "Did not record best requirement for root SCC?"); + // The set of root components that each component is reachable from. + SmallVector, 2> reachableFromRoot; + reachableFromRoot.resize(componentCount); - if (vertex.req == *best) - continue; + // Traverse the graph of connected components starting from the roots. + for (auto rootComponent : rootComponents) { + SmallVector worklist; + + auto addToWorklist = [&](ComponentID nextComponent) { + if (!reachableFromRoot[nextComponent].count(rootComponent)) + worklist.push_back(nextComponent); + }; + + addToWorklist(rootComponent); + + while (!worklist.empty()) { + auto component = worklist.back(); + worklist.pop_back(); + + reachableFromRoot[component].insert(rootComponent); + + for (auto nextComponent : outboundComponentEdges[component]) + addToWorklist(nextComponent); + } + } + + // Compute the mapping of redundant requirements to the best root + // requirement that implies them. + for (const auto &vertex : vertices) { + if (isRootComponent(vertex.component)) { + // A root component is reachable from itself, and itself only. + assert(reachableFromRoot[vertex.component].size() == 1); + assert(reachableFromRoot[vertex.component].count(vertex.component) == 1); } else { - // We have a non-root SCC. This requirement is always - // redundant. assert(!bestExplicitReq[vertex.component].hasValue() && "Recorded best requirement for non-root SCC?"); } - auto inserted = redundant.insert(vertex.req); - assert(inserted.second && "Saw the same vertex twice?"); + // We have a non-root component. This requirement is always + // redundant. + auto reachableFromRootSet = reachableFromRoot[vertex.component]; + assert(reachableFromRootSet.size() > 0); + + for (auto rootComponent : reachableFromRootSet) { + assert(isRootComponent(rootComponent)); + + auto best = bestExplicitReq[rootComponent]; + assert(best.hasValue() && + "Did not record best requirement for root SCC?"); + + assert(vertex.req != *best || vertex.component == rootComponent); + if (vertex.req != *best) { + redundant[vertex.req].insert(*best); + } + } } } @@ -8052,9 +8178,60 @@ static void checkGenericSignature(CanGenericSignature canSig, } #endif +bool GenericSignatureBuilder::hasExplicitConformancesImpliedByConcrete() const { + for (auto pair : Impl->RedundantRequirements) { + if (pair.first.getKind() != RequirementKind::Conformance) + continue; + + for (auto impliedByReq : pair.second) { + if (impliedByReq.getKind() == RequirementKind::Superclass) + return true; + + if (impliedByReq.getKind() == RequirementKind::SameType) + return true; + } + } + + return false; +} + +static Type stripBoundDependentMemberTypes(Type t) { + if (auto *depMemTy = t->getAs()) { + return DependentMemberType::get( + stripBoundDependentMemberTypes(depMemTy->getBase()), + depMemTy->getName()); + } + + return t; +} + +static Requirement stripBoundDependentMemberTypes(Requirement req) { + auto subjectType = stripBoundDependentMemberTypes(req.getFirstType()); + + switch (req.getKind()) { + case RequirementKind::Conformance: + return Requirement(RequirementKind::Conformance, subjectType, + req.getSecondType()); + + case RequirementKind::Superclass: + case RequirementKind::SameType: + return Requirement(req.getKind(), subjectType, + req.getSecondType().transform([](Type t) { + return stripBoundDependentMemberTypes(t); + })); + + case RequirementKind::Layout: + return Requirement(RequirementKind::Conformance, subjectType, + req.getLayoutConstraint()); + } + + llvm_unreachable("Bad requirement kind"); +} + GenericSignature GenericSignatureBuilder::computeGenericSignature( bool allowConcreteGenericParams, - bool allowBuilderToMove) && { + bool buildingRequirementSignature, + bool rebuildingWithoutRedundantConformances) && { // Finalize the builder, producing any necessary diagnostics. finalize(getGenericParams(), allowConcreteGenericParams); @@ -8065,6 +8242,43 @@ GenericSignature GenericSignatureBuilder::computeGenericSignature( // Form the generic signature. auto sig = GenericSignature::get(getGenericParams(), requirements); + // If any of our explicit conformance requirements were implied by + // superclass or concrete same-type requirements, we have to build the + // signature again, since dropping the redundant conformance requirements + // changes the canonical type computation. + // + // However, if we already diagnosed an error, don't do this, because + // we might end up emitting duplicate diagnostics. + // + // Also, don't do this when building a requirement signature. + if (!buildingRequirementSignature && + !Impl->HadAnyError && + hasExplicitConformancesImpliedByConcrete()) { + NumSignaturesRebuiltWithoutRedundantRequirements++; + + if (rebuildingWithoutRedundantConformances) { + llvm::errs() << "Rebuilt signature still has " + << "redundant conformance requirements: "; + llvm::errs() << sig << "\n"; + abort(); + } + + GenericSignatureBuilder newBuilder(Context); + + for (auto param : sig->getGenericParams()) + newBuilder.addGenericParameter(param); + + for (auto &req : sig->getRequirements()) { + newBuilder.addRequirement(stripBoundDependentMemberTypes(req), + FloatingRequirementSource::forAbstract(), nullptr); + } + + return std::move(newBuilder).computeGenericSignature( + allowConcreteGenericParams, + buildingRequirementSignature, + /*rebuildingWithoutRedundantConformances=*/true); + } + #ifndef NDEBUG if (!Impl->HadAnyError) { checkGenericSignature(sig.getCanonicalSignature(), *this); @@ -8076,7 +8290,9 @@ GenericSignature GenericSignatureBuilder::computeGenericSignature( // will produce the same thing. // // We cannot do this when there were errors. - if (allowBuilderToMove && !Impl->HadAnyError) { + // + // Also, we cannot do this when building a requirement signature. + if (!buildingRequirementSignature && !Impl->HadAnyError) { // Register this generic signature builder as the canonical builder for the // given signature. Context.registerGenericSignatureBuilder(sig, std::move(*this)); diff --git a/lib/AST/NameLookup.cpp b/lib/AST/NameLookup.cpp index e496eb1c846eb..050e637c36e12 100644 --- a/lib/AST/NameLookup.cpp +++ b/lib/AST/NameLookup.cpp @@ -2625,6 +2625,7 @@ CustomAttrNominalRequest::evaluate(Evaluator &evaluator, } ctx.Diags.diagnose(attr->getLocation(), diag::unknown_attribute, typeName); + attr->setInvalid(); return nullptr; } diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index e44b307ebfb99..62a4a520335ae 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -3481,6 +3481,17 @@ ClangTypeInfo AnyFunctionType::getClangTypeInfo() const { } } +Type AnyFunctionType::getGlobalActor() const { + switch (getKind()) { + case TypeKind::Function: + return cast(this)->getGlobalActor(); + case TypeKind::GenericFunction: + return cast(this)->getGlobalActor(); + default: + llvm_unreachable("Illegal type kind for AnyFunctionType."); + } +} + ClangTypeInfo AnyFunctionType::getCanonicalClangTypeInfo() const { return getClangTypeInfo().getCanonical(); } diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 84d950998897c..69d6d1a3bcd7b 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -14,6 +14,7 @@ list(APPEND LLVM_COMMON_DEPENDS intrinsics_gen clang-tablegen-targets) list(APPEND LLVM_COMMON_DEPENDS swift-syntax-generated-headers) list(APPEND LLVM_COMMON_DEPENDS swift-parse-syntax-generated-headers) +add_subdirectory(APIDigester) add_subdirectory(AST) add_subdirectory(ASTSectionImporter) add_subdirectory(Basic) diff --git a/lib/ClangImporter/ImportDecl.cpp b/lib/ClangImporter/ImportDecl.cpp index 79b71d532feda..bdadf3d314ec0 100644 --- a/lib/ClangImporter/ImportDecl.cpp +++ b/lib/ClangImporter/ImportDecl.cpp @@ -3334,6 +3334,22 @@ namespace { return result; } + bool isCxxRecordImportable(const clang::CXXRecordDecl *decl) { + if (auto dtor = decl->getDestructor()) { + if (dtor->isDeleted() || dtor->getAccess() != clang::AS_public) { + return false; + } + } + + // If we have no way of copying the type we can't import the class + // at all because we cannot express the correct semantics as a swift + // struct. + return llvm::none_of(decl->ctors(), [](clang::CXXConstructorDecl *ctor) { + return ctor->isCopyConstructor() && + (ctor->isDeleted() || ctor->getAccess() != clang::AS_public); + }); + } + Decl *VisitRecordDecl(const clang::RecordDecl *decl) { // Track whether this record contains fields we can't reference in Swift // as stored properties. @@ -3626,30 +3642,9 @@ namespace { result->setHasUnreferenceableStorage(hasUnreferenceableStorage); - if (cxxRecordDecl) { + if (cxxRecordDecl) result->setIsCxxNonTrivial(!cxxRecordDecl->isTriviallyCopyable()); - for (auto ctor : cxxRecordDecl->ctors()) { - if (ctor->isCopyConstructor()) { - // If we have no way of copying the type we can't import the class - // at all because we cannot express the correct semantics as a swift - // struct. - if (ctor->isDeleted() || ctor->getAccess() != clang::AS_public) - return nullptr; - } - if (ctor->getAccess() != clang::AS_public) { - result->setIsCxxNonTrivial(true); - break; - } - } - - if (auto dtor = cxxRecordDecl->getDestructor()) { - if (dtor->isDeleted() || dtor->getAccess() != clang::AS_public) { - return nullptr; - } - } - } - return result; } @@ -3704,6 +3699,11 @@ namespace { } } + // It is import that we bail on an unimportable record *before* we import + // any of its members or cache the decl. + if (!isCxxRecordImportable(decl)) + return nullptr; + return VisitRecordDecl(decl); } @@ -8028,6 +8028,7 @@ void ClangImporter::Implementation::importAttributes( // Scan through Clang attributes and map them onto Swift // equivalents. + PatternBindingInitializer *initContext = nullptr; bool AnyUnavailable = MappedDecl->getAttrs().isUnavailable(C); for (clang::NamedDecl::attr_iterator AI = ClangDecl->attr_begin(), AE = ClangDecl->attr_end(); AI != AE; ++AI) { @@ -8207,7 +8208,8 @@ void ClangImporter::Implementation::importAttributes( SourceLoc atLoc; if (parser.consumeIf(tok::at_sign, atLoc)) { (void)parser.parseDeclAttribute( - MappedDecl->getAttrs(), atLoc, /*isFromClangAttribute=*/true); + MappedDecl->getAttrs(), atLoc, initContext, + /*isFromClangAttribute=*/true); } else { // Complain about the missing '@'. auto &clangSrcMgr = getClangASTContext().getSourceManager(); diff --git a/lib/Demangling/Demangler.cpp b/lib/Demangling/Demangler.cpp index 006a8bf711c67..cd97d03d38f37 100644 --- a/lib/Demangling/Demangler.cpp +++ b/lib/Demangling/Demangler.cpp @@ -123,6 +123,9 @@ bool swift::Demangle::isFunctionAttr(Node::Kind kind) { case Node::Kind::DynamicallyReplaceableFunctionKey: case Node::Kind::DynamicallyReplaceableFunctionVar: case Node::Kind::AsyncFunctionPointer: + case Node::Kind::AsyncNonconstantPartialApplyThunk: + case Node::Kind::AsyncAwaitResumePartialFunction: + case Node::Kind::AsyncSuspendResumePartialFunction: return true; default: return false; @@ -2296,6 +2299,14 @@ NodePointer Demangler::demangleThunkOrSpecialization() { case 'X': return createNode(Node::Kind::DynamicallyReplaceableFunctionVar); case 'x': return createNode(Node::Kind::DynamicallyReplaceableFunctionKey); case 'I': return createNode(Node::Kind::DynamicallyReplaceableFunctionImpl); + case 'Y': + case 'Q': { + NodePointer discriminator = demangleIndexAsNode(); + return createWithChild( + c == 'Q' ? Node::Kind::AsyncAwaitResumePartialFunction : + /*'Y'*/ Node::Kind::AsyncSuspendResumePartialFunction, + discriminator); + } case 'C': { NodePointer type = popNode(Node::Kind::Type); return createWithChild(Node::Kind::CoroutineContinuationPrototype, type); @@ -2520,6 +2531,11 @@ NodePointer Demangler::demangleThunkOrSpecialization() { return demangleAutoDiffFunctionOrSimpleThunk( Node::Kind::AutoDiffFunction); } + case 'w': { + NodePointer discriminator = demangleIndexAsNode(); + return createWithChild(Node::Kind::AsyncNonconstantPartialApplyThunk, + discriminator); + } default: return nullptr; } diff --git a/lib/Demangling/NodePrinter.cpp b/lib/Demangling/NodePrinter.cpp index 8d7bab3b3bdfd..e6af32e34b481 100644 --- a/lib/Demangling/NodePrinter.cpp +++ b/lib/Demangling/NodePrinter.cpp @@ -573,6 +573,9 @@ class NodePrinter { case Node::Kind::AutoDiffFunctionKind: case Node::Kind::DifferentiabilityWitness: case Node::Kind::IndexSubset: + case Node::Kind::AsyncNonconstantPartialApplyThunk: + case Node::Kind::AsyncAwaitResumePartialFunction: + case Node::Kind::AsyncSuspendResumePartialFunction: return false; } printer_unreachable("bad node kind"); @@ -2774,7 +2777,26 @@ NodePointer NodePrinter::print(NodePointer Node, bool asPrefixContext) { case Node::Kind::AsyncFunctionPointer: Printer << "async function pointer to "; return nullptr; + case Node::Kind::AsyncNonconstantPartialApplyThunk: + Printer << "("; + print(Node->getChild(0)); + Printer << ")"; + Printer << " thunk for non-constant partial apply in "; + return nullptr; + case Node::Kind::AsyncAwaitResumePartialFunction: + Printer << "("; + print(Node->getChild(0)); + Printer << ")"; + Printer << " await resume partial function for "; + return nullptr; + case Node::Kind::AsyncSuspendResumePartialFunction: + Printer << "("; + print(Node->getChild(0)); + Printer << ")"; + Printer << " suspend resume partial function for "; + return nullptr; } + printer_unreachable("bad node kind!"); } diff --git a/lib/Demangling/OldRemangler.cpp b/lib/Demangling/OldRemangler.cpp index f1ecb813d64bd..8c0188e47df68 100644 --- a/lib/Demangling/OldRemangler.cpp +++ b/lib/Demangling/OldRemangler.cpp @@ -606,6 +606,17 @@ void Remangler::mangleDynamicallyReplaceableFunctionVar(Node *node) { Buffer << "TX"; } +void Remangler::mangleAsyncNonconstantPartialApplyThunk(Node *node) { + unreachable("unsupported"); +} + +void Remangler::mangleAsyncAwaitResumePartialFunction(Node *node) { + unreachable("unsupported"); +} +void Remangler::mangleAsyncSuspendResumePartialFunction(Node *node) { + unreachable("unsupported"); +} + void Remangler::mangleDirectness(Node *node) { auto getChar = [](Directness d) -> char { switch (d) { diff --git a/lib/Demangling/Remangler.cpp b/lib/Demangling/Remangler.cpp index 150e850b2be27..032321d1e6e3e 100644 --- a/lib/Demangling/Remangler.cpp +++ b/lib/Demangling/Remangler.cpp @@ -1396,6 +1396,9 @@ void Remangler::mangleGlobal(Node *node) { case Node::Kind::DynamicallyReplaceableFunctionImpl: case Node::Kind::DynamicallyReplaceableFunctionVar: case Node::Kind::AsyncFunctionPointer: + case Node::Kind::AsyncNonconstantPartialApplyThunk: + case Node::Kind::AsyncAwaitResumePartialFunction: + case Node::Kind::AsyncSuspendResumePartialFunction: mangleInReverseOrder = true; break; default: @@ -1904,6 +1907,21 @@ void Remangler::mangleDynamicallyReplaceableFunctionVar(Node *node) { Buffer << "TX"; } +void Remangler::mangleAsyncNonconstantPartialApplyThunk(Node *node) { + Buffer << "Tw"; + mangleChildNode(node, 0); +} + +void Remangler::mangleAsyncAwaitResumePartialFunction(Node *node) { + Buffer << "TQ"; + mangleChildNode(node, 0); +} + +void Remangler::mangleAsyncSuspendResumePartialFunction(Node *node) { + Buffer << "TY"; + mangleChildNode(node, 0); +} + void Remangler::manglePostfixOperator(Node *node) { mangleIdentifierImpl(node, /*isOperator*/ true); Buffer << "oP"; diff --git a/lib/Driver/DarwinToolChains.cpp b/lib/Driver/DarwinToolChains.cpp index 95accad29f2bd..a0ee603a9f3ef 100644 --- a/lib/Driver/DarwinToolChains.cpp +++ b/lib/Driver/DarwinToolChains.cpp @@ -901,9 +901,15 @@ void toolchains::Darwin::validateArguments(DiagnosticEngine &diags, const llvm::opt::ArgList &args, StringRef defaultTarget) const { - // Validating arclite library path when link-objc-runtime. - validateLinkObjcRuntimeARCLiteLib(*this, diags, args); - + if (!getDriver().isDummyDriverForFrontendInvocation()) { + // Validating arclite library path when link-objc-runtime. + // If the driver is just set up to retrieve the swift-frontend invocation, + // we don't care about link-time, so we can skip this step, which may be + // expensive since it might call to `xcrun` to find `clang` and `arclite` + // relative to `clang`. + validateLinkObjcRuntimeARCLiteLib(*this, diags, args); + } + // Validating apple platforms deployment targets. validateDeploymentTarget(*this, diags, args); validateTargetVariant(*this, diags, args, defaultTarget); diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index 0554ec52589c9..1732f3bbd17ee 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -96,15 +96,16 @@ void Driver::parseDriverKind(ArrayRef Args) { } Optional Kind = - llvm::StringSwitch>(DriverName) - .Case("swift", DriverKind::Interactive) - .Case("swiftc", DriverKind::Batch) - .Case("swift-autolink-extract", DriverKind::AutolinkExtract) - .Case("swift-indent", DriverKind::SwiftIndent) - .Case("swift-symbolgraph-extract", DriverKind::SymbolGraph) - .Case("swift-api-extract", DriverKind::APIExtract) - .Default(None); - + llvm::StringSwitch>(DriverName) + .Case("swift", DriverKind::Interactive) + .Case("swiftc", DriverKind::Batch) + .Case("swift-autolink-extract", DriverKind::AutolinkExtract) + .Case("swift-indent", DriverKind::SwiftIndent) + .Case("swift-symbolgraph-extract", DriverKind::SymbolGraph) + .Case("swift-api-extract", DriverKind::APIExtract) + .Case("swift-api-digester", DriverKind::APIDigester) + .Default(None); + if (Kind.hasValue()) driverKind = Kind.getValue(); else if (!OptName.empty()) @@ -3507,6 +3508,7 @@ void Driver::printHelp(bool ShowHidden) const { case DriverKind::SwiftIndent: case DriverKind::SymbolGraph: case DriverKind::APIExtract: + case DriverKind::APIDigester: ExcludedFlagsBitmask |= options::NoBatchOption; break; } diff --git a/lib/Driver/FrontendUtil.cpp b/lib/Driver/FrontendUtil.cpp index 2f2c8c8c3171d..9be9def90fc2f 100644 --- a/lib/Driver/FrontendUtil.cpp +++ b/lib/Driver/FrontendUtil.cpp @@ -75,6 +75,8 @@ bool swift::driver::getSingleFrontendInvocationFromDriverArguments( // CompilerInvocation may wish to remap inputs to source buffers. TheDriver.setCheckInputFilesExist(false); + TheDriver.setIsDummyDriverForFrontendInvocation(true); + std::unique_ptr ArgList = TheDriver.parseArgStrings(ArrayRef(Args).slice(1)); if (Diags.hadAnyError()) diff --git a/lib/Driver/UnixToolChains.cpp b/lib/Driver/UnixToolChains.cpp index edfe2c46c2325..e6f71c00ccbd1 100644 --- a/lib/Driver/UnixToolChains.cpp +++ b/lib/Driver/UnixToolChains.cpp @@ -263,6 +263,14 @@ toolchains::GenericUnix::constructInvocation(const DynamicLinkJobAction &job, Arguments.push_back(context.Args.MakeArgString(context.OI.SDKPath)); } + // If we are linking statically, we need to add all + // dependencies to a library search group to resolve + // potential circular dependencies + if (staticExecutable || staticStdlib) { + Arguments.push_back("-Xlinker"); + Arguments.push_back("--start-group"); + } + // Add any autolinking scripts to the arguments for (const Job *Cmd : context.Inputs) { auto &OutputInfo = Cmd->getOutput(); @@ -271,6 +279,11 @@ toolchains::GenericUnix::constructInvocation(const DynamicLinkJobAction &job, Twine("@") + OutputInfo.getPrimaryOutputFilename())); } + if (staticExecutable || staticStdlib) { + Arguments.push_back("-Xlinker"); + Arguments.push_back("--end-group"); + } + // Add the runtime library link paths. for (auto path : RuntimeLibPaths) { Arguments.push_back("-L"); diff --git a/lib/IRGen/CMakeLists.txt b/lib/IRGen/CMakeLists.txt index 777096b39e6e0..22381ce49efcf 100644 --- a/lib/IRGen/CMakeLists.txt +++ b/lib/IRGen/CMakeLists.txt @@ -52,6 +52,7 @@ add_swift_host_library(swiftIRGen STATIC MetadataLayout.cpp MetadataRequest.cpp Outlining.cpp + PartialApplyLowering.cpp StructLayout.cpp SwiftTargetInfo.cpp TypeLayout.cpp diff --git a/lib/IRGen/Callee.h b/lib/IRGen/Callee.h index 512c5c01785d3..3a3e967524eab 100644 --- a/lib/IRGen/Callee.h +++ b/lib/IRGen/Callee.h @@ -176,10 +176,15 @@ namespace irgen { switch (getSpecialKind()) { case SpecialKind::TaskFutureWait: case SpecialKind::TaskFutureWaitThrowing: + // FIXME: I have disabled this optimization, if we bring it back we + // need to debug why it currently does not work (call emission + // computes an undef return pointer) and change the runtime entries to + // remove the extra type parameter. + // // We suppress generics from these as a code-size optimization // because the runtime can recover the success type from the // future. - return true; + return false; case SpecialKind::TaskGroupWaitNext: return false; } diff --git a/lib/IRGen/EntryPointArgumentEmission.h b/lib/IRGen/EntryPointArgumentEmission.h index 5bec25a7bdd5f..0896d6ce591b4 100644 --- a/lib/IRGen/EntryPointArgumentEmission.h +++ b/lib/IRGen/EntryPointArgumentEmission.h @@ -43,6 +43,7 @@ class NativeCCEntryPointArgumentEmission : public virtual EntryPointArgumentEmission { public: + virtual void mapAsyncParameters() = 0; virtual llvm::Value *getCallerErrorResultArgument() = 0; virtual llvm::Value *getContext() = 0; virtual Explosion getArgumentExplosion(unsigned index, unsigned size) = 0; diff --git a/lib/IRGen/GenBuiltin.cpp b/lib/IRGen/GenBuiltin.cpp index 4c1c27e14a40f..79263c196745d 100644 --- a/lib/IRGen/GenBuiltin.cpp +++ b/lib/IRGen/GenBuiltin.cpp @@ -230,7 +230,6 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin, Builtin.ID == BuiltinValueKind::CreateAsyncTaskGroupFuture) { auto flags = args.claimNext(); - auto parentTask = args.claimNext(); auto taskGroup = (Builtin.ID == BuiltinValueKind::CreateAsyncTaskGroupFuture) ? args.claimNext() @@ -244,7 +243,7 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin, auto taskContext = args.claimNext(); auto newTaskAndContext = emitTaskCreate( - IGF, flags, parentTask, taskGroup, futureResultType, taskFunction, taskContext, + IGF, flags, taskGroup, futureResultType, taskFunction, taskContext, substitutions); // Cast back to NativeObject/RawPointer. diff --git a/lib/IRGen/GenCall.cpp b/lib/IRGen/GenCall.cpp index 7a59f91ed9160..eb34408e81ac2 100644 --- a/lib/IRGen/GenCall.cpp +++ b/lib/IRGen/GenCall.cpp @@ -87,9 +87,10 @@ AsyncContextLayout irgen::getAsyncContextLayout(IRGenModule &IGM, CanSILFunctionType substitutedType = originalType->substGenericArgs( IGM.getSILModule(), forwardingSubstitutionMap, IGM.getMaximalTypeExpansionContext()); - auto layout = getAsyncContextLayout(IGM, originalType, substitutedType, - forwardingSubstitutionMap, - /*suppressGenerics*/false); + auto layout = getAsyncContextLayout( + IGM, originalType, substitutedType, forwardingSubstitutionMap, + /*suppressGenerics*/ false, + FunctionPointer::Kind(FunctionPointer::BasicKind::AsyncFunctionPointer)); return layout; } @@ -97,16 +98,14 @@ AsyncContextLayout irgen::getAsyncContextLayout(IRGenModule &IGM, CanSILFunctionType originalType, CanSILFunctionType substitutedType, SubstitutionMap substitutionMap, - bool suppressGenerics) { + bool suppressGenerics, + FunctionPointer::Kind kind) { SmallVector typeInfos; SmallVector valTypes; SmallVector paramInfos; - bool isCoroutine = originalType->isCoroutine(); - SmallVector yieldInfos; SmallVector indirectReturnInfos; SmallVector directReturnInfos; - auto parameters = substitutedType->getParameters(); SILFunctionConventions fnConv(substitutedType, IGM.getSILModule()); auto addTaskContinuationFunction = [&]() { @@ -147,11 +146,6 @@ irgen::getAsyncContextLayout(IRGenModule &IGM, CanSILFunctionType originalType, typeInfos.push_back(&ti); } - if (isCoroutine) { - // SwiftPartialFunction * __ptrauth(...) yieldToCaller?; - addTaskContinuationFunction(); - } - // SwiftError **errorResult; auto errorCanType = IGM.Context.getExceptionType(); auto errorType = SILType::getPrimitiveObjectType(errorCanType); @@ -159,176 +153,68 @@ irgen::getAsyncContextLayout(IRGenModule &IGM, CanSILFunctionType originalType, IGM.getTypeInfoForLowered(CanInOutType::get(errorCanType)); typeInfos.push_back(&errorTypeInfo); valTypes.push_back(errorType); - - bool canHaveValidError = substitutedType->hasErrorResult(); - - // IndirectResultTypes *indirectResults...; - auto indirectResults = fnConv.getIndirectSILResults(); - for (auto indirectResult : indirectResults) { - auto ty = - fnConv.getSILType(indirectResult, IGM.getMaximalTypeExpansionContext()); - auto retLoweringTy = CanInOutType::get(ty.getASTType()); - auto &ti = IGM.getTypeInfoForLowered(retLoweringTy); - valTypes.push_back(ty); - typeInfos.push_back(&ti); - indirectReturnInfos.push_back(indirectResult); - } - - // union { - if (isCoroutine) { - // SwiftPartialFunction * __ptrauth(...) resumeFromYield? - addTaskContinuationFunction(); - // SwiftPartialFunction * __ptrauth(...) abortFromYield? - addTaskContinuationFunction(); - // SwiftActor * __ptrauth(...) calleeActorDuringYield? - addExecutor(); - // YieldTypes yieldValues... - for (auto yield : fnConv.getYields()) { - auto ty = fnConv.getSILType(yield, IGM.getMaximalTypeExpansionContext()); - auto &ti = IGM.getTypeInfoForLowered(ty.getASTType()); + // Add storage for data used by runtime entry points. + // See TaskFutureWaitAsyncContext. + if (kind.isSpecial()) { + switch (kind.getSpecialKind()) { + case FunctionPointer::SpecialKind::TaskFutureWait: + case FunctionPointer::SpecialKind::TaskFutureWaitThrowing: { + // This needs to match the layout of TaskFutureWaitAsyncContext. + // Add storage for the waiting future's result pointer (OpaqueValue *). + auto ty = SILType(); + auto &ti = IGM.getSwiftContextPtrTypeInfo(); + // SwiftError * valTypes.push_back(ty); typeInfos.push_back(&ti); - yieldInfos.push_back(yield); - } - } else { - // ResultTypes directResults...; - for (auto result : fnConv.getDirectSILResults()) { - auto ty = fnConv.getSILType(result, IGM.getMaximalTypeExpansionContext()); - auto &ti = IGM.getTypeInfoForLowered(ty.getASTType()); + // OpaqueValue *successResultPointer valTypes.push_back(ty); typeInfos.push_back(&ti); - directReturnInfos.push_back(result); - } - } - - // SelfType self?; - bool hasSelf = hasSelfContextParameter(substitutedType); - SILParameterInfo localContextParameter = - hasSelf ? parameters.back() : SILParameterInfo(); - if (hasSelf) { - parameters = parameters.drop_back(); - } - - Optional localContextInfo = llvm::None; - if (hasSelf) { - assert(originalType->getRepresentation() != - SILFunctionTypeRepresentation::Thick); - SILType ty = IGM.silConv.getSILType(localContextParameter, substitutedType, - IGM.getMaximalTypeExpansionContext()); - auto argumentLoweringType = - getArgumentLoweringType(ty.getASTType(), localContextParameter, - /*isNoEscape*/ true); - - auto &ti = IGM.getTypeInfoForLowered(argumentLoweringType); - valTypes.push_back(ty); - typeInfos.push_back(&ti); - localContextInfo = {ty, localContextParameter.getConvention()}; - } else { - auto &ti = IGM.getNativeObjectTypeInfo(); - SILType ty = SILType::getNativeObjectType(IGM.Context); - valTypes.push_back(ty); - typeInfos.push_back(&ti); - localContextInfo = {ty, substitutedType->getCalleeConvention()}; - } - - // ArgTypes formalArguments...; - for (auto parameter : parameters) { - SILType ty = IGM.silConv.getSILType(parameter, substitutedType, - IGM.getMaximalTypeExpansionContext()); - - auto argumentLoweringType = - getArgumentLoweringType(ty.getASTType(), parameter, - /*isNoEscape*/ true); - - auto &ti = IGM.getTypeInfoForLowered(argumentLoweringType); - - valTypes.push_back(ty); - typeInfos.push_back(&ti); - paramInfos.push_back({ty, parameter.getConvention()}); - } - auto bindings = suppressGenerics - ? NecessaryBindings() - : NecessaryBindings::forAsyncFunctionInvocation( - IGM, originalType, substitutionMap); - if (!bindings.empty()) { - auto bindingsSize = bindings.getBufferSize(IGM); - auto &bindingsTI = - IGM.getOpaqueStorageTypeInfo(bindingsSize, IGM.getPointerAlignment()); - valTypes.push_back(SILType()); - typeInfos.push_back(&bindingsTI); - } - - Optional trailingWitnessInfo; - if (originalType->getRepresentation() == - SILFunctionTypeRepresentation::WitnessMethod) { - assert(getTrailingWitnessSignatureLength(IGM, originalType) == 2); - - // First, the Self metadata. - { - auto ty = SILType(); - auto &ti = IGM.getTypeMetadataPtrTypeInfo(); + // void (*, *) async *asyncResumeEntryPoint; valTypes.push_back(ty); typeInfos.push_back(&ti); - } - // Then, the Self witness table. - { + } break; + case FunctionPointer::SpecialKind::TaskGroupWaitNext: { + // This needs to match the layout of TaskGroupNextAsyncContext. + // Add storage for the waiting future's result pointer (OpaqueValue *). auto ty = SILType(); - auto &ti = IGM.getWitnessTablePtrTypeInfo(); + auto &ti = IGM.getSwiftContextPtrTypeInfo(); + // SwiftError * errorResult; + valTypes.push_back(ty); + typeInfos.push_back(&ti); + // OpaqueValue *successResultPointer; + valTypes.push_back(ty); + typeInfos.push_back(&ti); + // void (*, *) async *asyncResumeEntryPoint; valTypes.push_back(ty); typeInfos.push_back(&ti); + // TaskGroup *group; + valTypes.push_back(ty); + typeInfos.push_back(&ti); + // Metata *successType; + valTypes.push_back(ty); + typeInfos.push_back(&ti); + } break; } - trailingWitnessInfo = AsyncContextLayout::TrailingWitnessInfo(); } - + bool canHaveValidError = substitutedType->hasErrorResult(); return AsyncContextLayout(IGM, LayoutStrategy::Optimal, valTypes, typeInfos, originalType, substitutedType, substitutionMap, - std::move(bindings), trailingWitnessInfo, errorType, - canHaveValidError, paramInfos, isCoroutine, - yieldInfos, indirectReturnInfos, directReturnInfos, - localContextInfo); + errorType, canHaveValidError); } AsyncContextLayout::AsyncContextLayout( IRGenModule &IGM, LayoutStrategy strategy, ArrayRef fieldTypes, ArrayRef fieldTypeInfos, CanSILFunctionType originalType, CanSILFunctionType substitutedType, SubstitutionMap substitutionMap, - NecessaryBindings &&bindings, - Optional trailingWitnessInfo, SILType errorType, - bool canHaveValidError, ArrayRef argumentInfos, - bool isCoroutine, ArrayRef yieldInfos, - ArrayRef indirectReturnInfos, - ArrayRef directReturnInfos, - Optional localContextInfo) + SILType errorType, bool canHaveValidError) : StructLayout(IGM, /*decl=*/nullptr, LayoutKind::NonHeapObject, strategy, fieldTypeInfos, /*typeToFill*/ nullptr), IGM(IGM), originalType(originalType), substitutedType(substitutedType), substitutionMap(substitutionMap), errorType(errorType), - canHaveValidError(canHaveValidError), isCoroutine(isCoroutine), - yieldInfos(yieldInfos.begin(), yieldInfos.end()), - directReturnInfos(directReturnInfos.begin(), directReturnInfos.end()), - indirectReturnInfos(indirectReturnInfos.begin(), - indirectReturnInfos.end()), - localContextInfo(localContextInfo), bindings(std::move(bindings)), - trailingWitnessInfo(trailingWitnessInfo), - argumentInfos(argumentInfos.begin(), argumentInfos.end()) { + canHaveValidError(canHaveValidError) { #ifndef NDEBUG assert(fieldTypeInfos.size() == fieldTypes.size() && "type infos don't match types"); - if (isCoroutine) { - assert(directReturnInfos.empty()); - } else { - assert(yieldInfos.empty()); - } - if (!bindings.empty()) { - assert(fieldTypeInfos.size() >= 2 && "no field for bindings"); - auto fixedBindingsField = - dyn_cast(fieldTypeInfos[getBindingsIndex()]); - assert(fixedBindingsField && "bindings field is not fixed size"); - assert(fixedBindingsField->getFixedSize() == bindings.getBufferSize(IGM) && - fixedBindingsField->getFixedAlignment() == - IGM.getPointerAlignment() && - "bindings field doesn't fit bindings"); - } assert(this->isFixedLayout()); #endif } @@ -337,28 +223,16 @@ static Alignment getAsyncContextAlignment(IRGenModule &IGM) { return IGM.getPointerAlignment(); } -void IRGenFunction::setupAsync() { - llvm::Value *t = CurFn->getArg((unsigned)AsyncFunctionArgumentIndex::Task); - asyncTaskLocation = createAlloca(t->getType(), IGM.getPointerAlignment()); - Builder.CreateStore(t, asyncTaskLocation); - - llvm::Value *e = CurFn->getArg((unsigned)AsyncFunctionArgumentIndex::Executor); - asyncExecutorLocation = createAlloca(e->getType(), IGM.getPointerAlignment()); - Builder.CreateStore(e, asyncExecutorLocation); - - llvm::Value *c = CurFn->getArg((unsigned)AsyncFunctionArgumentIndex::Context); +void IRGenFunction::setupAsync(unsigned asyncContextIndex) { + llvm::Value *c = CurFn->getArg(asyncContextIndex); asyncContextLocation = createAlloca(c->getType(), IGM.getPointerAlignment()); Builder.CreateStore(c, asyncContextLocation); } llvm::Value *IRGenFunction::getAsyncTask() { - assert(isAsync()); - return Builder.CreateLoad(asyncTaskLocation); -} - -llvm::Value *IRGenFunction::getAsyncExecutor() { - assert(isAsync()); - return Builder.CreateLoad(asyncExecutorLocation); + auto call = Builder.CreateCall(IGM.getGetCurrentTaskFn(), {}); + call->setDoesNotThrow(); + return call; } llvm::Value *IRGenFunction::getAsyncContext() { @@ -366,29 +240,16 @@ llvm::Value *IRGenFunction::getAsyncContext() { return Builder.CreateLoad(asyncContextLocation); } -llvm::CallInst *IRGenFunction::emitSuspendAsyncCall(ArrayRef args) { - auto resultTy = llvm::StructType::get( - IGM.getLLVMContext(), {IGM.Int8PtrTy, IGM.Int8PtrTy, IGM.Int8PtrTy}); - +llvm::CallInst * +IRGenFunction::emitSuspendAsyncCall(unsigned asyncContextIndex, + llvm::StructType *resultTy, + ArrayRef args) { auto *id = Builder.CreateIntrinsicCall(llvm::Intrinsic::coro_suspend_async, {resultTy}, args); - // Update the current values of task, executor and context. - - auto *rawTask = Builder.CreateExtractValue(id, - (unsigned)AsyncFunctionArgumentIndex::Task); - auto *task = Builder.CreateBitCast(rawTask, IGM.SwiftTaskPtrTy); - Builder.CreateStore(task, asyncTaskLocation); - - // Update the current values of task, executor and context. - auto *rawExecutor = Builder.CreateExtractValue(id, - (unsigned)AsyncFunctionArgumentIndex::Executor); - auto *executor = Builder.CreateBitCast(rawExecutor, IGM.SwiftExecutorPtrTy); - Builder.CreateStore(executor, asyncExecutorLocation); - - auto *calleeContext = Builder.CreateExtractValue(id, - (unsigned)AsyncFunctionArgumentIndex::Context); + llvm::Value *calleeContext = + Builder.CreateExtractValue(id, asyncContextIndex); + calleeContext = Builder.CreateBitOrPointerCast(calleeContext, IGM.Int8PtrTy); llvm::Constant *projectFn = cast(args[2])->stripPointerCasts(); - // Get the caller context from the callee context. llvm::Value *context = Builder.CreateCall(projectFn, {calleeContext}); context = Builder.CreateBitCast(context, IGM.SwiftContextPtrTy); Builder.CreateStore(context, asyncContextLocation); @@ -576,6 +437,8 @@ namespace { bool CanUseError = true; bool CanUseSelf = true; bool SuppressGenerics; + unsigned AsyncContextIdx; + unsigned AsyncResumeFunctionSwiftSelfIdx = 0; SignatureExpansion(IRGenModule &IGM, CanSILFunctionType fnType, bool suppressGenerics) @@ -588,6 +451,17 @@ namespace { /// function type. void expandCoroutineContinuationType(); + // Expand the components for the async continuation entrypoint of the + // function type (the function to be called on returning). + void expandAsyncReturnType(); + + // Expand the componends for the async suspend call of the function type. + void expandAsyncAwaitType(); + + // Expand the componends for the primary entrypoint of the async function + // type. + void expandAsyncEntryType(); + Signature getSignature(); private: @@ -632,6 +506,7 @@ namespace { void expandResult(); llvm::Type *expandDirectResult(); + void expandIndirectResults(); void expandParameters(); void expandExternalSignatureTypes(); @@ -677,6 +552,12 @@ void SignatureExpansion::expandResult() { // Expand the direct result. ResultIRType = expandDirectResult(); + // Expand the indirect results. + expandIndirectResults(); +} + +void SignatureExpansion::expandIndirectResults() { + auto fnConv = getSILFuncConventions(); // Expand the indirect results. for (auto indirectResultType : fnConv.getIndirectSILResultTypes(IGM.getMaximalTypeExpansionContext())) { @@ -842,10 +723,9 @@ void SignatureExpansion::expandCoroutineContinuationParameters() { void SignatureExpansion::addAsyncParameters() { // using TaskContinuationFunction = // SWIFT_CC(swift) - // void (AsyncTask *, ExecutorRef, AsyncContext *); - ParamIRTypes.push_back(IGM.SwiftTaskPtrTy); - ParamIRTypes.push_back(IGM.SwiftExecutorPtrTy); - Attrs = Attrs.addParamAttribute(IGM.getLLVMContext(), getCurParamIndex(), + // void (SWIFT_ASYNC_CONTEXT AsyncContext *); + AsyncContextIdx = getCurParamIndex(); + Attrs = Attrs.addParamAttribute(IGM.getLLVMContext(), AsyncContextIdx, llvm::Attribute::SwiftAsync); ParamIRTypes.push_back(IGM.SwiftContextPtrTy); } @@ -1738,9 +1618,7 @@ void SignatureExpansion::expandParameters() { && "block with non-C calling conv?!"); if (FnType->isAsync()) { - addAsyncParameters(); - // All other parameters will be passed inside the context added by the - // addAsyncParameters call. + assert(false && "Should not use expandParameters for async functions"); return; } @@ -1833,6 +1711,10 @@ void SignatureExpansion::expandParameters() { void SignatureExpansion::expandFunctionType() { switch (FnType->getLanguage()) { case SILFunctionLanguage::Swift: { + if (FnType->isAsync()) { + expandAsyncEntryType(); + return; + } expandResult(); expandParameters(); return; @@ -1849,6 +1731,171 @@ void SignatureExpansion::expandCoroutineContinuationType() { expandCoroutineContinuationParameters(); } +void SignatureExpansion::expandAsyncReturnType() { + // Build up the signature of the return continuation function. + // void (AsyncTask *, ExecutorRef, AsyncContext *, DirectResult0, ..., + // DirectResultN, Error*); + ResultIRType = IGM.VoidTy; + addAsyncParameters(); + SmallVector components; + + auto addErrorResult = [&]() { + // Add the error pointer at the end. + if (FnType->hasErrorResult()) { + llvm::Type *errorType = + IGM.getStorageType(getSILFuncConventions().getSILType( + FnType->getErrorResult(), IGM.getMaximalTypeExpansionContext())); + claimSelf(); + auto selfIdx = ParamIRTypes.size(); + IGM.addSwiftSelfAttributes(Attrs, selfIdx); + AsyncResumeFunctionSwiftSelfIdx = selfIdx; + ParamIRTypes.push_back(errorType); + } + }; + + auto resultType = getSILFuncConventions().getSILResultType( + IGM.getMaximalTypeExpansionContext()); + auto &ti = IGM.getTypeInfo(resultType); + auto &native = ti.nativeReturnValueSchema(IGM); + if (native.requiresIndirect() || native.empty()) { + addErrorResult(); + return; + } + + // Add the result type components as trailing parameters. + native.enumerateComponents( + [&](clang::CharUnits offset, clang::CharUnits end, llvm::Type *type) { + ParamIRTypes.push_back(type); + }); + + addErrorResult(); +} + +void SignatureExpansion::expandAsyncEntryType() { + ResultIRType = IGM.VoidTy; + + // FIXME: Claim the SRet for now. The way we have set up the function type to + // start with the three async specific arguments does not allow for use of + // sret. + CanUseSRet = false; + + // Add the indirect 'direct' result type. + auto resultType = getSILFuncConventions().getSILResultType( + IGM.getMaximalTypeExpansionContext()); + auto &ti = IGM.getTypeInfo(resultType); + auto &native = ti.nativeReturnValueSchema(IGM); + if (native.requiresIndirect()) + addIndirectResult(); + + // Add the indirect result types. + expandIndirectResults(); + + // Add the async context parameter. + addAsyncParameters(); + + // Add the parameters. + auto params = FnType->getParameters(); + auto hasSelfContext = false; + if (hasSelfContextParameter(FnType)) { + hasSelfContext = true; + params = params.drop_back(); + } + + for (auto param : params) { + expand(param); + } + + // Next, the generic signature. + if (hasPolymorphicParameters(FnType) && !SuppressGenerics) + expandPolymorphicSignature(IGM, FnType, ParamIRTypes); + + // Context is next. + if (hasSelfContext) { + auto curLength = ParamIRTypes.size(); + (void)curLength; + expand(FnType->getSelfParameter()); + assert(ParamIRTypes.size() == curLength + 1 && + "adding 'self' added unexpected number of parameters"); + if (claimSelf()) + IGM.addSwiftSelfAttributes(Attrs, curLength); + } else { + auto needsContext = [=]() -> bool { + switch (FnType->getRepresentation()) { + case SILFunctionType::Representation::Block: + llvm_unreachable("adding block parameter in Swift CC expansion?"); + + // Always leave space for a context argument if we have an error result. + case SILFunctionType::Representation::CFunctionPointer: + case SILFunctionType::Representation::Method: + case SILFunctionType::Representation::WitnessMethod: + case SILFunctionType::Representation::ObjCMethod: + case SILFunctionType::Representation::Thin: + case SILFunctionType::Representation::Closure: + return false; + + case SILFunctionType::Representation::Thick: + return true; + } + llvm_unreachable("bad representation kind"); + }; + if (needsContext()) { + if (claimSelf()) + IGM.addSwiftSelfAttributes(Attrs, ParamIRTypes.size()); + ParamIRTypes.push_back(IGM.RefCountedPtrTy); + } + } + + // For now we continue to store the error result in the context to be able to + // reuse non throwing functions. + + // Witness methods have some extra parameter types. + if (FnType->getRepresentation() == + SILFunctionTypeRepresentation::WitnessMethod) { + expandTrailingWitnessSignature(IGM, FnType, ParamIRTypes); + } +} + +void SignatureExpansion::expandAsyncAwaitType() { + expandAsyncEntryType(); + + SmallVector components; + // Async context. + AsyncContextIdx = 0; + components.push_back(IGM.Int8PtrTy); + + auto addErrorResult = [&]() { + if (FnType->hasErrorResult()) { + llvm::Type *errorType = + IGM.getStorageType(getSILFuncConventions().getSILType( + FnType->getErrorResult(), IGM.getMaximalTypeExpansionContext())); + auto selfIdx = components.size(); + AsyncResumeFunctionSwiftSelfIdx = selfIdx; + components.push_back(errorType); + } + }; + + // Direct result type as arguments. + auto resultType = getSILFuncConventions().getSILResultType( + IGM.getMaximalTypeExpansionContext()); + auto &ti = IGM.getTypeInfo(resultType); + auto &native = ti.nativeReturnValueSchema(IGM); + if (native.requiresIndirect() || native.empty()) { + addErrorResult(); + ResultIRType = llvm::StructType::get(IGM.getLLVMContext(), components); + return; + } + + // Add the result type components as trailing parameters. + native.enumerateComponents( + [&](clang::CharUnits offset, clang::CharUnits end, llvm::Type *type) { + components.push_back(type); + }); + + addErrorResult(); + + ResultIRType = llvm::StructType::get(IGM.getLLVMContext(), components); +} + Signature SignatureExpansion::getSignature() { // Create the appropriate LLVM type. llvm::FunctionType *llvmType = @@ -1874,6 +1921,12 @@ Signature SignatureExpansion::getSignature() { result.ExtraDataKind = ExtraData::kindForMember(); result.ExtraDataStorage.emplace(result.ExtraDataKind, CoroInfo); + } else if (FnType->isAsync()) { + result.ExtraDataKind = ExtraData::kindForMember(); + AsyncInfo info; + info.AsyncContextIdx = AsyncContextIdx; + info.AsyncResumeFunctionSwiftSelfIdx = AsyncResumeFunctionSwiftSelfIdx; + result.ExtraDataStorage.emplace(result.ExtraDataKind, info); } else { result.ExtraDataKind = ExtraData::kindForMember(); } @@ -1897,6 +1950,33 @@ Signature Signature::forCoroutineContinuation(IRGenModule &IGM, return expansion.getSignature(); } +Signature Signature::forAsyncReturn(IRGenModule &IGM, + CanSILFunctionType fnType) { + assert(fnType->isAsync()); + GenericContextScope scope(IGM, fnType->getInvocationGenericSignature()); + SignatureExpansion expansion(IGM, fnType, /*suppress generics*/ false); + expansion.expandAsyncReturnType(); + return expansion.getSignature(); +} + +Signature Signature::forAsyncAwait(IRGenModule &IGM, + CanSILFunctionType fnType) { + assert(fnType->isAsync()); + GenericContextScope scope(IGM, fnType->getInvocationGenericSignature()); + SignatureExpansion expansion(IGM, fnType, /*suppress generics*/ false); + expansion.expandAsyncAwaitType(); + return expansion.getSignature(); +} + +Signature Signature::forAsyncEntry(IRGenModule &IGM, + CanSILFunctionType fnType) { + assert(fnType->isAsync()); + GenericContextScope scope(IGM, fnType->getInvocationGenericSignature()); + SignatureExpansion expansion(IGM, fnType, /*suppress generics*/ false); + expansion.expandAsyncEntryType(); + return expansion.getSignature(); +} + void irgen::extractScalarResults(IRGenFunction &IGF, llvm::Type *bodyType, llvm::Value *call, Explosion &out) { assert(!bodyType->isVoidTy() && "Unexpected void result type!"); @@ -1926,223 +2006,38 @@ std::pair irgen::getAsyncFunctionAndSize( assert(functionPointer.getKind() != FunctionPointer::Kind::Function); bool emitFunction = values.first; bool emitSize = values.second; - // TODO: This calculation should be extracted out into standalone functions - // emitted on-demand per-module to improve codesize. - switch (representation) { - case SILFunctionTypeRepresentation::Thick: { - assert(!functionPointer.useStaticContextSize()); - // If the called function is thick, the size of the called function's - // async context is not statically knowable. - // - // Specifically, if the thick function was produced by a partial_apply, - // the function which was originally partially applied determines the - // size of the needed async context. That original function isn't known - // statically. The dynamic size is available within the context as an - // i32 at the first index: <{ %swift.refcounted*, /*size*/ i32, ... }>. - // In this case, the function pointer is actually a pointer to an llvm - // function. - // - // On the other hand, if the thick function was produced by a - // thin_to_thick_function, then the context will be nullptr. In that - // case, the dynamic size of the needed async context is available within - // the struct, an AsyncFunctionPointer pointed to by the "function" pointer - // as an i32 at the second index: <{ /*fn rel addr*/ i32, /*size*/ i32 }>. - // - // We are currently emitting into some basic block. To handle these two - // cases, we need to branch based on whether the context is nullptr; each - // branch must then determine the size and function pointer in the manner - // appropriate to it. Finally, both blocks must join back together to make - // the call: - // - // +-------------------------+ - // |%cond = %ctx == nullptr | - // +----------------|br %cond, thin, thick |----------------------+ - // | +-------------------------+ | - // | | - // V | - // +-thin-------------------------------------------+ | - // |%afp = bitcast %fp to %swift.async_func_pointer*| | - // |%size_ptr = getelementptr %afp, i32 0, i32 1 | | - // |%size = load %size_ptr | | - // |%offset_ptr = getelementptr %afp, i32 0, i32 1 | | - // |%offset = load i32 %offset_ptr | | - // |%offset64 = sext %offset to i64 | | - // |%raw_fp = add %offset64, %offset_ptr | | - // |br join(%raw_fp, %size) | | - // +------------------------------------------------+ | - // | | - // | V - // | +-thick--------------------------------------------+ - // | |%layout = bitcast %ctx to <{%swift.context*, i32}>| - // | |%size_addr = getelementptr %layout, i32 0, i32 1 | - // | |%size = load %size_addr | - // | |br join(%fp, %size) | - // | +---/----------------------------------------------+ - // | / - // | / - // V V - // +-join(%fn, %size)------------------------------------------------------+ - // |%dataAddr = swift_taskAlloc(%task, %size) | - // |%async_context = bitcast %dataAddr to ASYNC_CONTEXT(static_callee_type)| - // |... // populate the fields %ctx with arguments | - // |call %fn(%async_context, %ctx) | - // +-----------------------------------------------------------------------+ - auto *thinBlock = llvm::BasicBlock::Create(IGF.IGM.getLLVMContext()); - auto *thickBlock = llvm::BasicBlock::Create(IGF.IGM.getLLVMContext()); - auto *joinBlock = llvm::BasicBlock::Create(IGF.IGM.getLLVMContext()); - - auto hasThickContext = - IGF.Builder.CreateICmpNE(thickContext, IGF.IGM.RefCountedNull); - IGF.Builder.CreateCondBr(hasThickContext, thickBlock, thinBlock); - - SmallVector, 2> fnPhiValues; - SmallVector, 2> sizePhiValues; - { // thin - IGF.Builder.emitBlock(thinBlock); - auto *ptr = functionPointer.getRawPointer(); - - // If function pointer is a direct pointer to a function, it could not be - // an async function pointer. And additive operation to function address is - // illegal on some archs like wasm32, so emit undefs instead. - if (isa(ptr)) { - if (emitFunction) { - auto *undef = llvm::UndefValue::get(IGF.IGM.Int8PtrTy); - fnPhiValues.push_back({thinBlock, undef}); - } - if (emitSize) { - auto *undef = llvm::UndefValue::get(IGF.IGM.Int32Ty); - sizePhiValues.push_back({thinBlock, undef}); - } - } else { - if (auto authInfo = functionPointer.getAuthInfo()) { - ptr = emitPointerAuthAuth(IGF, ptr, authInfo); - } - auto *afpPtr = - IGF.Builder.CreateBitCast(ptr, IGF.IGM.AsyncFunctionPointerPtrTy); - if (emitFunction) { - llvm::Value *addrPtr = IGF.Builder.CreateStructGEP(afpPtr, 0); - auto *uncastFnPtr = IGF.emitLoadOfRelativePointer( - Address(addrPtr, IGF.IGM.getPointerAlignment()), /*isFar*/ false, - /*expectedType*/ functionPointer.getFunctionType()->getPointerTo()); - auto *fnPtr = IGF.Builder.CreateBitCast(uncastFnPtr, IGF.IGM.Int8PtrTy); - if (auto authInfo = functionPointer.getAuthInfo()) { - fnPtr = emitPointerAuthSign(IGF, fnPtr, authInfo); - } - fnPhiValues.push_back({thinBlock, fnPtr}); - } - if (emitSize) { - auto *sizePtr = IGF.Builder.CreateStructGEP(afpPtr, 1); - auto *size = - IGF.Builder.CreateLoad(sizePtr, IGF.IGM.getPointerAlignment()); - sizePhiValues.push_back({thinBlock, size}); - } - } - IGF.Builder.CreateBr(joinBlock); - } - - { // thick - IGF.Builder.emitBlock(thickBlock); - if (emitFunction) { - auto *uncastFnPtr = functionPointer.getRawPointer(); - auto *fnPtr = IGF.Builder.CreateBitCast(uncastFnPtr, IGF.IGM.Int8PtrTy); - fnPhiValues.push_back({thickBlock, fnPtr}); - } - if (emitSize) { - SmallVector argTypeInfos; - SmallVector argValTypes; - auto int32ASTType = - BuiltinIntegerType::get(32, IGF.IGM.IRGen.SIL.getASTContext()) - ->getCanonicalType(); - auto int32SILType = SILType::getPrimitiveObjectType(int32ASTType); - const TypeInfo &int32TI = IGF.IGM.getTypeInfo(int32SILType); - argValTypes.push_back(int32SILType); - argTypeInfos.push_back(&int32TI); - HeapLayout layout(IGF.IGM, LayoutStrategy::Optimal, argValTypes, - argTypeInfos, - /*typeToFill*/ nullptr, NecessaryBindings()); - auto castThickContext = - layout.emitCastTo(IGF, thickContext, "context.prefix"); - auto sizeLayout = layout.getElement(0); - auto sizeAddr = sizeLayout.project(IGF, castThickContext, - /*NonFixedOffsets*/ llvm::None); - auto *sizeValue = IGF.Builder.CreateLoad(sizeAddr); - sizePhiValues.push_back({thickBlock, sizeValue}); - } - IGF.Builder.CreateBr(joinBlock); - } - - { // join - IGF.Builder.emitBlock(joinBlock); - llvm::Value *fn = nullptr; - llvm::PHINode *fnPhi = nullptr; - llvm::PHINode *sizePhi = nullptr; - if (emitFunction) { - fnPhi = IGF.Builder.CreatePHI(IGF.IGM.Int8PtrTy, fnPhiValues.size()); - } - if (emitSize) { - sizePhi = IGF.Builder.CreatePHI(IGF.IGM.Int32Ty, sizePhiValues.size()); - } - if (emitFunction) { - assert(fnPhi); - for (auto &entry : fnPhiValues) { - fnPhi->addIncoming(entry.second, entry.first); - } - fn = IGF.Builder.CreateBitCast( - fnPhi, functionPointer.getFunctionType()->getPointerTo()); - } - llvm::Value *size = nullptr; - if (emitSize) { - assert(sizePhi); - for (auto &entry : sizePhiValues) { - sizePhi->addIncoming(entry.second, entry.first); - } - size = sizePhi; - } - return {fn, size}; + auto *ptr = functionPointer.getRawPointer(); + if (auto authInfo = functionPointer.getAuthInfo()) { + ptr = emitPointerAuthAuth(IGF, ptr, authInfo); + } + auto *afpPtr = + IGF.Builder.CreateBitCast(ptr, IGF.IGM.AsyncFunctionPointerPtrTy); + llvm::Value *fn = nullptr; + if (emitFunction) { + if (functionPointer.useStaticContextSize()) { + fn = functionPointer.getRawPointer(); + } else { + llvm::Value *addrPtr = IGF.Builder.CreateStructGEP(afpPtr, 0); + fn = IGF.emitLoadOfRelativePointer( + Address(addrPtr, IGF.IGM.getPointerAlignment()), /*isFar*/ false, + /*expectedType*/ functionPointer.getFunctionType()->getPointerTo()); } - } - case SILFunctionTypeRepresentation::Thin: - case SILFunctionTypeRepresentation::CFunctionPointer: - case SILFunctionTypeRepresentation::Method: - case SILFunctionTypeRepresentation::ObjCMethod: - case SILFunctionTypeRepresentation::WitnessMethod: - case SILFunctionTypeRepresentation::Closure: - case SILFunctionTypeRepresentation::Block: { - auto *ptr = functionPointer.getRawPointer(); if (auto authInfo = functionPointer.getAuthInfo()) { - ptr = emitPointerAuthAuth(IGF, ptr, authInfo); + fn = emitPointerAuthSign(IGF, fn, authInfo); } - auto *afpPtr = - IGF.Builder.CreateBitCast(ptr, IGF.IGM.AsyncFunctionPointerPtrTy); - llvm::Value *fn = nullptr; - if (emitFunction) { - if (functionPointer.useStaticContextSize()) { - fn = functionPointer.getRawPointer(); - } else { - llvm::Value *addrPtr = IGF.Builder.CreateStructGEP(afpPtr, 0); - fn = IGF.emitLoadOfRelativePointer( - Address(addrPtr, IGF.IGM.getPointerAlignment()), /*isFar*/ false, - /*expectedType*/ functionPointer.getFunctionType()->getPointerTo()); - } - if (auto authInfo = functionPointer.getAuthInfo()) { - fn = emitPointerAuthSign(IGF, fn, authInfo); - } - } - llvm::Value *size = nullptr; - if (emitSize) { - if (functionPointer.useStaticContextSize()) { - size = llvm::ConstantInt::get(IGF.IGM.Int32Ty, - initialContextSize.getValue()); - } else { - assert(!functionPointer.useStaticContextSize()); - auto *sizePtr = IGF.Builder.CreateStructGEP(afpPtr, 1); - size = IGF.Builder.CreateLoad(sizePtr, IGF.IGM.getPointerAlignment()); - } - } - return {fn, size}; } + llvm::Value *size = nullptr; + if (emitSize) { + if (functionPointer.useStaticContextSize()) { + size = llvm::ConstantInt::get(IGF.IGM.Int32Ty, + initialContextSize.getValue()); + } else { + assert(!functionPointer.useStaticContextSize()); + auto *sizePtr = IGF.Builder.CreateStructGEP(afpPtr, 1); + size = IGF.Builder.CreateLoad(sizePtr, IGF.IGM.getPointerAlignment()); + } } - llvm_unreachable("unhandled case"); + return {fn, size}; } static void externalizeArguments(IRGenFunction &IGF, const Callee &callee, @@ -2378,7 +2273,8 @@ class AsyncCallEmission final : public CallEmission { IGF.IGM, getCallee().getOrigFunctionType(), getCallee().getSubstFunctionType(), getCallee().getSubstitutions(), - getCallee().suppressGenerics())); + getCallee().suppressGenerics(), + getCallee().getFunctionPointer().getKind())); } return *asyncContextLayout; } @@ -2405,12 +2301,18 @@ class AsyncCallEmission final : public CallEmission { assert(!contextBuffer.isValid()); assert(!context.isValid()); auto layout = getAsyncContextLayout(); - // Allocate space for the async arguments. + // Allocate space for the async context. + + auto initialContextSize = Size(0); + // Only c++ runtime functions should use the initial context size. + if (CurCallee.getFunctionPointer().getKind().isSpecial()) { + initialContextSize = layout.getSize(); + } llvm::Value *dynamicContextSize32; std::tie(calleeFunction, dynamicContextSize32) = getAsyncFunctionAndSize( IGF, CurCallee.getOrigFunctionType()->getRepresentation(), CurCallee.getFunctionPointer(), thickContext, - std::make_pair(true, true), layout.getSize()); + std::make_pair(true, true), initialContextSize); auto *dynamicContextSize = IGF.Builder.CreateZExt(dynamicContextSize32, IGF.IGM.SizeTy); contextBuffer = emitAllocAsyncContext(IGF, dynamicContextSize); @@ -2430,29 +2332,120 @@ class AsyncCallEmission final : public CallEmission { super::end(); } void setFromCallee() override { + thickContext = nullptr; // TODO: this should go + super::setFromCallee(); - thickContext = CurCallee.getSwiftContext(); + + auto fnType = CurCallee.getOrigFunctionType(); + + if (fnType->getRepresentation() == + SILFunctionTypeRepresentation::WitnessMethod) { + unsigned n = getTrailingWitnessSignatureLength(IGF.IGM, fnType); + while (n--) { + Args[--LastArgWritten] = nullptr; + } + } + // We store the error pointer in the async context. + + llvm::Value *contextPtr = CurCallee.getSwiftContext(); + // Add the data pointer if we have one. + if (contextPtr) { + assert(LastArgWritten > 0); + Args[--LastArgWritten] = contextPtr; + IGF.IGM.addSwiftSelfAttributes(CurCallee.getMutableAttributes(), + LastArgWritten); + } } + FunctionPointer getCalleeFunctionPointer() override { return FunctionPointer( FunctionPointer::Kind::Function, calleeFunction, CurCallee.getFunctionPointer().getAuthInfo(), - IGF.IGM.getSignature(getCallee().getSubstFunctionType())); + Signature::forAsyncAwait(IGF.IGM, getCallee().getOrigFunctionType())); } + SILType getParameterType(unsigned index) override { - return getAsyncContextLayout().getParameterType(index); + SILFunctionConventions origConv(getCallee().getOrigFunctionType(), + IGF.getSILModule()); + return origConv.getSILArgumentType( + index, IGF.IGM.getMaximalTypeExpansionContext()); } - void setArgs(Explosion &llArgs, bool isOutlined, + void setArgs(Explosion &original, bool isOutlined, WitnessMetadata *witnessMetadata) override { Explosion asyncExplosion; - asyncExplosion.add(IGF.getAsyncTask()); - asyncExplosion.add(IGF.getAsyncExecutor()); + // Convert arguments to a representation appropriate to the calling + // convention. + + auto origCalleeType = CurCallee.getOrigFunctionType(); + SILFunctionConventions fnConv(origCalleeType, IGF.getSILModule()); + + // Pass along the indirect result pointers. + original.transferInto(asyncExplosion, fnConv.getNumIndirectSILResults()); + + // Pass the async context. asyncExplosion.add(contextBuffer.getAddress()); + + // Pass along the coroutine buffer. + switch (origCalleeType->getCoroutineKind()) { + case SILCoroutineKind::YieldMany: + case SILCoroutineKind::YieldOnce: + assert(false && "Should not reach this"); + break; + + case SILCoroutineKind::None: + break; + } + + // Translate the formal arguments and handle any special arguments. + switch (getCallee().getRepresentation()) { + case SILFunctionTypeRepresentation::ObjCMethod: + assert(false && "Should not reach this"); + break; + + case SILFunctionTypeRepresentation::Block: + assert(false && "Should not reach this"); + break; + + case SILFunctionTypeRepresentation::CFunctionPointer: + assert(false && "Should not reach this"); + break; + + case SILFunctionTypeRepresentation::WitnessMethod: + assert(witnessMetadata); + assert(witnessMetadata->SelfMetadata->getType() == + IGF.IGM.TypeMetadataPtrTy); + assert(witnessMetadata->SelfWitnessTable->getType() == + IGF.IGM.WitnessTablePtrTy); + Args.rbegin()[1] = witnessMetadata->SelfMetadata; + Args.rbegin()[0] = witnessMetadata->SelfWitnessTable; + LLVM_FALLTHROUGH; + + case SILFunctionTypeRepresentation::Closure: + case SILFunctionTypeRepresentation::Method: + case SILFunctionTypeRepresentation::Thin: + case SILFunctionTypeRepresentation::Thick: { + // Check for value arguments that need to be passed indirectly. + // But don't expect to see 'self' if it's been moved to the context + // position. + auto params = origCalleeType->getParameters(); + if (hasSelfContextParameter(origCalleeType)) { + params = params.drop_back(); + } + for (auto param : params) { + addNativeArgument(IGF, original, origCalleeType, param, asyncExplosion, + isOutlined); + } + + // Anything else, just pass along. This will include things like + // generic arguments. + asyncExplosion.add(original.claimAll()); + + break; + } + } super::setArgs(asyncExplosion, false, witnessMetadata); - SILFunctionConventions fnConv(getCallee().getSubstFunctionType(), - IGF.getSILModule()); - auto layout = getAsyncContextLayout(); + auto layout = getAsyncContextLayout(); // Set caller info into the context. { // caller context Explosion explosion; @@ -2487,75 +2480,110 @@ class AsyncCallEmission final : public CallEmission { explosion.add(fnVal); saveValue(fieldLayout, explosion, isOutlined); } - { // caller executor - Explosion explosion; - explosion.add(IGF.getAsyncExecutor()); - auto fieldLayout = layout.getResumeParentExecutorLayout(); - saveValue(fieldLayout, explosion, isOutlined); - } - // Move all the arguments into the context. - for (unsigned index = 0, count = layout.getIndirectReturnCount(); - index < count; ++index) { - auto fieldLayout = layout.getIndirectReturnLayout(index); - saveValue(fieldLayout, llArgs, isOutlined); - } - for (unsigned index = 0, count = layout.getArgumentCount(); index < count; - ++index) { - auto fieldLayout = layout.getArgumentLayout(index); - saveValue(fieldLayout, llArgs, isOutlined); - } - if (layout.hasBindings()) { - auto bindingLayout = layout.getBindingsLayout(); - auto bindingsAddr = bindingLayout.project(IGF, context, /*offsets*/ None); - layout.getBindings().save(IGF, bindingsAddr, llArgs); - } - auto isThick = - getCallee().getRepresentation() == SILFunctionTypeRepresentation::Thick; - if (selfValue || isThick) { - Explosion localExplosion; - if (selfValue) { - assert(!isThick); - localExplosion.add(selfValue); - } else { - localExplosion.add(getCallee().getSwiftContext()); - } - auto fieldLayout = layout.getLocalContextLayout(); - saveValue(fieldLayout, localExplosion, isOutlined); - } - if (auto selfMetadata = witnessMetadata->SelfMetadata) { - Explosion selfMetadataExplosion; - selfMetadataExplosion.add(selfMetadata); - auto fieldLayout = layout.getSelfMetadataLayout(); - saveValue(fieldLayout, selfMetadataExplosion, isOutlined); - } - if (auto selfWitnessTable = witnessMetadata->SelfWitnessTable) { - Explosion selfWitnessTableExplosion; - selfWitnessTableExplosion.add(selfWitnessTable); - auto fieldLayout = layout.getSelfWitnessTableLayout(); - saveValue(fieldLayout, selfWitnessTableExplosion, isOutlined); - } } void emitCallToUnmappedExplosion(llvm::CallInst *call, Explosion &out) override { - auto layout = getAsyncContextLayout(); - for (unsigned index = 0, count = layout.getDirectReturnCount(); - index < count; ++index) { - auto fieldLayout = layout.getDirectReturnLayout(index); - loadValue(fieldLayout, out); + // Bail out on a void result type. + llvm::Value *result = call; + auto *suspendResultTy = cast(result->getType()); + auto numAsyncContextParams = + getCalleeFunctionPointer().getSignature().getAsyncContextIndex() + 1; + if (suspendResultTy->getNumElements() == numAsyncContextParams) + return; + + auto &IGM = IGF.IGM; + auto &Builder = IGF.Builder; + + auto resultTys = + makeArrayRef(suspendResultTy->element_begin() + numAsyncContextParams, + suspendResultTy->element_end()); + + auto substCalleeType = getCallee().getSubstFunctionType(); + SILFunctionConventions substConv(substCalleeType, IGF.getSILModule()); + auto hasError = substCalleeType->hasErrorResult(); + SILType errorType; + if (hasError) + errorType = + substConv.getSILErrorType(IGM.getMaximalTypeExpansionContext()); + + if (resultTys.size() == 1) { + result = Builder.CreateExtractValue(result, numAsyncContextParams); + if (hasError) { + Address errorAddr = IGF.getCalleeErrorResultSlot(errorType); + Builder.CreateStore(result, errorAddr); + return; + } + } else if (resultTys.size() == 2 && hasError) { + auto tmp = result; + result = Builder.CreateExtractValue(result, numAsyncContextParams); + auto errorResult = Builder.CreateExtractValue(tmp, numAsyncContextParams + 1); + Address errorAddr = IGF.getCalleeErrorResultSlot(errorType); + Builder.CreateStore(errorResult, errorAddr); + } else { + auto directResultTys = hasError ? resultTys.drop_back() : resultTys; + auto resultTy = llvm::StructType::get(IGM.getLLVMContext(), directResultTys); + llvm::Value *resultAgg = llvm::UndefValue::get(resultTy); + for (unsigned i = 0, e = directResultTys.size(); i != e; ++i) { + llvm::Value *elt = + Builder.CreateExtractValue(result, numAsyncContextParams + i); + resultAgg = Builder.CreateInsertValue(resultAgg, elt, i); + } + if (hasError) { + auto errorResult = Builder.CreateExtractValue( + result, numAsyncContextParams + directResultTys.size()); + Address errorAddr = IGF.getCalleeErrorResultSlot(errorType); + Builder.CreateStore(errorResult, errorAddr); + } + result = resultAgg; + } + + SILFunctionConventions fnConv(getCallee().getOrigFunctionType(), + IGF.getSILModule()); + + // Get the natural IR type in the body of the function that makes + // the call. This may be different than the IR type returned by the + // call itself due to ABI type coercion. + auto resultType = + fnConv.getSILResultType(IGF.IGM.getMaximalTypeExpansionContext()); + auto &nativeSchema = + IGF.IGM.getTypeInfo(resultType).nativeReturnValueSchema(IGF.IGM); + + // For ABI reasons the result type of the call might not actually match the + // expected result type. + // + // This can happen when calling C functions, or class method dispatch thunks + // for methods that have covariant ABI-compatible overrides. + auto expectedNativeResultType = nativeSchema.getExpandedType(IGF.IGM); + // If the expected result type is void, bail. + if (expectedNativeResultType->isVoidTy()) + return; + if (result->getType() != expectedNativeResultType) { + result = + IGF.coerceValue(result, expectedNativeResultType, IGF.IGM.DataLayout); } + + // Gather the values. + Explosion nativeExplosion; + extractScalarResults(IGF, result->getType(), result, nativeExplosion); + + out = nativeSchema.mapFromNative(IGF.IGM, IGF, nativeExplosion, resultType); } Address getCalleeErrorSlot(SILType errorType, bool isCalleeAsync) override { - if (isCalleeAsync) { - auto layout = getAsyncContextLayout(); - auto errorLayout = layout.getErrorLayout(); - auto pointerToAddress = - errorLayout.project(IGF, context, /*offsets*/ llvm::None); - auto load = IGF.Builder.CreateLoad(pointerToAddress); - auto address = Address(load, IGF.IGM.getPointerAlignment()); - return address; - } else { - return IGF.getCalleeErrorResultSlot(errorType); - } - }; + return IGF.getCalleeErrorResultSlot(errorType); + } + + FunctionPointer getFunctionPointerForDispatchCall(const FunctionPointer &fn) { + auto &IGM = IGF.IGM; + // Strip off the return type. The original function pointer signature + // captured both the entry point type and the resume function type. + auto *fnTy = llvm::FunctionType::get( + IGM.VoidTy, fn.getSignature().getType()->params(), false /*vaargs*/); + auto signature = + Signature(fnTy, fn.getSignature().getAttributes(), IGM.SwiftAsyncCC); + auto fnPtr = + FunctionPointer(FunctionPointer::Kind::Function, fn.getRawPointer(), + fn.getAuthInfo(), signature); + return fnPtr; + } llvm::CallInst *createCall(const FunctionPointer &fn, ArrayRef args) override { @@ -2563,12 +2591,21 @@ class AsyncCallEmission final : public CallEmission { auto &Builder = IGF.Builder; // Setup the suspend point. SmallVector arguments; - arguments.push_back(IGM.getInt32(2)); // Index of swiftasync context. + auto signature = fn.getSignature(); + auto asyncContextIndex = + signature.getAsyncContextIndex(); + auto paramAttributeFlags = + asyncContextIndex | + (signature.getAsyncResumeFunctionSwiftSelfIndex() << 8); + // Index of swiftasync context | ((index of swiftself) << 8). + arguments.push_back( + IGM.getInt32(paramAttributeFlags)); arguments.push_back(currentResumeFn); auto resumeProjFn = IGF.getOrCreateResumePrjFn(); arguments.push_back( Builder.CreateBitOrPointerCast(resumeProjFn, IGM.Int8PtrTy)); - auto dispatchFn = IGF.createAsyncDispatchFn(fn, args); + auto dispatchFn = + IGF.createAsyncDispatchFn(getFunctionPointerForDispatchCall(fn), args); arguments.push_back( Builder.CreateBitOrPointerCast(dispatchFn, IGM.Int8PtrTy)); arguments.push_back( @@ -2578,7 +2615,9 @@ class AsyncCallEmission final : public CallEmission { } for (auto arg: args) arguments.push_back(arg); - return IGF.emitSuspendAsyncCall(arguments); + auto resultTy = + cast(signature.getType()->getReturnType()); + return IGF.emitSuspendAsyncCall(asyncContextIndex, resultTy, arguments); } }; @@ -3693,7 +3732,8 @@ emitRetconCoroutineEntry(IRGenFunction &IGF, CanSILFunctionType fnType, void irgen::emitAsyncFunctionEntry(IRGenFunction &IGF, const AsyncContextLayout &layout, - LinkEntity asyncFunction) { + LinkEntity asyncFunction, + unsigned asyncContextIndex) { auto &IGM = IGF.IGM; auto size = layout.getSize(); auto asyncFuncPointer = IGF.Builder.CreateBitOrPointerCast( @@ -3702,7 +3742,8 @@ void irgen::emitAsyncFunctionEntry(IRGenFunction &IGF, llvm::Intrinsic::coro_id_async, {llvm::ConstantInt::get(IGM.Int32Ty, size.getValue()), llvm::ConstantInt::get(IGM.Int32Ty, 16), - llvm::ConstantInt::get(IGM.Int32Ty, 2), asyncFuncPointer}); + llvm::ConstantInt::get(IGM.Int32Ty, asyncContextIndex), + asyncFuncPointer}); // Call 'llvm.coro.begin', just for consistency with the normal pattern. // This serves as a handle that we can pass around to other intrinsics. auto hdl = IGF.Builder.CreateIntrinsicCall( @@ -3775,25 +3816,22 @@ void irgen::emitTaskCancel(IRGenFunction &IGF, llvm::Value *task) { llvm::Value *irgen::emitTaskCreate( IRGenFunction &IGF, llvm::Value *flags, - llvm::Value *parentTask, llvm::Value *taskGroup, + llvm::Value *taskGroup, llvm::Value *futureResultType, llvm::Value *taskFunction, llvm::Value *localContextInfo, SubstitutionMap subs) { - parentTask = IGF.Builder.CreateBitOrPointerCast( - parentTask, IGF.IGM.SwiftTaskPtrTy); - llvm::CallInst *result; if (taskGroup && futureResultType) { taskGroup = IGF.Builder.CreateBitOrPointerCast( taskGroup, IGF.IGM.SwiftTaskGroupPtrTy); result = IGF.Builder.CreateCall( IGF.IGM.getTaskCreateGroupFutureFn(), - {flags, parentTask, taskGroup, futureResultType, + {flags, taskGroup, futureResultType, taskFunction, localContextInfo}); } else if (futureResultType) { result = IGF.Builder.CreateCall( IGF.IGM.getTaskCreateFutureFn(), - {flags, parentTask, futureResultType, taskFunction, localContextInfo}); + {flags, futureResultType, taskFunction, localContextInfo}); } else { llvm_unreachable("no future?!"); } @@ -4580,9 +4618,12 @@ void IRGenFunction::emitScalarReturn(SILType returnResultType, /// for the type. Signature irgen::emitCastOfFunctionPointer(IRGenFunction &IGF, llvm::Value *&fnPtr, - CanSILFunctionType fnType) { + CanSILFunctionType fnType, + bool forAsyncReturn) { // Figure out the function type. - auto sig = IGF.IGM.getSignature(fnType); + // FIXME: cache async signature. + auto sig = forAsyncReturn ? Signature::forAsyncReturn(IGF.IGM, fnType) + : IGF.IGM.getSignature(fnType); // Emit the cast. fnPtr = IGF.Builder.CreateBitCast(fnPtr, sig.getType()->getPointerTo()); @@ -4722,8 +4763,10 @@ FunctionPointer FunctionPointer::getAsFunction(IRGenFunction &IGF) const { return FunctionPointer(Kind::Function, getPointer(IGF), AuthInfo, Sig); } -void irgen::emitAsyncReturn(IRGenFunction &IGF, AsyncContextLayout &asyncLayout, - CanSILFunctionType fnType) { +void irgen::emitAsyncReturn( + IRGenFunction &IGF, AsyncContextLayout &asyncLayout, + CanSILFunctionType fnType, + Optional> nativeResultArgs) { auto contextAddr = asyncLayout.emitCastTo(IGF, IGF.getAsyncContext()); auto returnToCallerLayout = asyncLayout.getResumeParentLayout(); auto returnToCallerAddr = @@ -4741,15 +4784,17 @@ void irgen::emitAsyncReturn(IRGenFunction &IGF, AsyncContextLayout &asyncLayout, fnVal = emitPointerAuthAuth(IGF, fnVal, authInfo); } - auto sig = emitCastOfFunctionPointer(IGF, fnVal, fnType); + auto sig = emitCastOfFunctionPointer(IGF, fnVal, fnType, true); FunctionPointer fnPtr(FunctionPointer::Kind::Function, fnVal, PointerAuthInfo(), sig); SmallVector Args; - // Get the current task, executor, and async context. - Args.push_back(IGF.getAsyncTask()); - Args.push_back(IGF.getAsyncExecutor()); + // Get the current async context. Args.push_back(IGF.getAsyncContext()); + if (nativeResultArgs) { + for (auto nativeResultArg : *nativeResultArgs) + Args.push_back(nativeResultArg); + } // Setup the coro.end.async intrinsic call. auto &Builder = IGF.Builder; @@ -4771,29 +4816,56 @@ void irgen::emitAsyncReturn(IRGenFunction &IGF, AsyncContextLayout &asyncLayout, } void irgen::emitAsyncReturn(IRGenFunction &IGF, AsyncContextLayout &asyncLayout, - CanSILFunctionType fnType, Explosion &result) { - llvm::Value *context = IGF.getAsyncContext(); + SILType funcResultTypeInContext, + CanSILFunctionType fnType, Explosion &result, + Explosion &error) { + assert((fnType->hasErrorResult() && !error.empty()) || + (!fnType->hasErrorResult() && error.empty())); - Address dataAddr = asyncLayout.emitCastTo(IGF, context); - for (unsigned index = 0, count = asyncLayout.getDirectReturnCount(); - index < count; ++index) { - auto fieldLayout = asyncLayout.getDirectReturnLayout(index); - Address fieldAddr = - fieldLayout.project(IGF, dataAddr, /*offsets*/ llvm::None); - cast(fieldLayout.getType()) - .initialize(IGF, result, fieldAddr, /*isOutlined*/ false); - } + auto &IGM = IGF.IGM; - emitAsyncReturn(IGF, asyncLayout, fnType); + // Map the explosion to the native result type. + Optional> nativeResults = llvm::None; + SmallVector nativeResultsStorage; + SILFunctionConventions conv(fnType, IGF.getSILModule()); + auto &nativeSchema = + IGM.getTypeInfo(funcResultTypeInContext).nativeReturnValueSchema(IGM); + if (result.empty() && !nativeSchema.empty()) { + // When we throw, we set the return values to undef. + nativeSchema.enumerateComponents([&](clang::CharUnits begin, + clang::CharUnits end, + llvm::Type *componentTy) { + nativeResultsStorage.push_back(llvm::UndefValue::get(componentTy)); + }); + if (!error.empty()) + nativeResultsStorage.push_back(error.claimNext()); + nativeResults = nativeResultsStorage; + } else if (!result.empty()) { + assert(!nativeSchema.empty()); + assert(!nativeSchema.requiresIndirect()); + Explosion native = nativeSchema.mapIntoNative( + IGM, IGF, result, funcResultTypeInContext, false /*isOutlined*/); + while (!native.empty()) { + nativeResultsStorage.push_back(native.claimNext()); + } + if (!error.empty()) + nativeResultsStorage.push_back(error.claimNext()); + nativeResults = nativeResultsStorage; + } else if (!error.empty()) { + nativeResultsStorage.push_back(error.claimNext()); + nativeResults = nativeResultsStorage; + } + emitAsyncReturn(IGF, asyncLayout, fnType, nativeResults); } FunctionPointer IRGenFunction::getFunctionPointerForResumeIntrinsic(llvm::Value *resume) { auto *fnTy = llvm::FunctionType::get( - IGM.VoidTy, {IGM.Int8PtrTy, IGM.Int8PtrTy, IGM.Int8PtrTy}, + IGM.VoidTy, {IGM.Int8PtrTy}, false /*vaargs*/); - auto signature = - Signature(fnTy, IGM.constructInitialAttributes(), IGM.SwiftAsyncCC); + auto signature = Signature( + fnTy, IGM.constructInitialAttributes(true /*disable ptrauth-returns*/), + IGM.SwiftAsyncCC); auto fnPtr = FunctionPointer( FunctionPointer::Kind::Function, Builder.CreateBitOrPointerCast(resume, fnTy->getPointerTo()), diff --git a/lib/IRGen/GenCall.h b/lib/IRGen/GenCall.h index 49aa733926b3d..46307bc2ccc58 100644 --- a/lib/IRGen/GenCall.h +++ b/lib/IRGen/GenCall.h @@ -25,6 +25,7 @@ #include "swift/SIL/ApplySite.h" #include "llvm/IR/CallingConv.h" +#include "Callee.h" #include "GenHeap.h" #include "IRGenModule.h" @@ -71,18 +72,6 @@ namespace irgen { // SwiftActor * __ptrauth(...) callerActor; // SwiftPartialFunction * __ptrauth(...) yieldToCaller?; // SwiftError **errorResult; - // IndirectResultTypes *indirectResults...; - // union { - // struct { - // SwiftPartialFunction * __ptrauth(...) resumeFromYield?; - // SwiftPartialFunction * __ptrauth(...) abortFromYield?; - // SwiftActor * __ptrauth(...) calleeActorDuringYield?; - // YieldTypes yieldValues...; - // }; - // ResultTypes directResults...; - // }; - // SelfType self; - // ArgTypes formalArguments...; // }; struct AsyncContextLayout : StructLayout { struct ArgumentInfo { @@ -97,7 +86,6 @@ namespace irgen { ResumeParent = 1, ResumeParentExecutor = 2, Flags = 3, - YieldToParent = 4, }; enum class FixedCount : unsigned { Parent = 1, @@ -111,15 +99,7 @@ namespace irgen { SubstitutionMap substitutionMap; SILType errorType; bool canHaveValidError; - bool isCoroutine; - SmallVector yieldInfos; - SmallVector directReturnInfos; - SmallVector indirectReturnInfos; - Optional localContextInfo; - NecessaryBindings bindings; - Optional trailingWitnessInfo; - SmallVector argumentInfos; - + unsigned getParentIndex() { return (unsigned)FixedIndex::Parent; } unsigned getResumeParentIndex() { return (unsigned)FixedIndex::ResumeParent; @@ -128,83 +108,8 @@ namespace irgen { return (unsigned)FixedIndex::ResumeParentExecutor; } unsigned getFlagsIndex() { return (unsigned)FixedIndex::Flags; } - unsigned getYieldToParentIndex() { - assert(isCoroutine); - return (unsigned)FixedIndex::YieldToParent; - } unsigned getErrorIndex() { - return (isCoroutine ? getYieldToParentIndex() : getFlagsIndex()) + 1; - } - unsigned getFirstIndirectReturnIndex() { - return getErrorIndex() + getErrorCount(); - } - unsigned getIndexAfterIndirectReturns() { - return getFirstIndirectReturnIndex() + getIndirectReturnCount(); - } - unsigned getFirstDirectReturnIndex() { - assert(!isCoroutine); - return getIndexAfterIndirectReturns(); - } - unsigned getIndexAfterDirectReturns() { - assert(!isCoroutine); - return getFirstDirectReturnIndex() + getDirectReturnCount(); - } - unsigned getResumeFromYieldIndex() { - assert(isCoroutine); - return getIndexAfterIndirectReturns(); - } - unsigned getAbortFromYieldIndex() { - assert(isCoroutine); - return getResumeFromYieldIndex() + 1; - ; - } - unsigned getCalleeExecutorDuringYieldIndex() { - assert(isCoroutine); - return getAbortFromYieldIndex() + 1; - } - unsigned getFirstYieldIndex() { - assert(isCoroutine); - return getCalleeExecutorDuringYieldIndex() + 1; - } - unsigned getIndexAfterYields() { - assert(isCoroutine); - return getFirstYieldIndex() + getYieldCount(); - } - unsigned getIndexAfterUnion() { - if (isCoroutine) { - return getIndexAfterYields(); - } else { - return getIndexAfterDirectReturns(); - } - } - unsigned getLocalContextIndex() { - assert(hasLocalContext()); - return getIndexAfterUnion(); - } - unsigned getIndexAfterLocalContext() { - return getIndexAfterUnion() + (hasLocalContext() ? 1 : 0); - } - unsigned getFirstArgumentIndex() { return getIndexAfterLocalContext(); } - unsigned getIndexAfterArguments() { - return getFirstArgumentIndex() + getArgumentCount(); - } - unsigned getBindingsIndex() { - assert(hasBindings()); - return getIndexAfterArguments(); - } - unsigned getIndexAfterBindings() { - return getIndexAfterArguments() + (hasBindings() ? 1 : 0); - } - unsigned getSelfMetadataIndex() { - assert(hasTrailingWitnesses()); - return getIndexAfterBindings(); - } - unsigned getSelfWitnessTableIndex() { - assert(hasTrailingWitnesses()); - return getIndexAfterBindings() + 1; - } - unsigned getIndexAfterTrailingWitnesses() { - return getIndexAfterBindings() + (hasTrailingWitnesses() ? 2 : 0); + return getFlagsIndex() + 1; } public: @@ -221,76 +126,11 @@ namespace irgen { unsigned getErrorCount() { return (unsigned)FixedCount::Error; } SILType getErrorType() { return errorType; } - ElementLayout getIndirectReturnLayout(unsigned index) { - return getElement(getFirstIndirectReturnIndex() + index); - } - unsigned getIndirectReturnCount() { return indirectReturnInfos.size(); } - - bool hasLocalContext() { return (bool)localContextInfo; } - ElementLayout getLocalContextLayout() { - assert(hasLocalContext()); - return getElement(getLocalContextIndex()); - } - SILType getLocalContextType() { - assert(hasLocalContext()); - return localContextInfo->type; - } - - bool hasBindings() const { return !bindings.empty(); } - ElementLayout getBindingsLayout() { - assert(hasBindings()); - return getElement(getBindingsIndex()); - } - const NecessaryBindings &getBindings() const { return bindings; } - - ElementLayout getArgumentLayout(unsigned index) { - return getElement(getFirstArgumentIndex() + index); - } - SILType getArgumentType(unsigned index) { - return argumentInfos[index].type; - } - // Returns the type of a parameter of the substituted function using the - // indexing of the function parameters, *not* the indexing of - // AsyncContextLayout. - SILType getParameterType(unsigned index) { - SILFunctionConventions origConv(substitutedType, IGM.getSILModule()); - return origConv.getSILArgumentType(index, - IGM.getMaximalTypeExpansionContext()); - } - unsigned getArgumentCount() { return argumentInfos.size(); } - bool hasTrailingWitnesses() { return (bool)trailingWitnessInfo; } - ElementLayout getSelfMetadataLayout() { - assert(hasTrailingWitnesses()); - return getElement(getSelfMetadataIndex()); - } - ElementLayout getSelfWitnessTableLayout() { - return getElement(getSelfWitnessTableIndex()); - } - - unsigned getDirectReturnCount() { - assert(!isCoroutine); - return directReturnInfos.size(); - } - ElementLayout getDirectReturnLayout(unsigned index) { - assert(!isCoroutine); - return getElement(getFirstDirectReturnIndex() + index); - } - unsigned getYieldCount() { - assert(isCoroutine); - return yieldInfos.size(); - } - AsyncContextLayout( IRGenModule &IGM, LayoutStrategy strategy, ArrayRef fieldTypes, ArrayRef fieldTypeInfos, CanSILFunctionType originalType, CanSILFunctionType substitutedType, - SubstitutionMap substitutionMap, NecessaryBindings &&bindings, - Optional trailingWitnessInfo, SILType errorType, - bool canHaveValidError, ArrayRef argumentInfos, - bool isCoroutine, ArrayRef yieldInfos, - ArrayRef indirectReturnInfos, - ArrayRef directReturnInfos, - Optional localContextInfo); + SubstitutionMap substitutionMap, SILType errorType, bool canHaveValidError); }; AsyncContextLayout getAsyncContextLayout(IRGenModule &IGM, @@ -300,7 +140,8 @@ namespace irgen { CanSILFunctionType originalType, CanSILFunctionType substitutedType, SubstitutionMap substitutionMap, - bool suppressGenerics); + bool suppressGenerics, + FunctionPointer::Kind kind); /// Given an async function, get the pointer to the function to be called and /// the size of the context to be allocated. @@ -321,7 +162,8 @@ namespace irgen { bool isAsync); Signature emitCastOfFunctionPointer(IRGenFunction &IGF, llvm::Value *&fnPtr, - CanSILFunctionType fnType); + CanSILFunctionType fnType, + bool forAsyncReturn = false); /// Does the given function have a self parameter that should be given /// the special treatment for self parameters? @@ -409,7 +251,7 @@ namespace irgen { /// a future. llvm::Value *emitTaskCreate( IRGenFunction &IGF, llvm::Value *flags, - llvm::Value *parentTask, llvm::Value *taskGroup, + llvm::Value *taskGroup, llvm::Value *futureResultType, llvm::Value *taskFunction, llvm::Value *localContextInfo, SubstitutionMap subs); @@ -420,7 +262,8 @@ namespace irgen { void emitAsyncFunctionEntry(IRGenFunction &IGF, const AsyncContextLayout &layout, - LinkEntity asyncFunction); + LinkEntity asyncFunction, + unsigned asyncContextIndex); /// Yield the given values from the current continuation. /// @@ -431,16 +274,17 @@ namespace irgen { Explosion &yieldedValues); enum class AsyncFunctionArgumentIndex : unsigned { - Task = 0, - Executor = 1, - Context = 2, + Context = 0, }; - void emitAsyncReturn(IRGenFunction &IGF, AsyncContextLayout &layout, - CanSILFunctionType fnType); + void emitAsyncReturn( + IRGenFunction &IGF, AsyncContextLayout &layout, CanSILFunctionType fnType, + Optional> nativeResultArgs = llvm::None); void emitAsyncReturn(IRGenFunction &IGF, AsyncContextLayout &layout, - CanSILFunctionType fnType, Explosion &result); + SILType funcResultTypeInContext, + CanSILFunctionType fnType, Explosion &result, + Explosion &error); Address emitAutoDiffCreateLinearMapContext( IRGenFunction &IGF, llvm::Value *topLevelSubcontextSize); diff --git a/lib/IRGen/GenDecl.cpp b/lib/IRGen/GenDecl.cpp index 39b0c4b016e5f..edf503db7c0a5 100644 --- a/lib/IRGen/GenDecl.cpp +++ b/lib/IRGen/GenDecl.cpp @@ -2171,7 +2171,11 @@ llvm::Function *irgen::createFunction(IRGenModule &IGM, .to(fn, linkInfo.isForDefinition()); llvm::AttrBuilder initialAttrs; - IGM.constructInitialFnAttributes(initialAttrs, FuncOptMode); + // Workaround an llvm bug that does not handle this case correctly. + bool disablePtrAuthReturns = + signature.getCallingConv() == llvm::CallingConv::SwiftTail; + IGM.constructInitialFnAttributes(initialAttrs, disablePtrAuthReturns, + FuncOptMode); // Merge initialAttrs with attrs. auto updatedAttrs = signature.getAttributes().addAttributes(IGM.getLLVMContext(), @@ -2882,7 +2886,7 @@ llvm::Constant *swift::irgen::emitCXXConstructorThunkIfNeeded( thunk->setCallingConv(llvm::CallingConv::C); llvm::AttrBuilder attrBuilder; - IGM.constructInitialFnAttributes(attrBuilder); + IGM.constructInitialFnAttributes(attrBuilder, false /*disablePtrAuthReturns*/); attrBuilder.addAttribute(llvm::Attribute::AlwaysInline); llvm::AttributeList attr = signature.getAttributes().addAttributes( IGM.getLLVMContext(), llvm::AttributeList::FunctionIndex, attrBuilder); diff --git a/lib/IRGen/GenFunc.cpp b/lib/IRGen/GenFunc.cpp index 7f7730e47fee6..775b9171b3f53 100644 --- a/lib/IRGen/GenFunc.cpp +++ b/lib/IRGen/GenFunc.cpp @@ -80,13 +80,14 @@ #include "swift/IRGen/Linking.h" #include "clang/AST/ASTContext.h" #include "clang/CodeGen/CodeGenABITypes.h" +#include "llvm/ADT/StringSwitch.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/Function.h" +#include "llvm/IR/GlobalValue.h" #include "llvm/IR/Module.h" #include "llvm/ProfileData/InstrProf.h" #include "llvm/Support/Debug.h" -#include "llvm/ADT/StringSwitch.h" #include "BitPatternBuilder.h" #include "Callee.h" @@ -748,6 +749,10 @@ class PartialApplicationForwarderEmission { SILFunctionConventions outConv; Explosion origParams; + // Create a new explosion for potentially reabstracted parameters. + Explosion args; + Address resultValueAddr; + PartialApplicationForwarderEmission( IRGenModule &IGM, IRGenFunction &subIGF, llvm::Function *fwd, const Optional &staticFnPtr, bool calleeHasContext, @@ -768,54 +773,12 @@ class PartialApplicationForwarderEmission { PartialApply, }; virtual void begin(){}; + virtual void gatherArgumentsFromApply() = 0; - virtual unsigned getCurrentArgumentIndex() = 0; - virtual bool transformArgumentToNative(SILParameterInfo origParamInfo, - Explosion &in, Explosion &out) = 0; - virtual void addArgument(Explosion &explosion) = 0; - virtual void addArgument(llvm::Value *argValue) = 0; - virtual void addArgument(Explosion &explosion, unsigned index) = 0; - virtual void addArgument(llvm::Value *argValue, unsigned index) = 0; - virtual SILParameterInfo getParameterInfo(unsigned index) = 0; - virtual llvm::Value *getContext() = 0; - virtual llvm::Value *getDynamicFunctionPointer(PointerAuthInfo &authInfo) = 0; - virtual llvm::Value *getDynamicFunctionContext() = 0; - virtual void addDynamicFunctionContext(Explosion &explosion, - DynamicFunctionKind kind) = 0; - virtual void addDynamicFunctionPointer(Explosion &explosion, - DynamicFunctionKind kind) = 0; - virtual void addSelf(Explosion &explosion) = 0; - virtual void addWitnessSelfMetadata(llvm::Value *value) = 0; - virtual void addWitnessSelfWitnessTable(llvm::Value *value) = 0; - virtual void forwardErrorResult() = 0; - virtual bool originalParametersConsumed() = 0; - virtual void addPolymorphicArguments(Explosion polyArgs) = 0; - virtual llvm::CallInst *createCall(FunctionPointer &fnPtr) = 0; - virtual void createReturn(llvm::CallInst *call) = 0; - virtual void end(){}; - virtual ~PartialApplicationForwarderEmission() {} -}; -class SyncPartialApplicationForwarderEmission - : public PartialApplicationForwarderEmission { - using super = PartialApplicationForwarderEmission; - // Create a new explosion for potentially reabstracted parameters. - Explosion args; - Address resultValueAddr; -public: - SyncPartialApplicationForwarderEmission( - IRGenModule &IGM, IRGenFunction &subIGF, llvm::Function *fwd, - const Optional &staticFnPtr, bool calleeHasContext, - const Signature &origSig, CanSILFunctionType origType, - CanSILFunctionType substType, CanSILFunctionType outType, - SubstitutionMap subs, HeapLayout const *layout, - ArrayRef conventions) - : PartialApplicationForwarderEmission( - IGM, subIGF, fwd, staticFnPtr, calleeHasContext, origSig, origType, - substType, outType, subs, layout, conventions) {} + virtual void mapAsyncParameters() {} - void begin() override { super::begin(); } - void gatherArgumentsFromApply() override { + void gatherArgumentsFromApply(bool isAsync) { // Lower the forwarded arguments in the original function's generic context. GenericContextScope scope(IGM, origType->getInvocationGenericSignature()); @@ -829,7 +792,7 @@ class SyncPartialApplicationForwarderEmission // Forward the indirect return values. We might have to reabstract the // return value. - bool useSRet = true; + bool useSRet = !isAsync; if (nativeResultSchema.requiresIndirect()) { assert(origNativeSchema.requiresIndirect()); auto resultAddr = origParams.claimNext(); @@ -867,6 +830,9 @@ class SyncPartialApplicationForwarderEmission useSRet = false; } + if (isAsync) + mapAsyncParameters(); + // Reemit the parameters as unsubstituted. for (unsigned i = 0; i < outType->getParameters().size(); ++i) { auto origParamInfo = origType->getParameters()[i]; @@ -931,25 +897,74 @@ class SyncPartialApplicationForwarderEmission nativeApplyArg.transferInto(args, nativeApplyArg.size()); } } - unsigned getCurrentArgumentIndex() override { return args.size(); } + + unsigned getCurrentArgumentIndex() { return args.size(); } + bool transformArgumentToNative(SILParameterInfo origParamInfo, Explosion &in, - Explosion &out) override { + Explosion &out) { return addNativeArgument(subIGF, in, origType, origParamInfo, out, false); } - void addArgument(Explosion &explosion) override { + void addArgument(Explosion &explosion) { args.add(explosion.claimAll()); } - void addArgument(llvm::Value *argValue) override { args.add(argValue); } - void addArgument(Explosion &explosion, unsigned index) override { + void addArgument(llvm::Value *argValue) { args.add(argValue); } + void addArgument(Explosion &explosion, unsigned index) { addArgument(explosion); } - void addArgument(llvm::Value *argValue, unsigned index) override { + void addArgument(llvm::Value *argValue, unsigned index) { addArgument(argValue); } - SILParameterInfo getParameterInfo(unsigned index) override { + + SILParameterInfo getParameterInfo(unsigned index) { return substType->getParameters()[index]; } - llvm::Value *getContext() override { return origParams.claimNext(); } + + llvm::Value *getContext() { return origParams.claimNext(); } + + virtual llvm::Value *getDynamicFunctionPointer(PointerAuthInfo &authInfo) = 0; + virtual llvm::Value *getDynamicFunctionContext() = 0; + virtual void addDynamicFunctionContext(Explosion &explosion, + DynamicFunctionKind kind) = 0; + virtual void addDynamicFunctionPointer(Explosion &explosion, + DynamicFunctionKind kind) = 0; + + void addSelf(Explosion &explosion) { addArgument(explosion); } + void addWitnessSelfMetadata(llvm::Value *value) { + addArgument(value); + } + void addWitnessSelfWitnessTable(llvm::Value *value) { + addArgument(value); + } + virtual void forwardErrorResult() = 0; + bool originalParametersConsumed() { return origParams.empty(); } + void addPolymorphicArguments(Explosion polyArgs) { + polyArgs.transferInto(args, polyArgs.size()); + } + virtual llvm::CallInst *createCall(FunctionPointer &fnPtr) = 0; + virtual void createReturn(llvm::CallInst *call) = 0; + virtual void end(){}; + virtual ~PartialApplicationForwarderEmission() {} +}; +class SyncPartialApplicationForwarderEmission + : public PartialApplicationForwarderEmission { + using super = PartialApplicationForwarderEmission; + +public: + SyncPartialApplicationForwarderEmission( + IRGenModule &IGM, IRGenFunction &subIGF, llvm::Function *fwd, + const Optional &staticFnPtr, bool calleeHasContext, + const Signature &origSig, CanSILFunctionType origType, + CanSILFunctionType substType, CanSILFunctionType outType, + SubstitutionMap subs, HeapLayout const *layout, + ArrayRef conventions) + : PartialApplicationForwarderEmission( + IGM, subIGF, fwd, staticFnPtr, calleeHasContext, origSig, origType, + substType, outType, subs, layout, conventions) {} + + void begin() override { super::begin(); } + void gatherArgumentsFromApply() override { + super::gatherArgumentsFromApply(false); + } llvm::Value *getDynamicFunctionPointer(PointerAuthInfo &authInfo) override { return args.takeLast(); } @@ -962,21 +977,10 @@ class SyncPartialApplicationForwarderEmission DynamicFunctionKind kind) override { addArgument(explosion); } - void addSelf(Explosion &explosion) override { addArgument(explosion); } - void addWitnessSelfMetadata(llvm::Value *value) override { - addArgument(value); - } - void addWitnessSelfWitnessTable(llvm::Value *value) override { - addArgument(value); - } void forwardErrorResult() override { llvm::Value *errorResultPtr = origParams.claimNext(); args.add(errorResultPtr); } - bool originalParametersConsumed() override { return origParams.empty(); } - void addPolymorphicArguments(Explosion polyArgs) override { - polyArgs.transferInto(args, polyArgs.size()); - } llvm::CallInst *createCall(FunctionPointer &fnPtr) override { return subIGF.Builder.CreateCall(fnPtr, args.claimAll()); } @@ -1035,8 +1039,6 @@ class AsyncPartialApplicationForwarderEmission : public PartialApplicationForwarderEmission { using super = PartialApplicationForwarderEmission; AsyncContextLayout layout; - llvm::Value *task; - llvm::Value *executor; llvm::Value *contextBuffer; Size contextSize; Address context; @@ -1087,204 +1089,47 @@ class AsyncPartialApplicationForwarderEmission : PartialApplicationForwarderEmission( IGM, subIGF, fwd, staticFnPtr, calleeHasContext, origSig, origType, substType, outType, subs, layout, conventions), - layout(getAsyncContextLayout(subIGF.IGM, origType, substType, subs, - staticFnPtr - ? staticFnPtr->suppressGenerics() - : false)), - currentArgumentIndex(outType->getNumParameters()) { - task = origParams.claimNext(); - executor = origParams.claimNext(); - contextBuffer = origParams.claimNext(); - } + layout(getAsyncContextLayout( + subIGF.IGM, origType, substType, subs, + staticFnPtr ? staticFnPtr->suppressGenerics() : false, + FunctionPointer::Kind( + FunctionPointer::BasicKind::AsyncFunctionPointer))), + currentArgumentIndex(outType->getNumParameters()) {} - void begin() override { - super::begin(); - assert(task); - assert(executor); - assert(contextBuffer); + void begin() override { super::begin(); } + + void mapAsyncParameters() override { + contextBuffer = origParams.claimNext(); context = layout.emitCastTo(subIGF, contextBuffer); + args.add(contextBuffer); } - bool transformArgumentToNative(SILParameterInfo origParamInfo, Explosion &in, - Explosion &out) override { - out.add(in.claimAll()); - return false; - } - unsigned getCurrentArgumentIndex() override { return currentArgumentIndex; } void gatherArgumentsFromApply() override { - // The provided %swift.context* already contains all the values from the - // apply site. All that remains to do is bind polymorphic parameters. - for (unsigned index = 0; index < outType->getParameters().size(); ++index) { - auto fieldLayout = layout.getArgumentLayout(index); - Explosion explosion; - loadValue(fieldLayout, explosion); - bindPolymorphicParameter(subIGF, origType, substType, explosion, index); - (void)explosion.claimAll(); - // TODO: Rather than just discard this explosion, avoid loading the - // parameters if no polymorphic binding is necessary. - } - } - void addArgument(llvm::Value *argValue) override { - addArgument(argValue, currentArgumentIndex); - } - void addArgument(Explosion &explosion) override { - addArgument(explosion, currentArgumentIndex); - } - void addArgument(llvm::Value *argValue, unsigned index) override { - Explosion explosion; - explosion.add(argValue); - addArgument(explosion, index); - } - void addArgument(Explosion &explosion, unsigned index) override { - currentArgumentIndex = index + 1; - auto isLocalContext = (hasSelfContextParameter(origType) && - index == origType->getParameters().size() - 1); - if (isLocalContext) { - addSelf(explosion); - return; - } - auto fieldLayout = layout.getArgumentLayout(index); - saveValue(fieldLayout, explosion); - } - SILParameterInfo getParameterInfo(unsigned index) override { - return origType->getParameters()[index]; - } - llvm::Value *getContext() override { - return loadValue(layout.getLocalContextLayout()); + super::gatherArgumentsFromApply(true); } llvm::Value *getDynamicFunctionPointer(PointerAuthInfo &authInfo) override { - assert(dynamicFunction && dynamicFunction->pointer); - auto *context = dynamicFunction->context; - if (!context) { - return dynamicFunction->pointer; - } - auto *rawFunction = subIGF.Builder.CreateBitCast( - dynamicFunction->pointer, origSig.getType()->getPointerTo()); - auto functionPointer = - FunctionPointer(FunctionPointer::Kind::AsyncFunctionPointer, - rawFunction, authInfo, origSig); - llvm::Value *size = nullptr; - llvm::Value *function = nullptr; - std::tie(function, size) = getAsyncFunctionAndSize( - subIGF, origType->getRepresentation(), functionPointer, context, - {/*function*/ true, /*size*/ false}); - assert(size == nullptr); - return function; + llvm_unreachable( + "async partial applies never have dynamic function pointers"); } llvm::Value *getDynamicFunctionContext() override { - assert((dynamicFunction && dynamicFunction->context) || - (self && self->value)); - return dynamicFunction ? dynamicFunction->context : self->value; + return args.takeLast(); } void addDynamicFunctionContext(Explosion &explosion, DynamicFunction::Kind kind) override { - auto *value = explosion.claimNext(); - assert(explosion.empty()); - if (dynamicFunction) { - assert(dynamicFunction->kind == kind); - if (dynamicFunction->context) { - assert(dynamicFunction->context == value); - } else { - dynamicFunction->context = value; - } - return; - } - dynamicFunction = {kind, /*pointer*/ nullptr, /*context*/ value}; + addArgument(explosion); } void addDynamicFunctionPointer(Explosion &explosion, DynamicFunction::Kind kind) override { - auto *value = explosion.claimNext(); - assert(explosion.empty()); - if (dynamicFunction) { - assert(dynamicFunction->kind == kind); - if (dynamicFunction->pointer) { - assert(dynamicFunction->pointer == value); - } else { - dynamicFunction->pointer = value; - } - return; - } - dynamicFunction = {kind, /*pointer*/ value, /*context*/ nullptr}; - } - void addSelf(Explosion &explosion) override { - auto *value = explosion.claimNext(); - assert(explosion.empty()); - Self::Kind kind = [&](SILFunctionTypeRepresentation representation) { - switch (representation) { - case SILFunctionTypeRepresentation::Method: - return Self::Kind::Method; - case SILFunctionTypeRepresentation::WitnessMethod: - return Self::Kind::WitnessMethod; - default: - llvm_unreachable("representation does not have a self"); - } - }(origType->getRepresentation()); - if (self) { - assert(self->kind == kind); - if (self->value) { - assert(self->value == value); - } else { - self->value = value; - } - return; - } - self = {kind, value}; - - Explosion toSave; - toSave.add(value); - auto fieldLayout = layout.getLocalContextLayout(); - saveValue(fieldLayout, toSave); - } - void addWitnessSelfMetadata(llvm::Value *value) override { - auto fieldLayout = layout.getSelfMetadataLayout(); - Explosion explosion; - explosion.add(value); - saveValue(fieldLayout, explosion); - } - void addWitnessSelfWitnessTable(llvm::Value *value) override { - auto fieldLayout = layout.getSelfWitnessTableLayout(); - Explosion explosion; - explosion.add(value); - saveValue(fieldLayout, explosion); + assert(false); + addArgument(explosion); } + void forwardErrorResult() override { // Nothing to do here. The error result pointer is already in the // appropriate position. } - bool originalParametersConsumed() override { - // The original parameters remain in the initially allocated - // %swift.context*, so they have always already been consumed. - return true; - } - void addPolymorphicArguments(Explosion polyArgs) override { - if (polyArgs.size() == 0) { - return; - } - assert(layout.hasBindings()); - auto bindingsLayout = layout.getBindingsLayout(); - auto bindingsAddr = - bindingsLayout.project(subIGF, context, /*offsets*/ None); - layout.getBindings().save(subIGF, bindingsAddr, polyArgs); - } llvm::CallInst *createCall(FunctionPointer &fnPtr) override { - Explosion asyncExplosion; - asyncExplosion.add(subIGF.getAsyncTask()); - asyncExplosion.add(subIGF.getAsyncExecutor()); - asyncExplosion.add(contextBuffer); - if (dynamicFunction && - dynamicFunction->kind == DynamicFunction::Kind::PartialApply) { - // Just before making the call, replace the old thick context with the - // new thick context so that (1) the new thick context is never used by - // this partial apply forwarder and (2) the old thick context is never - // used by the callee partial apply forwarder. - assert(dynamicFunction->context); - auto fieldLayout = layout.getLocalContextLayout(); - Explosion explosion; - explosion.add(dynamicFunction->context); - saveValue(fieldLayout, explosion); - } - return subIGF.Builder.CreateCall(fnPtr.getAsFunction(subIGF), - asyncExplosion.claimAll()); + args.claimAll()); } // [FIXME: swiftasynccc] This call should be marked musttail. void createReturn(llvm::CallInst *call) override { @@ -1321,7 +1166,7 @@ getPartialApplicationForwarderEmission( /// If 'layout' is null, there is a single captured value of /// Swift-refcountable type that is being used directly as the /// context object. -static llvm::Function *emitPartialApplicationForwarder(IRGenModule &IGM, +static llvm::Value *emitPartialApplicationForwarder(IRGenModule &IGM, const Optional &staticFnPtr, bool calleeHasContext, const Signature &origSig, @@ -1347,17 +1192,33 @@ static llvm::Function *emitPartialApplicationForwarder(IRGenModule &IGM, llvm::Function *fwd = llvm::Function::Create(fwdTy, llvm::Function::InternalLinkage, llvm::StringRef(thunkName), &IGM.Module); + llvm::Value *asyncFunctionPtr = nullptr; fwd->setCallingConv(outSig.getCallingConv()); fwd->setAttributes(outAttrs); // Merge initial attributes with outAttrs. llvm::AttrBuilder b; - IGM.constructInitialFnAttributes(b); + bool disablePtrAuthReturns = + outSig.getCallingConv() == llvm::CallingConv::SwiftTail; + IGM.constructInitialFnAttributes(b, disablePtrAuthReturns); fwd->addAttributes(llvm::AttributeList::FunctionIndex, b); IRGenFunction subIGF(IGM, fwd); - if (origType->isAsync()) - subIGF.setupAsync(); + if (origType->isAsync()) { + subIGF.setupAsync( + Signature::forAsyncEntry(IGM, outType).getAsyncContextIndex()); + + auto *calleeAFP = staticFnPtr->getDirectPointer(); + LinkEntity entity = LinkEntity::forPartialApplyForwarder(fwd); + auto size = Size(0); + assert(!asyncFunctionPtr && + "already had an async function pointer to the forwarder?!"); + asyncFunctionPtr = emitAsyncFunctionPointer(IGM, fwd, entity, size); + subIGF.Builder.CreateIntrinsicCall( + llvm::Intrinsic::coro_async_size_replace, + {subIGF.Builder.CreateBitCast(asyncFunctionPtr, IGM.Int8PtrTy), + subIGF.Builder.CreateBitCast(calleeAFP, IGM.Int8PtrTy)}); + } if (IGM.DebugInfo) IGM.DebugInfo->emitArtificialFunction(subIGF, fwd); @@ -1406,11 +1267,6 @@ static llvm::Function *emitPartialApplicationForwarder(IRGenModule &IGM, } else if (!layout->isKnownEmpty()) { rawData = emission->getContext(); data = layout->emitCastTo(subIGF, rawData); - if (origType->isAsync()) { - // Async layouts contain the size of the needed async context as their - // first element. It is not a parameter and needs to be skipped. - ++nextCapturedField; - } // Restore type metadata bindings, if we have them. if (layout->hasBindings()) { @@ -1844,7 +1700,7 @@ static llvm::Function *emitPartialApplicationForwarder(IRGenModule &IGM, emission->createReturn(call); emission->end(); - return fwd; + return asyncFunctionPtr ? asyncFunctionPtr : fwd; } /// Emit a partial application thunk for a function pointer applied to a partial @@ -1865,19 +1721,6 @@ Optional irgen::emitFunctionPartialApplication( SmallVector argValTypes; SmallVector argConventions; - if (origType->isAsync()) { - // Store the size of the partially applied async function's context here so - // that it can be recovered by at the apply site. - auto int32ASTType = - BuiltinIntegerType::get(32, IGF.IGM.IRGen.SIL.getASTContext()) - ->getCanonicalType(); - auto int32SILType = SILType::getPrimitiveObjectType(int32ASTType); - const TypeInfo &int32TI = IGF.IGM.getTypeInfo(int32SILType); - argValTypes.push_back(int32SILType); - argTypeInfos.push_back(&int32TI); - argConventions.push_back(ParameterConvention::Direct_Unowned); - } - // A context's HeapLayout stores all of the partially applied args. // A HeapLayout is "fixed" if all of its fields have a fixed layout. // Otherwise the HeapLayout is "non-fixed". @@ -1907,20 +1750,10 @@ Optional irgen::emitFunctionPartialApplication( auto bindings = NecessaryBindings::forPartialApplyForwarder( IGF.IGM, origType, subs, considerParameterSources); + // TODO: Revisit. Now that async thick functions are always represented with + // an async function pointer, it should again be possible to allow + // contexts that consist of only a single swift refcounted value. if (origType->isAsync()) { - // The size of the async context needs to be available at the apply site. - // - // TODO: In the "single refcounted context" case the async "function - // pointer" (actually a pointer to a - // constant { - // /*context size*/ i32, - // /*relative address of function*/ i32 - // } - // rather than a pointer directly to the function) would be able to - // provide the async context size required. At the apply site, it is - // possible to determine whether we're in the "single refcounted - // context" by looking at the metadata of a nonnull context pointer - // and checking whether it is TargetHeapMetadata. hasSingleSwiftRefcountedContext = No; } @@ -2115,7 +1948,7 @@ Optional irgen::emitFunctionPartialApplication( && "argument info lists out of sync"); HeapLayout layout(IGF.IGM, LayoutStrategy::Optimal, argValTypes, argTypeInfos, /*typeToFill*/ nullptr, std::move(bindings), - /*bindingsIndex*/ origType->isAsync() ? 1 : 0); + /*bindingsIndex*/ 0); llvm::Value *data; @@ -2147,15 +1980,6 @@ Optional irgen::emitFunctionPartialApplication( unsigned i = 0; - if (origType->isAsync()) { - auto &fieldLayout = layout.getElement(i); - auto &fieldTI = fieldLayout.getType(); - Address fieldAddr = fieldLayout.project(IGF, dataAddr, offsets); - cast(fieldTI).initialize(IGF, args, fieldAddr, - isOutlined); - ++i; - } - // Store necessary bindings, if we have them. if (layout.hasBindings()) { auto &bindingsLayout = layout.getElement(i); @@ -2508,19 +2332,10 @@ IRGenFunction::createAsyncDispatchFn(const FunctionPointer &fnPtr, void IRGenFunction::emitSuspensionPoint(llvm::Value *toExecutor, llvm::Value *asyncResume) { - llvm::Value *task = getAsyncTask(); - llvm::Value *callableResume = asyncResume; - - if (auto schema = IGM.getOptions().PointerAuth.TaskResumeFunction) { - auto *resumeAddr = Builder.CreateStructGEP(task, 4); - auto authInfo = PointerAuthInfo::emit( - *this, schema, resumeAddr, PointerAuthEntity()); - callableResume = emitPointerAuthSign(*this, asyncResume, authInfo); - } - // Setup the suspend point. SmallVector arguments; - arguments.push_back(IGM.getInt32(2)); // swiftasync context index + unsigned swiftAsyncContextIndex = 0; + arguments.push_back(IGM.getInt32(swiftAsyncContextIndex)); // context index arguments.push_back(asyncResume); auto resumeProjFn = getOrCreateResumeFromSuspensionFn(); arguments.push_back( @@ -2529,14 +2344,14 @@ void IRGenFunction::emitSuspensionPoint(llvm::Value *toExecutor, arguments.push_back( Builder.CreateBitOrPointerCast(suspendFn, IGM.Int8PtrTy)); - arguments.push_back(callableResume); + // Extra arguments to pass to the suspension function. + arguments.push_back(asyncResume); arguments.push_back( - Builder.CreateBitOrPointerCast(toExecutor, getAsyncExecutor()->getType())); - arguments.push_back(task); - arguments.push_back(getAsyncExecutor()); + Builder.CreateBitOrPointerCast(toExecutor, IGM.SwiftExecutorPtrTy)); arguments.push_back(getAsyncContext()); - - emitSuspendAsyncCall(arguments); + auto resultTy = llvm::StructType::get(IGM.getLLVMContext(), {IGM.Int8PtrTy}, + false /*packed*/); + emitSuspendAsyncCall(swiftAsyncContextIndex, resultTy, arguments); } llvm::Function *IRGenFunction::getOrCreateResumeFromSuspensionFn() { @@ -2551,19 +2366,19 @@ llvm::Function *IRGenFunction::getOrCreateResumeFromSuspensionFn() { } llvm::Function *IRGenFunction::createAsyncSuspendFn() { - SmallVector argTys; - argTys.push_back(IGM.Int8PtrTy); // Resume function. - argTys.push_back(getAsyncExecutor()->getType()); // Executor to hop to. - argTys.push_back(getAsyncTask()->getType()); - argTys.push_back(getAsyncExecutor()->getType()); - argTys.push_back(getAsyncContext()->getType()); - auto *suspendFnTy = - llvm::FunctionType::get(IGM.VoidTy, argTys, false /*vaargs*/); - StringRef name = "__swift_suspend_point"; if (llvm::GlobalValue *F = IGM.Module.getNamedValue(name)) return cast(F); + // The parameters here match the extra arguments passed to + // @llvm.coro.suspend.async by emitSuspensionPoint. + SmallVector argTys; + argTys.push_back(IGM.Int8PtrTy); // resume function + argTys.push_back(IGM.SwiftExecutorPtrTy); // target executor + argTys.push_back(getAsyncContext()->getType()); // current context + auto *suspendFnTy = + llvm::FunctionType::get(IGM.VoidTy, argTys, false /*vaargs*/); + llvm::Function *suspendFn = llvm::Function::Create(suspendFnTy, llvm::Function::InternalLinkage, name, &IGM.Module); @@ -2576,26 +2391,29 @@ llvm::Function *IRGenFunction::createAsyncSuspendFn() { llvm::Value *resumeFunction = suspendFn->getArg(0); llvm::Value *targetExecutor = suspendFn->getArg(1); - llvm::Value *task = suspendFn->getArg(2); - llvm::Value *executor = suspendFn->getArg(3); - llvm::Value *context = suspendFn->getArg(4); - - Alignment ptrAlign = IGM.getPointerAlignment(); - auto *resumeAddr = Builder.CreateStructGEP(task, 4); - Builder.CreateStore(resumeFunction, Address(resumeAddr, ptrAlign)); - auto *contextAddr = Builder.CreateStructGEP(task, 5); - if (auto schema = IGM.getOptions().PointerAuth.TaskResumeContext) { - auto authInfo = PointerAuthInfo::emit(suspendIGF, schema, contextAddr, + llvm::Value *context = suspendFn->getArg(2); + context = Builder.CreateBitCast(context, IGM.SwiftContextPtrTy); + + // Sign the task resume function with the C function pointer schema. + if (auto schema = IGM.getOptions().PointerAuth.FunctionPointers) { + // TODO: use the Clang type for TaskContinuationFunction* + // to make this work with type diversity. + auto authInfo = PointerAuthInfo::emit(suspendIGF, schema, nullptr, PointerAuthEntity()); - context = emitPointerAuthSign(suspendIGF, context, authInfo); + resumeFunction = emitPointerAuthSign(suspendIGF, resumeFunction, authInfo); } - Builder.CreateStore(context, Address(contextAddr, ptrAlign)); + auto *suspendCall = Builder.CreateCall( IGM.getTaskSwitchFuncFn(), - { task, executor, targetExecutor }); + { context, resumeFunction, targetExecutor }); suspendCall->setDoesNotThrow(); suspendCall->setCallingConv(IGM.SwiftAsyncCC); suspendCall->setTailCallKind(IGM.AsyncTailCallKind); + + llvm::AttributeList attrs = suspendCall->getAttributes(); + IGM.addSwiftAsyncContextAttributes(attrs, /*context arg index*/ 0); + suspendCall->setAttributes(attrs); + Builder.CreateRetVoid(); return suspendFn; } diff --git a/lib/IRGen/GenObjC.cpp b/lib/IRGen/GenObjC.cpp index 38dcb2b3ebbaf..88d9210301314 100644 --- a/lib/IRGen/GenObjC.cpp +++ b/lib/IRGen/GenObjC.cpp @@ -717,7 +717,7 @@ static llvm::Function *emitObjCPartialApplicationForwarder(IRGenModule &IGM, fwd->setAttributes(attrs); // Merge initial attributes with attrs. llvm::AttrBuilder b; - IGM.constructInitialFnAttributes(b); + IGM.constructInitialFnAttributes(b, false /*disable ptr auth returns*/); fwd->addAttributes(llvm::AttributeList::FunctionIndex, b); IRGenFunction subIGF(IGM, fwd); diff --git a/lib/IRGen/GenThunk.cpp b/lib/IRGen/GenThunk.cpp index 8bd93eb1df6d6..98028fcb1bbe1 100644 --- a/lib/IRGen/GenThunk.cpp +++ b/lib/IRGen/GenThunk.cpp @@ -118,7 +118,9 @@ IRGenThunk::IRGenThunk(IRGenFunction &IGF, SILDeclRef declRef) if (isAsync) { asyncLayout.emplace(irgen::getAsyncContextLayout( - IGF.IGM, origTy, substTy, subMap, /*suppress generics*/ false)); + IGF.IGM, origTy, substTy, subMap, /*suppress generics*/ false, + FunctionPointer::Kind( + FunctionPointer::BasicKind::AsyncFunctionPointer))); } } @@ -127,129 +129,87 @@ IRGenThunk::IRGenThunk(IRGenFunction &IGF, SILDeclRef declRef) // conceptually all we're doing is forwarding the arguments verbatim // using the sync or async calling convention. void IRGenThunk::prepareArguments() { - if (isAsync) { - assert(!isCoroutine); - - assert(asyncLayout->hasLocalContext()); - auto context = asyncLayout->emitCastTo(IGF, IGF.getAsyncContext()); - auto localContextAddr = - asyncLayout->getLocalContextLayout().project( - IGF, context, llvm::None); - selfValue = IGF.Builder.CreateLoad(localContextAddr); - - if (isWitnessMethod) { - assert(asyncLayout->hasTrailingWitnesses()); - auto context = asyncLayout->emitCastTo( - IGF, IGF.getAsyncContext()); - - auto metadataAddr = - asyncLayout->getSelfMetadataLayout().project( - IGF, context, llvm::None); - witnessMetadata.SelfMetadata = IGF.Builder.CreateLoad(metadataAddr); - - auto wtableAddr = - asyncLayout->getSelfWitnessTableLayout().project( - IGF, context, llvm::None); - witnessMetadata.SelfWitnessTable = IGF.Builder.CreateLoad(wtableAddr); - } - - if (origTy->hasErrorResult()) { - auto errorLayout = asyncLayout->getErrorLayout(); - Address pointerToAddress = - errorLayout.project(IGF, context, /*offsets*/ llvm::None); - auto load = IGF.Builder.CreateLoad(pointerToAddress); - auto addr = Address(load, IGF.IGM.getPointerAlignment()); - IGF.setCallerErrorResultSlot(addr.getAddress()); - } - - for (unsigned i = 0, e = asyncLayout->getIndirectReturnCount(); i < e; ++i) { - Address addr = asyncLayout->getIndirectReturnLayout(i).project( - IGF, context, llvm::None); - params.add(IGF.Builder.CreateLoad(addr)); - } - - for (unsigned i = 0, e = asyncLayout->getArgumentCount(); i < e; ++i) { - auto layout = asyncLayout->getArgumentLayout(i); - Address addr = layout.project(IGF, context, llvm::None); - auto &ti = cast(layout.getType()); - ti.loadAsTake(IGF, addr, params); - } + Explosion original = IGF.collectParameters(); - if (asyncLayout->hasBindings()) { - Address addr = asyncLayout->getBindingsLayout().project( - IGF, context, llvm::None); - asyncLayout->getBindings().save(IGF, addr, params); - } - } else { - Explosion original = IGF.collectParameters(); - - if (isWitnessMethod) { - witnessMetadata.SelfWitnessTable = original.takeLast(); - witnessMetadata.SelfMetadata = original.takeLast(); - } + if (isWitnessMethod) { + witnessMetadata.SelfWitnessTable = original.takeLast(); + witnessMetadata.SelfMetadata = original.takeLast(); + } - if (origTy->hasErrorResult()) { + if (origTy->hasErrorResult()) { + if (isAsync) { + // nothing to do. + } else { errorResult = original.takeLast(); IGF.setCallerErrorResultSlot(errorResult); } + } - if (isCoroutine) { - original.transferInto(params, 1); - } + if (isCoroutine) { + original.transferInto(params, 1); + } - selfValue = original.takeLast(); + selfValue = original.takeLast(); - // Prepare indirect results, if any. - SILFunctionConventions conv(origTy, IGF.getSILModule()); - SILType directResultType = conv.getSILResultType(expansionContext); - auto &directResultTL = IGF.IGM.getTypeInfo(directResultType); - auto &schema = directResultTL.nativeReturnValueSchema(IGF.IGM); - if (schema.requiresIndirect()) { - indirectReturnSlot = original.claimNext(); - } + // Prepare indirect results, if any. + SILFunctionConventions conv(origTy, IGF.getSILModule()); + SILType directResultType = conv.getSILResultType(expansionContext); + auto &directResultTL = IGF.IGM.getTypeInfo(directResultType); + auto &schema = directResultTL.nativeReturnValueSchema(IGF.IGM); + if (schema.requiresIndirect()) { + indirectReturnSlot = original.claimNext(); + } - original.transferInto(params, conv.getNumIndirectSILResults()); - - // Prepare each parameter. - for (auto param : origTy->getParameters().drop_back()) { - auto paramType = conv.getSILType(param, expansionContext); - - // If the SIL parameter isn't passed indirectly, we need to map it - // to an explosion. - if (paramType.isObject()) { - auto ¶mTI = IGF.getTypeInfo(paramType); - auto &loadableParamTI = cast(paramTI); - auto &nativeSchema = loadableParamTI.nativeParameterValueSchema(IGF.IGM); - unsigned size = nativeSchema.size(); - - Explosion nativeParam; - if (nativeSchema.requiresIndirect()) { - // If the explosion must be passed indirectly, load the value from the - // indirect address. - Address paramAddr = - loadableParamTI.getAddressForPointer(original.claimNext()); - loadableParamTI.loadAsTake(IGF, paramAddr, nativeParam); - } else { - if (!nativeSchema.empty()) { - // Otherwise, we map from the native convention to the type's explosion - // schema. - Explosion paramExplosion; - original.transferInto(paramExplosion, size); - nativeParam = nativeSchema.mapFromNative(IGF.IGM, IGF, paramExplosion, - paramType); - } - } + original.transferInto(params, conv.getNumIndirectSILResults()); + + // Chop off the async context parameters. + if (isAsync) { + // FIXME: Once we remove async task and executor this should be one not + // three. + unsigned numAsyncContextParams = + (unsigned)AsyncFunctionArgumentIndex::Context + 1; + (void)original.claim(numAsyncContextParams); + } - nativeParam.transferInto(params, nativeParam.size()); + // Prepare each parameter. + for (auto param : origTy->getParameters().drop_back()) { + auto paramType = conv.getSILType(param, expansionContext); + + // If the SIL parameter isn't passed indirectly, we need to map it + // to an explosion. + if (paramType.isObject()) { + auto ¶mTI = IGF.getTypeInfo(paramType); + auto &loadableParamTI = cast(paramTI); + auto &nativeSchema = loadableParamTI.nativeParameterValueSchema(IGF.IGM); + unsigned size = nativeSchema.size(); + + Explosion nativeParam; + if (nativeSchema.requiresIndirect()) { + // If the explosion must be passed indirectly, load the value from the + // indirect address. + Address paramAddr = + loadableParamTI.getAddressForPointer(original.claimNext()); + loadableParamTI.loadAsTake(IGF, paramAddr, nativeParam); } else { - params.add(original.claimNext()); + if (!nativeSchema.empty()) { + // Otherwise, we map from the native convention to the type's + // explosion schema. + Explosion paramExplosion; + original.transferInto(paramExplosion, size); + nativeParam = nativeSchema.mapFromNative(IGF.IGM, IGF, paramExplosion, + paramType); + } } - } - // Anything else, just pass along. This will include things like - // generic arguments. - params.add(original.claimAll()); + nativeParam.transferInto(params, nativeParam.size()); + } else { + params.add(original.claimNext()); + } } + + // Anything else, just pass along. This will include things like + // generic arguments. + params.add(original.claimAll()); } Callee IRGenThunk::lookupMethod() { @@ -292,10 +252,12 @@ void IRGenThunk::emit() { GenericContextScope scope(IGF.IGM, origTy->getInvocationGenericSignature()); if (isAsync) { - IGF.setupAsync(); + auto asyncContextIdx = + Signature::forAsyncEntry(IGF.IGM, origTy).getAsyncContextIndex(); + IGF.setupAsync(asyncContextIdx); auto entity = LinkEntity::forDispatchThunk(declRef); - emitAsyncFunctionEntry(IGF, *asyncLayout, entity); + emitAsyncFunctionEntry(IGF, *asyncLayout, entity, asyncContextIdx); emitAsyncFunctionPointer(IGF.IGM, IGF.CurFn, entity, asyncLayout->getSize()); } @@ -348,12 +310,11 @@ void IRGenThunk::emit() { emission->end(); - if (isAsync && errorValue) { - IGF.Builder.CreateStore(errorValue, IGF.getCallerErrorResultSlot()); - } - if (isAsync) { - emitAsyncReturn(IGF, *asyncLayout, origTy, result); + Explosion error; + if (errorValue) + error.add(errorValue); + emitAsyncReturn(IGF, *asyncLayout, directResultType, origTy, result, error); return; } diff --git a/lib/IRGen/IRGenDebugInfo.cpp b/lib/IRGen/IRGenDebugInfo.cpp index a0fd3b3f574ed..92ddb5589dcb5 100644 --- a/lib/IRGen/IRGenDebugInfo.cpp +++ b/lib/IRGen/IRGenDebugInfo.cpp @@ -199,9 +199,6 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo { llvm::DILocalVariable *Var, llvm::DIExpression *Expr, unsigned Line, unsigned Col, llvm::DILocalScope *Scope, const SILDebugScope *DS, bool InCoroContext = false); -#ifndef NDEBUG - bool verifyCoroutineArgument(llvm::Value *Addr); -#endif void emitGlobalVariableDeclaration(llvm::GlobalVariable *Storage, StringRef Name, StringRef LinkageName, @@ -2476,27 +2473,6 @@ void IRGenDebugInfoImpl::emitDbgIntrinsic( } } -#ifndef NDEBUG -bool IRGenDebugInfoImpl::verifyCoroutineArgument(llvm::Value *Addr) { - llvm::Value *Storage = Addr; - while (Storage) { - if (auto *LdInst = dyn_cast(Storage)) - Storage = LdInst->getOperand(0); - else if (auto *GEPInst = dyn_cast(Storage)) - Storage = GEPInst->getOperand(0); - else if (auto *BCInst = dyn_cast(Storage)) - Storage = BCInst->getOperand(0); - else if (auto *CallInst = dyn_cast(Storage)) { - assert(CallInst->getCalledFunction() == IGM.getProjectBoxFn() && - "unhandled projection"); - Storage = CallInst->getArgOperand(0); - } else - break; - } - return llvm::isa(Storage); -} -#endif - void IRGenDebugInfoImpl::emitGlobalVariableDeclaration( llvm::GlobalVariable *Var, StringRef Name, StringRef LinkageName, DebugTypeInfo DbgTy, bool IsLocalToUnit, bool InFixedBuffer, @@ -2680,12 +2656,6 @@ void IRGenDebugInfo::emitDbgIntrinsic(IRBuilder &Builder, llvm::Value *Storage, Builder, Storage, Var, Expr, Line, Col, Scope, DS, InCoroContext); } -#ifndef NDEBUG -bool IRGenDebugInfo::verifyCoroutineArgument(llvm::Value *Addr) { - return static_cast(this)->verifyCoroutineArgument(Addr); -} -#endif - void IRGenDebugInfo::emitGlobalVariableDeclaration( llvm::GlobalVariable *Storage, StringRef Name, StringRef LinkageName, DebugTypeInfo DebugType, bool IsLocalToUnit, bool InFixedBuffer, diff --git a/lib/IRGen/IRGenDebugInfo.h b/lib/IRGen/IRGenDebugInfo.h index fc07fc33ba150..9de1d06aaea70 100644 --- a/lib/IRGen/IRGenDebugInfo.h +++ b/lib/IRGen/IRGenDebugInfo.h @@ -150,10 +150,6 @@ class IRGenDebugInfo { llvm::DILocalVariable *Var, llvm::DIExpression *Expr, unsigned Line, unsigned Col, llvm::DILocalScope *Scope, const SILDebugScope *DS, bool InCoroContext = false); -#ifndef NDEBUG - /// Verify that Addr can be processed by llvm's CoroFrame/CoroSplit. - bool verifyCoroutineArgument(llvm::Value *Addr); -#endif enum { NotHeapAllocated = false }; diff --git a/lib/IRGen/IRGenFunction.cpp b/lib/IRGen/IRGenFunction.cpp index dbef7021e04b9..0916f2028babf 100644 --- a/lib/IRGen/IRGenFunction.cpp +++ b/lib/IRGen/IRGenFunction.cpp @@ -502,7 +502,7 @@ void IRGenFunction::emitTrap(StringRef failureMessage, bool EmitUnreachable) { } Address IRGenFunction::emitTaskAlloc(llvm::Value *size, Alignment alignment) { - auto *call = Builder.CreateCall(IGM.getTaskAllocFn(), {getAsyncTask(), size}); + auto *call = Builder.CreateCall(IGM.getTaskAllocFn(), {size}); call->setDoesNotThrow(); call->setCallingConv(IGM.SwiftCC); auto address = Address(call, alignment); @@ -511,7 +511,7 @@ Address IRGenFunction::emitTaskAlloc(llvm::Value *size, Alignment alignment) { void IRGenFunction::emitTaskDealloc(Address address) { auto *call = Builder.CreateCall(IGM.getTaskDeallocFn(), - {getAsyncTask(), address.getAddress()}); + {address.getAddress()}); call->setDoesNotThrow(); call->setCallingConv(IGM.SwiftCC); } @@ -536,8 +536,7 @@ void IRGenFunction::emitGetAsyncContinuation(SILType resumeTy, StackAddress resultAddr, Explosion &out) { // Create the continuation. - // void current_sil_function(AsyncTask *currTask, Executor *currExecutor, - // AsyncContext *currCtxt) { + // void current_sil_function(AsyncContext *currCtxt) { // // A continuation is the current AsyncTask 'currTask' with: // currTask->ResumeTask = @llvm.coro.async.resume(); @@ -563,7 +562,7 @@ void IRGenFunction::emitGetAsyncContinuation(SILType resumeTy, // Create and setup the continuation context. // continuation_context.resumeCtxt = currCtxt; - // continuation_context.errResult = nulllptr; + // continuation_context.errResult = nullptr; // continuation_context.result = ... // local alloca T auto pointerAlignment = IGM.getPointerAlignment(); auto continuationContext = @@ -602,14 +601,8 @@ void IRGenFunction::emitGetAsyncContinuation(SILType resumeTy, contResultAddr->getType()->getPointerElementType()), Address(contResultAddr, pointerAlignment)); } - // continuation_context.resumeExecutor = // current executor - auto contExecutorRefAddr = - Builder.CreateStructGEP(continuationContext.getAddress(), 4); - Builder.CreateStore( - Builder.CreateBitOrPointerCast( - getAsyncExecutor(), - contExecutorRefAddr->getType()->getPointerElementType()), - Address(contExecutorRefAddr, pointerAlignment)); + // FIXME: + // continuation_context.resumeExecutor = // current executor // Fill the current task (i.e the continuation) with the continuation // information. @@ -695,7 +688,8 @@ void IRGenFunction::emitAwaitAsyncContinuation( { // Setup the suspend point. SmallVector arguments; - arguments.push_back(IGM.getInt32(2)); // swiftasync context index + unsigned swiftAsyncContextIndex = 0; + arguments.push_back(IGM.getInt32(swiftAsyncContextIndex)); // context index arguments.push_back(AsyncCoroutineCurrentResume); auto resumeProjFn = getOrCreateResumePrjFn(); arguments.push_back( @@ -704,17 +698,14 @@ void IRGenFunction::emitAwaitAsyncContinuation( auto resumeFnPtr = getFunctionPointerForResumeIntrinsic(AsyncCoroutineCurrentResume); arguments.push_back(Builder.CreateBitOrPointerCast( - createAsyncDispatchFn(resumeFnPtr, - {IGM.Int8PtrTy, IGM.Int8PtrTy, IGM.Int8PtrTy}), + createAsyncDispatchFn(resumeFnPtr, {IGM.Int8PtrTy}), IGM.Int8PtrTy)); arguments.push_back(AsyncCoroutineCurrentResume); - arguments.push_back( - Builder.CreateBitOrPointerCast(getAsyncTask(), IGM.Int8PtrTy)); - arguments.push_back( - Builder.CreateBitOrPointerCast(getAsyncExecutor(), IGM.Int8PtrTy)); arguments.push_back(Builder.CreateBitOrPointerCast( AsyncCoroutineCurrentContinuationContext, IGM.Int8PtrTy)); - emitSuspendAsyncCall(arguments); + auto resultTy = + llvm::StructType::get(IGM.getLLVMContext(), {IGM.Int8PtrTy}, false /*packed*/); + emitSuspendAsyncCall(swiftAsyncContextIndex, resultTy, arguments); auto results = Builder.CreateAtomicCmpXchg( contAwaitSyncAddr, null, one, diff --git a/lib/IRGen/IRGenFunction.h b/lib/IRGen/IRGenFunction.h index 73996c3391217..483a8fb7483f3 100644 --- a/lib/IRGen/IRGenFunction.h +++ b/lib/IRGen/IRGenFunction.h @@ -133,10 +133,11 @@ class IRGenFunction { } llvm::Value *getAsyncTask(); - llvm::Value *getAsyncExecutor(); llvm::Value *getAsyncContext(); - llvm::CallInst *emitSuspendAsyncCall(ArrayRef args); + llvm::CallInst *emitSuspendAsyncCall(unsigned swiftAsyncContextIndex, + llvm::StructType *resultTy, + ArrayRef args); llvm::Function *getOrCreateResumePrjFn(); llvm::Function *createAsyncDispatchFn(const FunctionPointer &fnPtr, @@ -175,8 +176,6 @@ class IRGenFunction { llvm::Value *AsyncCoroutineCurrentResume = nullptr; llvm::Value *AsyncCoroutineCurrentContinuationContext = nullptr; - Address asyncTaskLocation; - Address asyncExecutorLocation; Address asyncContextLocation; /// The unique block that calls @llvm.coro.end. @@ -197,8 +196,8 @@ class IRGenFunction { return getEffectiveOptimizationMode() == OptimizationMode::ForSize; } - void setupAsync(); - bool isAsync() const { return asyncTaskLocation.isValid(); } + void setupAsync(unsigned asyncContextIndex); + bool isAsync() const { return asyncContextLocation.isValid(); } Address createAlloca(llvm::Type *ty, Alignment align, const llvm::Twine &name = ""); diff --git a/lib/IRGen/IRGenMangler.cpp b/lib/IRGen/IRGenMangler.cpp index f83b44a5f4238..1ead81ef6df66 100644 --- a/lib/IRGen/IRGenMangler.cpp +++ b/lib/IRGen/IRGenMangler.cpp @@ -79,6 +79,23 @@ std::string IRGenMangler::manglePartialApplyForwarder(StringRef FuncName) { return finalize(); } +std::string +IRGenMangler::mangleAsyncNonconstantPartialApplyThunk(StringRef FuncName, + unsigned index) { + if (FuncName.empty()) { + beginMangling(); + } else { + if (FuncName.startswith(MANGLING_PREFIX_STR)) { + Buffer << FuncName; + } else { + beginMangling(); + appendIdentifier(FuncName); + } + } + appendOperator("Tw", Index(index)); + return finalize(); +} + SymbolicMangling IRGenMangler::withSymbolicReferences(IRGenModule &IGM, llvm::function_ref body) { diff --git a/lib/IRGen/IRGenMangler.h b/lib/IRGen/IRGenMangler.h index e4d05de2f0d25..89f5c653e7f9f 100644 --- a/lib/IRGen/IRGenMangler.h +++ b/lib/IRGen/IRGenMangler.h @@ -574,7 +574,9 @@ class IRGenMangler : public Mangle::ASTMangler { } std::string manglePartialApplyForwarder(StringRef FuncName); - + std::string mangleAsyncNonconstantPartialApplyThunk(StringRef FuncName, + unsigned index); + std::string mangleTypeForForeignMetadataUniquing(Type type) { return mangleTypeWithoutPrefix(type); } diff --git a/lib/IRGen/IRGenModule.cpp b/lib/IRGen/IRGenModule.cpp index e08857637d3ee..e1f4949141439 100644 --- a/lib/IRGen/IRGenModule.cpp +++ b/lib/IRGen/IRGenModule.cpp @@ -551,7 +551,7 @@ IRGenModule::IRGenModule(IRGenerator &irgen, bool isAsyncCCSupported = clangASTContext.getTargetInfo().checkCallingConvention(clang::CC_SwiftAsync) == clang::TargetInfo::CCCR_OK; - if (opts.UseAsyncLowering && isAsyncCCSupported) { + if (isAsyncCCSupported) { SwiftAsyncCC = llvm::CallingConv::SwiftTail; AsyncTailCallKind = llvm::CallInst::TCK_MustTail; } else { @@ -642,8 +642,7 @@ IRGenModule::IRGenModule(IRGenerator &irgen, // SWIFT_CC(swift) // void (AsyncTask *, ExecutorRef, AsyncContext *); TaskContinuationFunctionTy = llvm::FunctionType::get( - VoidTy, {SwiftTaskPtrTy, SwiftExecutorPtrTy, SwiftContextPtrTy}, - /*isVarArg*/ false); + VoidTy, {SwiftContextPtrTy}, /*isVarArg*/ false); TaskContinuationFunctionPtrTy = TaskContinuationFunctionTy->getPointerTo(); AsyncTaskAndContextTy = createStructType( @@ -1133,11 +1132,18 @@ void IRGenModule::setHasNoFramePointer(llvm::Function *F) { } /// Construct initial function attributes from options. -void IRGenModule::constructInitialFnAttributes(llvm::AttrBuilder &Attrs, - OptimizationMode FuncOptMode) { +void IRGenModule::constructInitialFnAttributes( + llvm::AttrBuilder &Attrs, bool disablePtrAuthReturns, + OptimizationMode FuncOptMode) { // Add the default attributes for the Clang configuration. clang::CodeGen::addDefaultFunctionDefinitionAttributes(getClangCGM(), Attrs); + // Disable `ptrauth-returns`. It does not work for swifttailcc lowering atm. + // The `autibsp` instruction executed before a tail call that adjust the stack + // will currently fail. + if (disablePtrAuthReturns) + Attrs.removeAttribute("ptrauth-returns"); + // Add/remove MinSize based on the appropriate setting. if (FuncOptMode == OptimizationMode::NotSet) FuncOptMode = IRGen.Opts.OptMode; @@ -1150,9 +1156,10 @@ void IRGenModule::constructInitialFnAttributes(llvm::AttrBuilder &Attrs, } } -llvm::AttributeList IRGenModule::constructInitialAttributes() { +llvm::AttributeList +IRGenModule::constructInitialAttributes(bool disablePtrAuthReturns) { llvm::AttrBuilder b; - constructInitialFnAttributes(b); + constructInitialFnAttributes(b, disablePtrAuthReturns); return llvm::AttributeList::get(getLLVMContext(), llvm::AttributeList::FunctionIndex, b); } diff --git a/lib/IRGen/IRGenModule.h b/lib/IRGen/IRGenModule.h index 0f18fd35db58d..cebcc3d06a5f1 100644 --- a/lib/IRGen/IRGenModule.h +++ b/lib/IRGen/IRGenModule.h @@ -1364,11 +1364,13 @@ private: \ bool finalize(); void constructInitialFnAttributes(llvm::AttrBuilder &Attrs, + bool disablePtrAuthReturns, OptimizationMode FuncOptMode = OptimizationMode::NotSet); void setHasNoFramePointer(llvm::AttrBuilder &Attrs); void setHasNoFramePointer(llvm::Function *F); - llvm::AttributeList constructInitialAttributes(); + llvm::AttributeList + constructInitialAttributes(bool disablePtrAuthReturns = false); void emitProtocolDecl(ProtocolDecl *D); void emitEnumDecl(EnumDecl *D); diff --git a/lib/IRGen/IRGenSIL.cpp b/lib/IRGen/IRGenSIL.cpp index 343459b30dfdf..e1707f38ca000 100644 --- a/lib/IRGen/IRGenSIL.cpp +++ b/lib/IRGen/IRGenSIL.cpp @@ -402,9 +402,9 @@ class IRGenSILFunction : llvm::SmallDenseMap TaskAllocStackSlots; llvm::SmallDenseMap, 8> AnonymousVariables; /// To avoid inserting elements into ValueDomPoints twice. - llvm::SmallDenseSet ValueVariables; + llvm::SmallDenseSet ValueVariables; /// Holds the DominancePoint of values that are storage for a source variable. - SmallVector, 8> ValueDomPoints; + SmallVector, 8> ValueDomPoints; unsigned NumAnonVars = 0; /// Accumulative amount of allocated bytes on the stack. Used to limit the @@ -742,7 +742,7 @@ class IRGenSILFunction : if (IGM.IRGen.Opts.shouldOptimize()) return; for (auto &Variable : ValueDomPoints) { - llvm::Instruction *Var = Variable.first; + llvm::Value *Var = Variable.first; DominancePoint VarDominancePoint = Variable.second; if (getActiveDominancePoint() == VarDominancePoint || isActiveDominancePointDominatedBy(VarDominancePoint)) { @@ -754,7 +754,10 @@ class IRGenSILFunction : // that this shouldn't be necessary. LiveDebugValues should be doing // this but can't in general because it currently only tracks register // locations. - llvm::BasicBlock *BB = Var->getParent(); + llvm::BasicBlock *BB = + isa(Var) + ? cast(Var)->getParent() + : &cast(Var)->getParent()->getEntryBlock(); llvm::BasicBlock *CurBB = Builder.GetInsertBlock(); if (BB == CurBB) // The current basic block must be a successor of the dbg.value(). @@ -841,56 +844,6 @@ class IRGenSILFunction : return false; } - /// Emit a direct path to an Argument. - llvm::Value *getDirectCoroutineArgument(llvm::Value *Addr) { - auto getDirect = [&](llvm::Instruction *Orig) { - llvm::Value *Buffered = Orig->getOperand(0); - llvm::Value *Direct = getDirectCoroutineArgument(Buffered); - if (Buffered == Direct) - return Orig; - llvm::Instruction *Cloned = Orig->clone(); - Cloned->setOperand(0, Direct); - Cloned->insertBefore(Orig); - return Cloned; - }; - if (auto *LdInst = dyn_cast(Addr)) - return getDirect(LdInst); - if (auto *GEPInst = dyn_cast(Addr)) - return getDirect(GEPInst); - if (auto *BCInst = dyn_cast(Addr)) - return getDirect(BCInst); - if (auto *CallInst = dyn_cast(Addr)) { - llvm::Value *Buffered = CallInst->getArgOperand(0); - if (CallInst->getCalledFunction() != IGM.getProjectBoxFn()) { - assert(false && "unhandled projection"); - return CallInst; - } - llvm::Value *Direct = getDirectCoroutineArgument(Buffered); - if (Buffered == Direct) - return CallInst; - auto *Cloned = cast(CallInst->clone()); - Cloned->setArgOperand(0, Direct); - Cloned->insertBefore(CallInst); - return Cloned; - } - if (auto *AllocaInst = dyn_cast(Addr)) { - llvm::Value *Direct = nullptr; - unsigned NumStores = 0; - for (auto &AIUse : AllocaInst->uses()) { - llvm::User *U = AIUse.getUser(); - if (llvm::StoreInst *StInst = llvm::dyn_cast(U)) { - ++NumStores; - Direct = StInst->getOperand(0); - } - } - if (NumStores == 1) - return Direct; - } - return Addr; - } - - // This returns shadow alloca when \p init is false or the shadowed value - // derived from that alloca with \p init is true. llvm::Value *emitTaskAllocShadowCopy(llvm::Value *Storage, const SILDebugScope *Scope, bool Init) { @@ -933,10 +886,6 @@ class IRGenSILFunction : llvm::Value *emitShadowCopy(llvm::Value *Storage, const SILDebugScope *Scope, SILDebugVariable VarInfo, llvm::Optional _Align, bool Init) { - if (CurSILFn->isAsync()) - if (isTaskAlloc(Storage)) - return emitTaskAllocShadowCopy(Storage, Scope, Init); - auto Align = _Align.getValueOr(IGM.getPointerAlignment()); unsigned ArgNo = VarInfo.ArgNo; auto &Alloca = ShadowStackSlots[{ArgNo, {Scope, VarInfo.Name}}]; @@ -955,8 +904,7 @@ class IRGenSILFunction : bool shouldShadowVariable(SILDebugVariable varInfo, bool isAnonymous) { return !IGM.IRGen.Opts.DisableDebuggerShadowCopies && !IGM.IRGen.Opts.shouldOptimize() - && !isAnonymous - && !CurSILFn->isAsync(); + && !isAnonymous; } bool shouldShadowStorage(llvm::Value *Storage) { @@ -975,26 +923,40 @@ class IRGenSILFunction : bool IsAnonymous, llvm::Optional Align = None) { // Never emit shadow copies when optimizing, or if already on the stack. No - // debug info is emitted for refcounts either. Shadow copies are also - // turned off for async functions, because they make it impossible to track - // debug info during coroutine splitting. Instead we are relying on LLVM's - // CoroSplit.cpp to emit shadow copies. + // debug info is emitted for refcounts either - // Mark variables in async functions for lifetime extension, so they get - // spilled into the async context. + // Mark variables in async functions that don't generate a shadow copy for + // lifetime extension, so they get spilled into the async context. if (!IGM.IRGen.Opts.shouldOptimize() && CurSILFn->isAsync()) - if (auto *Value = dyn_cast(Storage)) - if (emitLifetimeExtendingUse(Value)) - if (ValueVariables.insert(Value).second) - ValueDomPoints.push_back({Value, getActiveDominancePoint()}); + if (isa(Storage) || isa(Storage)) { + if (emitLifetimeExtendingUse(Storage)) + if (ValueVariables.insert(Storage).second) + ValueDomPoints.push_back({Storage, getActiveDominancePoint()}); + } + // This condition must be consistent with emitPoisonDebugValueInst to avoid // generating extra shadow copies for debug_value [poison]. if (!shouldShadowVariable(VarInfo, IsAnonymous) || !shouldShadowStorage(Storage)) { return Storage; } + // Emit a shadow copy. - return emitShadowCopy(Storage, Scope, VarInfo, Align, true); + auto shadow = emitShadowCopy(Storage, Scope, VarInfo, Align, true); + + // Mark variables in async functions for lifetime extension, so they get + // spilled into the async context. + if (!IGM.IRGen.Opts.shouldOptimize() && CurSILFn->isAsync()) { + if (emitLifetimeExtendingUse(shadow)) { + if (ValueVariables.insert(shadow).second) + ValueDomPoints.push_back({shadow, getActiveDominancePoint()}); + } + auto inst = cast(shadow); + llvm::IRBuilder<> builder(inst->getNextNode()); + shadow = builder.CreateLoad(shadow); + } + + return shadow; } /// Like \c emitShadowCopyIfNeeded() but takes an \c Address instead of an @@ -1021,11 +983,13 @@ class IRGenSILFunction : // Mark variables in async functions for lifetime extension, so they get // spilled into the async context. if (!IGM.IRGen.Opts.shouldOptimize() && CurSILFn->isAsync()) - if (vals.begin() != vals.end()) - if (auto *Value = dyn_cast(vals.front())) + if (vals.begin() != vals.end()) { + auto Value = vals.front(); + if (isa(Value) || isa(Value)) if (emitLifetimeExtendingUse(Value)) if (ValueVariables.insert(Value).second) ValueDomPoints.push_back({Value, getActiveDominancePoint()}); + } return; } @@ -1043,6 +1007,15 @@ class IRGenSILFunction : auto &Alloca = ShadowStackSlots[{ArgNo, {Scope, VarInfo.Name}}]; if (Alloca.isValid()) { (void)e.claimAll(); + // Async functions use the value of the artificial address. + if (CurSILFn->isAsync()) { + auto shadow = Alloca.getAddress(); + auto inst = cast(shadow); + llvm::IRBuilder<> builder(inst->getNextNode()); + shadow = builder.CreateLoad(shadow); + copy.push_back(shadow); + return; + } } else { SILType Type = SILVal->getType(); auto <I = cast(IGM.getTypeInfo(Type)); @@ -1051,6 +1024,18 @@ class IRGenSILFunction : zeroInit(cast(Alloca.getAddress())); ArtificialLocation AutoRestore(Scope, IGM.DebugInfo.get(), Builder); LTI.initialize(*this, e, Alloca, false /* isOutlined */); + auto shadow = Alloca.getAddress(); + // Async functions use the value of the artificial address. + if (CurSILFn->isAsync() && emitLifetimeExtendingUse(shadow)) { + if (ValueVariables.insert(shadow).second) + ValueDomPoints.push_back({shadow, getActiveDominancePoint()}); + auto inst = cast(shadow); + llvm::IRBuilder<> builder(inst->getNextNode()); + shadow = builder.CreateLoad(shadow); + copy.push_back(shadow); + return; + } + } copy.push_back(Alloca.getAddress()); } @@ -1450,6 +1435,7 @@ class SyncNativeCCEntryPointArgumentEmission final llvm::Value *getCallerErrorResultArgument() override { return allParamValues.takeLast(); } + void mapAsyncParameters() override{/* nothing to map*/}; llvm::Value *getContext() override { return allParamValues.takeLast(); } Explosion getArgumentExplosion(unsigned index, unsigned size) override { assert(size > 0); @@ -1512,12 +1498,9 @@ class SyncNativeCCEntryPointArgumentEmission final class AsyncNativeCCEntryPointArgumentEmission final : public NativeCCEntryPointArgumentEmission, public AsyncEntryPointArgumentEmission { - llvm::Value *task; - llvm::Value *executor; - llvm::Value *context; + llvm::Value *context = nullptr; /*const*/ AsyncContextLayout layout; - const Address dataAddr; - unsigned polymorphicParameterIndex = 0; + Address dataAddr; Explosion loadExplosion(ElementLayout layout) { Address addr = layout.project(IGF, dataAddr, /*offsets*/ llvm::None); @@ -1536,85 +1519,45 @@ class AsyncNativeCCEntryPointArgumentEmission final SILBasicBlock &entry, Explosion &allParamValues) : AsyncEntryPointArgumentEmission(IGF, entry, allParamValues), - task(allParamValues.claimNext()), executor(allParamValues.claimNext()), - context(allParamValues.claimNext()), layout(getAsyncContextLayout(IGF)), - dataAddr(layout.emitCastTo(IGF, context)){}; + layout(getAsyncContextLayout(IGF)){}; + + void mapAsyncParameters() override { + context = allParamValues.claimNext(); + dataAddr = layout.emitCastTo(IGF, context); + }; llvm::Value *getCallerErrorResultArgument() override { - auto errorLayout = layout.getErrorLayout(); - Address pointerToAddress = - errorLayout.project(IGF, dataAddr, /*offsets*/ llvm::None); - auto load = IGF.Builder.CreateLoad(pointerToAddress); - auto addr = Address(load, IGF.IGM.getPointerAlignment()); - return addr.getAddress(); - } - llvm::Value *getContext() override { - auto contextLayout = layout.getLocalContextLayout(); - return loadValue(contextLayout); + llvm_unreachable("should not be used"); } + llvm::Value *getContext() override { return allParamValues.takeLast(); } Explosion getArgumentExplosion(unsigned index, unsigned size) override { - auto argumentLayout = layout.getArgumentLayout(index); - auto result = loadExplosion(argumentLayout); + assert(size > 0); + Explosion result; + allParamValues.transferInto(result, size); return result; } - bool requiresIndirectResult(SILType retType) override { return false; } + bool requiresIndirectResult(SILType retType) override { + auto &schema = + IGF.IGM.getTypeInfo(retType).nativeReturnValueSchema(IGF.IGM); + return schema.requiresIndirect(); + } llvm::Value *getIndirectResultForFormallyDirectResult() override { - llvm_unreachable("async function do not need to lower direct SIL results " - "into indirect IR results because all results are already " - "indirected through the context"); - } - Address getNextUncastBinding() { - auto index = polymorphicParameterIndex; - ++polymorphicParameterIndex; - - assert(layout.hasBindings()); - - auto bindingLayout = layout.getBindingsLayout(); - auto bindingsAddr = bindingLayout.project(IGF, dataAddr, /*offsets*/ None); - auto erasedBindingsAddr = - IGF.Builder.CreateBitCast(bindingsAddr, IGF.IGM.Int8PtrPtrTy); - auto uncastBindingAddr = IGF.Builder.CreateConstArrayGEP( - erasedBindingsAddr, index, IGF.IGM.getPointerSize()); - return uncastBindingAddr; - } - llvm::Value *castUncastBindingToMetadata(Address uncastBindingAddr) { - auto bindingAddrAddr = IGF.Builder.CreateBitCast( - uncastBindingAddr.getAddress(), IGF.IGM.TypeMetadataPtrPtrTy); - auto bindingAddr = - IGF.Builder.CreateLoad(bindingAddrAddr, IGF.IGM.getPointerAlignment()); - return bindingAddr; - } - llvm::Value *castUncastBindingToWitnessTable(Address uncastBindingAddr) { - auto bindingAddrAddr = IGF.Builder.CreateBitCast( - uncastBindingAddr.getAddress(), IGF.IGM.WitnessTablePtrPtrTy); - auto bindingAddr = - IGF.Builder.CreateLoad(bindingAddrAddr, IGF.IGM.getPointerAlignment()); - return bindingAddr; + return allParamValues.claimNext(); } llvm::Value * getNextPolymorphicParameter(GenericRequirement &requirement) override { - auto uncastBindingAddr = getNextUncastBinding(); - if (requirement.Protocol) { - return castUncastBindingToWitnessTable(uncastBindingAddr); - } else { - return castUncastBindingToMetadata(uncastBindingAddr); - } + return allParamValues.claimNext(); } llvm::Value *getNextPolymorphicParameterAsMetadata() override { - return castUncastBindingToMetadata(getNextUncastBinding()); + return allParamValues.claimNext(); } llvm::Value *getIndirectResult(unsigned index) override { - auto fieldLayout = layout.getIndirectReturnLayout(index); - return loadValue(fieldLayout); + return allParamValues.claimNext(); }; llvm::Value *getSelfWitnessTable() override { - auto fieldLayout = layout.getSelfWitnessTableLayout(); - return loadValue(fieldLayout); - } - llvm::Value *getSelfMetadata() override { - auto fieldLayout = layout.getSelfMetadataLayout(); - return loadValue(fieldLayout); + return allParamValues.takeLast(); } + llvm::Value *getSelfMetadata() override { return allParamValues.takeLast(); } llvm::Value *getCoroutineBuffer() override { llvm_unreachable( "async functions do not use a fixed size coroutine buffer"); @@ -1625,7 +1568,35 @@ class AsyncNativeCCEntryPointArgumentEmission final const LoadableTypeInfo &loadableArgTI, std::function explosionForArgument) override { - return explosionForArgument(index, 1); + Explosion paramValues; + // If the explosion must be passed indirectly, load the value from the + // indirect address. + auto &nativeSchema = loadableArgTI.nativeParameterValueSchema(IGF.IGM); + if (nativeSchema.requiresIndirect()) { + Explosion paramExplosion = explosionForArgument(index, 1); + Address paramAddr = + loadableParamTI.getAddressForPointer(paramExplosion.claimNext()); + if (loadableParamTI.getStorageType() != loadableArgTI.getStorageType()) + paramAddr = + loadableArgTI.getAddressForPointer(IGF.Builder.CreateBitCast( + paramAddr.getAddress(), + loadableArgTI.getStorageType()->getPointerTo())); + loadableArgTI.loadAsTake(IGF, paramAddr, paramValues); + } else { + if (!nativeSchema.empty()) { + // Otherwise, we map from the native convention to the type's explosion + // schema. + Explosion nativeParam; + unsigned size = nativeSchema.size(); + Explosion paramExplosion = explosionForArgument(index, size); + paramExplosion.transferInto(nativeParam, size); + paramValues = nativeSchema.mapFromNative(IGF.IGM, IGF, nativeParam, + param->getType()); + } else { + assert(loadableParamTI.getSchema().empty()); + } + } + return paramValues; }; }; @@ -1757,8 +1728,10 @@ IRGenSILFunction::IRGenSILFunction(IRGenModule &IGM, SILFunction *f) IGM.createReplaceableProlog(*this, f); } - if (f->getLoweredFunctionType()->isAsync()) - setupAsync(); + if (f->getLoweredFunctionType()->isAsync()) { + setupAsync(Signature::forAsyncEntry(IGM, f->getLoweredFunctionType()) + .getAsyncContextIndex()); + } } IRGenSILFunction::~IRGenSILFunction() { @@ -1851,10 +1824,6 @@ static ArrayRef emitEntryPointIndirectReturn( SILType directResultType = IGF.CurSILFn->mapTypeIntoContext( fnConv.getSILResultType(IGF.IGM.getMaximalTypeExpansionContext())); if (requiresIndirectResult(directResultType)) { - assert(!IGF.CurSILFn->isAsync() && - "async function do not need to lower direct SIL results into " - "indirect IR results because all results are already indirected " - "through the context"); auto ¶mTI = IGF.IGM.getTypeInfo(directResultType); auto &retTI = IGF.IGM.getTypeInfo(IGF.getLoweredTypeInContext(directResultType)); @@ -1951,6 +1920,9 @@ static void emitEntryPointArgumentsNativeCC(IRGenSILFunction &IGF, return emission->requiresIndirectResult(retType); }); + // Map the async context parameters if present. + emission->mapAsyncParameters(); + // The witness method CC passes Self as a final argument. WitnessMetadata witnessMetadata; if (funcTy->getRepresentation() == SILFunctionTypeRepresentation::WitnessMethod) { @@ -1959,9 +1931,10 @@ static void emitEntryPointArgumentsNativeCC(IRGenSILFunction &IGF, } // Bind the error result by popping it off the parameter list. - if (funcTy->hasErrorResult()) { + if (funcTy->hasErrorResult() && !funcTy->isAsync()) { IGF.setCallerErrorResultSlot(emission->getCallerErrorResultArgument()); } + // The coroutine context should be the first parameter. switch (funcTy->getCoroutineKind()) { case SILCoroutineKind::None: @@ -1975,9 +1948,10 @@ static void emitEntryPointArgumentsNativeCC(IRGenSILFunction &IGF, } if (funcTy->isAsync()) { - emitAsyncFunctionEntry(IGF, - getAsyncContextLayout(IGF.IGM, IGF.CurSILFn), - LinkEntity::forSILFunction(IGF.CurSILFn)); + emitAsyncFunctionEntry( + IGF, getAsyncContextLayout(IGF.IGM, IGF.CurSILFn), + LinkEntity::forSILFunction(IGF.CurSILFn), + Signature::forAsyncEntry(IGF.IGM, funcTy).getAsyncContextIndex()); } SILFunctionConventions conv(funcTy, IGF.getSILModule()); @@ -2004,7 +1978,7 @@ static void emitEntryPointArgumentsNativeCC(IRGenSILFunction &IGF, // // For async functions, there will be a thick context within the async // context whenever there is no self context. - } else if (funcTy->isAsync() || funcTy->hasErrorResult() || + } else if ((!funcTy->isAsync() && funcTy->hasErrorResult()) || funcTy->getRepresentation() == SILFunctionTypeRepresentation::Thick) { llvm::Value *contextPtr = emission->getContext(); @@ -2634,6 +2608,23 @@ void IRGenSILFunction::visitGlobalAddrInst(GlobalAddrInst *i) { setLoweredAddress(i, addr); } +/// Returns true if \p val has no other uses than ref_element_addr or +/// ref_tail_addr. +static bool hasOnlyProjections(SILValue val) { + for (Operand *use : val->getUses()) { + SILInstruction *user = use->getUser(); + if (auto *upCast = dyn_cast(user)) { + if (!hasOnlyProjections(upCast)) + return false; + continue; + } + if (isa(user) || isa(user)) + continue; + return false; + } + return true; +} + void IRGenSILFunction::visitGlobalValueInst(GlobalValueInst *i) { SILGlobalVariable *var = i->getReferencedGlobal(); assert(var->isInitializedObject() && @@ -2645,17 +2636,19 @@ void IRGenSILFunction::visitGlobalValueInst(GlobalValueInst *i) { llvm::Value *Ref = IGM.getAddrOfSILGlobalVariable(var, ti, NotForDefinition).getAddress(); - - auto ClassType = loweredTy.getASTType(); - llvm::Value *Metadata = - emitClassHeapMetadataRef(*this, ClassType, MetadataValueType::TypeMetadata, - MetadataState::Complete); - llvm::Value *CastAddr = Builder.CreateBitCast(Ref, IGM.RefCountedPtrTy); - llvm::Value *InitRef = emitInitStaticObjectCall(Metadata, CastAddr, "staticref"); - InitRef = Builder.CreateBitCast(InitRef, Ref->getType()); - + // We don't need to initialize the global object if it's never used for + // something which can access the object header. + if (!hasOnlyProjections(i)) { + auto ClassType = loweredTy.getASTType(); + llvm::Value *Metadata = + emitClassHeapMetadataRef(*this, ClassType, MetadataValueType::TypeMetadata, + MetadataState::Complete); + llvm::Value *CastAddr = Builder.CreateBitCast(Ref, IGM.RefCountedPtrTy); + llvm::Value *InitRef = emitInitStaticObjectCall(Metadata, CastAddr, "staticref"); + Ref = Builder.CreateBitCast(InitRef, Ref->getType()); + } Explosion e; - e.add(InitRef); + e.add(Ref); setLoweredExplosion(i, e); } @@ -3334,19 +3327,6 @@ void IRGenSILFunction::visitPartialApplyInst(swift::PartialApplyInst *i) { Explosion llArgs; auto &lv = getLoweredValue(i->getCallee()); - if (i->getOrigCalleeType()->isAsync()) { - auto result = getPartialApplicationFunction(*this, i->getCallee(), - i->getSubstitutionMap(), - i->getSubstCalleeType()); - llvm::Value *innerContext = std::get<1>(result); - llvm::Value *size; - llvm::Value *fnPtr; - std::tie(fnPtr, size) = getAsyncFunctionAndSize( - *this, i->getOrigCalleeType()->getRepresentation(), std::get<0>(result), - innerContext, {/*function*/ false, /*size*/ true}); - assert(fnPtr == nullptr); - llArgs.add(size); - } // Lower the parameters in the callee's generic context. { @@ -3488,6 +3468,8 @@ static void emitReturnInst(IRGenSILFunction &IGF, IGF.emitCoroutineOrAsyncExit(); return; } + SILFunctionConventions conv(IGF.CurSILFn->getLoweredFunctionType(), + IGF.getSILModule()); // The invariant on the out-parameter is that it's always zeroed, so // there's nothing to do here. @@ -3495,26 +3477,50 @@ static void emitReturnInst(IRGenSILFunction &IGF, // Even if SIL has a direct return, the IR-level calling convention may // require an indirect return. if (IGF.IndirectReturn.isValid()) { - assert(!IGF.isAsync()); auto &retTI = cast(IGF.getTypeInfo(resultTy)); retTI.initialize(IGF, result, IGF.IndirectReturn, false); - IGF.Builder.CreateRetVoid(); - } else if (IGF.isAsync()) { + auto asyncLayout = getAsyncContextLayout(IGF); + if (!IGF.isAsync()) { + IGF.Builder.CreateRetVoid(); + return; + } else { + if (fnType->hasErrorResult()) { + SmallVector nativeResultsStorage; + auto errorResultType = IGF.CurSILFn->mapTypeIntoContext( + conv.getSILErrorType(IGF.IGM.getMaximalTypeExpansionContext())); + auto errorType = + cast(IGF.IGM.getStorageType(errorResultType)); + nativeResultsStorage.push_back(llvm::ConstantPointerNull::get(errorType)); + return emitAsyncReturn( + IGF, asyncLayout, fnType, + Optional>(nativeResultsStorage)); + } + + return emitAsyncReturn(IGF, asyncLayout, fnType, llvm::None); + } + } + + auto funcResultType = IGF.CurSILFn->mapTypeIntoContext( + conv.getSILResultType(IGF.IGM.getMaximalTypeExpansionContext())); + + if (IGF.isAsync()) { // If we're generating an async function, store the result into the buffer. - assert(!IGF.IndirectReturn.isValid() && - "Formally direct results should stay direct results for async " - "functions"); auto asyncLayout = getAsyncContextLayout(IGF); - emitAsyncReturn(IGF, asyncLayout, fnType, result); + Explosion error; + if (fnType->hasErrorResult()) { + SmallVector nativeResultsStorage; + auto errorResultType = IGF.CurSILFn->mapTypeIntoContext( + conv.getSILErrorType(IGF.IGM.getMaximalTypeExpansionContext())); + auto errorType = + cast(IGF.IGM.getStorageType(errorResultType)); + error.add(llvm::ConstantPointerNull::get(errorType)); + } + emitAsyncReturn(IGF, asyncLayout, funcResultType, fnType, result, error); } else { auto funcLang = IGF.CurSILFn->getLoweredFunctionType()->getLanguage(); auto swiftCCReturn = funcLang == SILFunctionLanguage::Swift; assert(swiftCCReturn || funcLang == SILFunctionLanguage::C && "Need to handle all cases"); - SILFunctionConventions conv(IGF.CurSILFn->getLoweredFunctionType(), - IGF.getSILModule()); - auto funcResultType = IGF.CurSILFn->mapTypeIntoContext( - conv.getSILResultType(IGF.IGM.getMaximalTypeExpansionContext())); IGF.emitScalarReturn(resultTy, funcResultType, result, swiftCCReturn, false); } @@ -3542,12 +3548,21 @@ void IRGenSILFunction::visitThrowInst(swift::ThrowInst *i) { // Store the exception to the error slot. llvm::Value *exn = getLoweredSingletonExplosion(i->getOperand()); - Builder.CreateStore(exn, getCallerErrorResultSlot()); - - // Async functions just return to the continuation. - if (isAsync()) { + if (!isAsync()) { + Builder.CreateStore(exn, getCallerErrorResultSlot()); + // Async functions just return to the continuation. + } else if (isAsync()) { auto layout = getAsyncContextLayout(*this); - emitAsyncReturn(*this, layout, i->getFunction()->getLoweredFunctionType()); + SILFunctionConventions conv(CurSILFn->getLoweredFunctionType(), + getSILModule()); + auto funcResultType = CurSILFn->mapTypeIntoContext( + conv.getSILResultType(IGM.getMaximalTypeExpansionContext())); + + Explosion empty; + Explosion error; + error.add(exn); + emitAsyncReturn(*this, layout, funcResultType, + i->getFunction()->getLoweredFunctionType(), empty, error); return; } @@ -4665,7 +4680,7 @@ void IRGenSILFunction::visitDebugValueInst(DebugValueInst *i) { } if (i->getDebugScope()->getInlinedFunction()->isTransparent()) return; - + auto VarInfo = i->getVarInfo(); assert(VarInfo && "debug_value without debug info"); auto SILVal = i->getOperand(); @@ -4705,12 +4720,6 @@ void IRGenSILFunction::visitDebugValueInst(DebugValueInst *i) { IndirectionKind Indirection = DirectValue; if (CurSILFn->isAsync() && !i->getDebugScope()->InlinedCallSite) { - if (VarInfo->ArgNo) - for (auto &Val : Copy) { - Val = getDirectCoroutineArgument(Val); - assert(IGM.DebugInfo->verifyCoroutineArgument(Val) && - "arg expected to be load from inside %swift.context"); - } Indirection = CoroDirectValue; } @@ -4741,9 +4750,6 @@ void IRGenSILFunction::visitDebugValueAddrInst(DebugValueAddrInst *i) { SILType SILTy = SILVal->getType(); auto RealType = SILTy.getASTType(); if (CurSILFn->isAsync() && !i->getDebugScope()->InlinedCallSite) { - if (IGM.DebugInfo && VarInfo->ArgNo) - assert(IGM.DebugInfo->verifyCoroutineArgument(Addr) && - "arg expected to be load from inside %swift.context"); Indirection = CoroIndirectValue; if (auto *PBI = dyn_cast(i->getOperand())) { // Usually debug info only ever describes the *result* of a projectBox @@ -5098,6 +5104,16 @@ void IRGenSILFunction::emitDebugInfoForAllocStack(AllocStackInst *i, SILType SILTy = i->getType(); auto RealType = SILTy.getASTType(); auto DbgTy = DebugTypeInfo::getLocalVariable(Decl, RealType, type); + // Async functions use the value of the artificial address. + auto shadow = addr; + if (CurSILFn->isAsync() && emitLifetimeExtendingUse(shadow) && + !isa(shadow)) { + if (ValueVariables.insert(shadow).second) + ValueDomPoints.push_back({shadow, getActiveDominancePoint()}); + auto inst = cast(shadow); + llvm::IRBuilder<> builder(inst->getNextNode()); + addr = builder.CreateLoad(shadow); + } bindArchetypes(DbgTy.getType()); if (IGM.DebugInfo) diff --git a/lib/IRGen/Linking.cpp b/lib/IRGen/Linking.cpp index 8fced80c55946..bcb21f6f48a2d 100644 --- a/lib/IRGen/Linking.cpp +++ b/lib/IRGen/Linking.cpp @@ -447,7 +447,8 @@ std::string LinkEntity::mangleAsString() const { case Kind::AsyncFunctionPointer: case Kind::DispatchThunkAsyncFunctionPointer: case Kind::DispatchThunkInitializerAsyncFunctionPointer: - case Kind::DispatchThunkAllocatorAsyncFunctionPointer: { + case Kind::DispatchThunkAllocatorAsyncFunctionPointer: + case Kind::PartialApplyForwarderAsyncFunctionPointer: { std::string Result(getUnderlyingEntityForAsyncFunctionPointer() .mangleAsString()); Result.append("Tu"); @@ -460,6 +461,10 @@ std::string LinkEntity::mangleAsString() const { Result.append("Tu"); return Result; } + case Kind::PartialApplyForwarder: + std::string Result; + Result = std::string(static_cast(Pointer)->getName()); + return Result; } llvm_unreachable("bad entity kind!"); } @@ -738,8 +743,11 @@ SILLinkage LinkEntity::getLinkage(ForDefinition_t forDefinition) const { case Kind::DispatchThunkAsyncFunctionPointer: case Kind::DispatchThunkInitializerAsyncFunctionPointer: case Kind::DispatchThunkAllocatorAsyncFunctionPointer: + case Kind::PartialApplyForwarderAsyncFunctionPointer: return getUnderlyingEntityForAsyncFunctionPointer() .getLinkage(ForDefinition); + case Kind::PartialApplyForwarder: + return SILLinkage::Private; } llvm_unreachable("bad link entity kind"); } @@ -763,6 +771,7 @@ bool LinkEntity::isContextDescriptor() const { case Kind::DispatchThunkAsyncFunctionPointer: case Kind::DispatchThunkInitializerAsyncFunctionPointer: case Kind::DispatchThunkAllocatorAsyncFunctionPointer: + case Kind::PartialApplyForwarderAsyncFunctionPointer: case Kind::MethodDescriptor: case Kind::MethodDescriptorDerivative: case Kind::MethodDescriptorInitializer: @@ -821,6 +830,7 @@ bool LinkEntity::isContextDescriptor() const { case Kind::NoncanonicalSpecializedGenericTypeMetadata: case Kind::NoncanonicalSpecializedGenericTypeMetadataCacheVariable: case Kind::CanonicalPrespecializedGenericTypeCachingOnceToken: + case Kind::PartialApplyForwarder: return false; } llvm_unreachable("invalid descriptor"); @@ -935,8 +945,11 @@ llvm::Type *LinkEntity::getDefaultDeclarationType(IRGenModule &IGM) const { case Kind::DispatchThunkAsyncFunctionPointer: case Kind::DispatchThunkInitializerAsyncFunctionPointer: case Kind::DispatchThunkAllocatorAsyncFunctionPointer: + case Kind::PartialApplyForwarderAsyncFunctionPointer: case Kind::AsyncFunctionPointerAST: return IGM.AsyncFunctionPointerTy; + case Kind::PartialApplyForwarder: + return IGM.FunctionPtrTy; default: llvm_unreachable("declaration LLVM type not specified"); } @@ -968,6 +981,7 @@ Alignment LinkEntity::getAlignment(IRGenModule &IGM) const { case Kind::DispatchThunkAsyncFunctionPointer: case Kind::DispatchThunkInitializerAsyncFunctionPointer: case Kind::DispatchThunkAllocatorAsyncFunctionPointer: + case Kind::PartialApplyForwarderAsyncFunctionPointer: case Kind::ObjCClassRef: case Kind::ObjCClass: case Kind::TypeMetadataLazyCacheVariable: @@ -992,6 +1006,7 @@ Alignment LinkEntity::getAlignment(IRGenModule &IGM) const { case Kind::DifferentiabilityWitness: case Kind::NoncanonicalSpecializedGenericTypeMetadata: case Kind::NoncanonicalSpecializedGenericTypeMetadataCacheVariable: + case Kind::PartialApplyForwarder: return IGM.getPointerAlignment(); case Kind::CanonicalPrespecializedGenericTypeCachingOnceToken: case Kind::TypeMetadataDemanglingCacheVariable: @@ -1086,6 +1101,7 @@ bool LinkEntity::isWeakImported(ModuleDecl *module) const { // TODO: Revisit some of the below, for weak conformances. case Kind::ObjCMetadataUpdateFunction: case Kind::ObjCResilientClassStub: + case Kind::PartialApplyForwarder: case Kind::TypeMetadataPattern: case Kind::TypeMetadataInstantiationCache: case Kind::TypeMetadataInstantiationFunction: @@ -1113,6 +1129,7 @@ bool LinkEntity::isWeakImported(ModuleDecl *module) const { case Kind::DispatchThunkAsyncFunctionPointer: case Kind::DispatchThunkInitializerAsyncFunctionPointer: case Kind::DispatchThunkAllocatorAsyncFunctionPointer: + case Kind::PartialApplyForwarderAsyncFunctionPointer: return getUnderlyingEntityForAsyncFunctionPointer() .isWeakImported(module); } @@ -1221,12 +1238,14 @@ DeclContext *LinkEntity::getDeclContextForEmission() const { case Kind::ValueWitness: case Kind::ValueWitnessTable: case Kind::DifferentiabilityWitness: + case Kind::PartialApplyForwarder: return nullptr; case Kind::AsyncFunctionPointer: case Kind::DispatchThunkAsyncFunctionPointer: case Kind::DispatchThunkInitializerAsyncFunctionPointer: case Kind::DispatchThunkAllocatorAsyncFunctionPointer: + case Kind::PartialApplyForwarderAsyncFunctionPointer: return getUnderlyingEntityForAsyncFunctionPointer() .getDeclContextForEmission(); } diff --git a/lib/IRGen/PartialApplyLowering.cpp b/lib/IRGen/PartialApplyLowering.cpp new file mode 100644 index 0000000000000..c7707bb8b720f --- /dev/null +++ b/lib/IRGen/PartialApplyLowering.cpp @@ -0,0 +1,475 @@ +//===---- PartialApplyLowering.cpp - Prepare partial_applies for IRGen ----===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +#define DEBUG_TYPE "partial-apply-lowerer" + +#include "swift/AST/ExtInfo.h" +#include "swift/AST/GenericEnvironment.h" +#include "swift/IRGen/IRGenSILPasses.h" +#include "swift/SIL/SILFunction.h" +#include "swift/SIL/SILInstruction.h" +#include "swift/SIL/SILInstructionWorklist.h" +#include "swift/SIL/SILVisitor.h" +#include "swift/SILOptimizer/PassManager/Transforms.h" +#include "swift/SILOptimizer/Utils/SILOptFunctionBuilder.h" +#include "llvm/ADT/None.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/Support/Debug.h" + +#include "IRGenMangler.h" +#include "IRGenModule.h" + +using namespace swift; + +//===----------------------------------------------------------------------===// +// PartialApplyLowerer Interface +//===----------------------------------------------------------------------===// + +class PartialApplyLowerer + : public SILInstructionVisitor { + + SILFunction &function; + irgen::IRGenModule &IGM; + SILOptFunctionBuilder &thunkBuilder; + + SmallSILInstructionWorklist<256> worklist; + bool madeChange; + + InstModCallbacks instModCallbacks; + SmallVectorImpl &thunks; + SmallVector instructionsPendingDeletion; + + SILFunction *createThunk(PartialApplyInst *instruction); + CanSILFunctionType createThunkType(PartialApplyInst *instruction); + +public: + PartialApplyLowerer(SILFunction &function, irgen::IRGenModule &IGM, + SILOptFunctionBuilder &thunkBuilder, + SmallVectorImpl &thunks) + : function(function), IGM(IGM), thunkBuilder(thunkBuilder), + worklist("APAF"), madeChange(false), + instModCallbacks( + [&](SILInstruction *instruction) { + worklist.erase(instruction); + instructionsPendingDeletion.push_back(instruction); + }, + [&](SILInstruction *instruction) { worklist.add(instruction); }, + [this](Operand *use, SILValue newValue) { + use->set(newValue); + worklist.add(use->getUser()); + }), + thunks(thunks) {} + + bool run(); + + SILInstruction *visitSILInstruction(SILInstruction *) { return nullptr; } + SILInstruction *visitPartialApplyInst(PartialApplyInst *instruction); +}; + +//===----------------------------------------------------------------------===// +// PartialApplyLowerer Utility Methods +//===----------------------------------------------------------------------===// + +bool PartialApplyLowerer::run() { + madeChange = false; + + for (auto &block : function) { + for (auto &instruction : block) { + worklist.add(&instruction); + } + } + + while (!worklist.isEmpty()) { + auto *instruction = worklist.pop_back_val(); + if (instruction == nullptr) { + continue; + } + +#ifndef NDEBUG + std::string instructionDescription; +#endif + LLVM_DEBUG(llvm::raw_string_ostream SS(instructionDescription); + instruction->print(SS); instructionDescription = SS.str();); + LLVM_DEBUG(llvm::dbgs() + << "APAF: Visiting: " << instructionDescription << '\n'); + + if (auto replacement = visit(instruction)) { + worklist.replaceInstructionWithInstruction(instruction, replacement +#ifndef NDEBUG + , + instructionDescription +#endif + ); + madeChange = true; + } + } + for (SILInstruction *instruction : instructionsPendingDeletion) { + worklist.eraseInstFromFunction(*instruction); + madeChange = true; + } + instructionsPendingDeletion.clear(); + + return madeChange; +} + +CanSILFunctionType +PartialApplyLowerer::createThunkType(PartialApplyInst *instruction) { + // The type is defined in three stages: + // (1) creation of an AnyFunctionType as follows: + // arguments: + // - the arguments of the callee + // - the callee itself + // result: + // - the results of the callee + // generic signature: + // - the signature of the original function, if any + // (2) lowering that AnyFunctionType to an initial SILFunctionType + // (3) create the final SILFunctionType whose by adjusting the parameter + // convention of every parameter (except the final) to match the + // callee's convention for that parameter + // TODO: Just define the type correctly to begin with. + + auto calleeType = instruction->getSubstCalleeType(); + + // (1) Create an AnyFunctionType. + // Form the result type which is just the tuple consisting of the callee's + // results. + llvm::SmallVector results; + for (auto result : calleeType->getResults()) { + results.push_back( + result + .getReturnValueType(function.getModule(), calleeType, + function.getTypeExpansionContext()) + ->mapTypeOutOfContext()); + } + auto resultType = + TupleType::get(results, function.getModule().getASTContext()); + + // Form the list of parameters. These are the original callee's parameters + // followed by the callee itself. + llvm::SmallVector parameters; { + for (auto parameter : calleeType->getParameters()) { + parameters.push_back(AnyFunctionType::Param( + parameter + .getArgumentType(function.getModule(), calleeType, + function.getTypeExpansionContext()) + ->mapTypeOutOfContext(), + Identifier())); + } + switch (calleeType->getRepresentation()) { + case swift::SILFunctionTypeRepresentation::Method: + case swift::SILFunctionTypeRepresentation::WitnessMethod: + // If the function is a method or a witness method, keep its generic + // arguments. + parameters.push_back( + AnyFunctionType::Param(instruction->getOrigCalleeType())); + break; + case swift::SILFunctionTypeRepresentation::Thin: + case swift::SILFunctionTypeRepresentation::Thick: + case swift::SILFunctionTypeRepresentation::Block: + case swift::SILFunctionTypeRepresentation::Closure: + case swift::SILFunctionTypeRepresentation::ObjCMethod: + case swift::SILFunctionTypeRepresentation::CFunctionPointer: + // Non-constant thick functions which are generic, i.e. those that are + // passed-in as arguments, will refer to the archetypes of the function + // to which they are passed As such, in order to be passed to the thunk, + // their types must be mapped out of the function's context to replace + // those archetypes with generic parameters. + parameters.push_back( + AnyFunctionType::Param(calleeType->mapTypeOutOfContext())); + break; + } + } + + // The generic signature is just the original function's generic signature. + CanGenericSignature signature; + if (auto *env = function.getGenericEnvironment()) { + signature = env->getGenericSignature()->getCanonicalSignature(); + } else { + signature = CanGenericSignature(); + } + + AnyFunctionType *ty; + if (signature) { + GenericFunctionType::ExtInfo info; + ty = GenericFunctionType::get(signature, parameters, resultType, info); + } else { + FunctionType::ExtInfo info; + ty = FunctionType::get(parameters, resultType, info); + } + + // (2) Lower the initial AnyFunctionType to a SILFunctionType. + auto unadjusted = + IGM.getLoweredType(ty).castTo()->getWithExtInfo( + SILExtInfoBuilder() + .withAsync() + .withRepresentation(SILFunctionTypeRepresentation::Thin) + .build()); + + // (3) Create the final SILFunctionType by modifying the parameters of the + // intermediate SILFunctionType. + // Adjust the parameter infos of each of the function's parameters to match + // those of the callee, since that information gets lost during lowering. + llvm::SmallVector parameterInfos; { + auto originalThunkParameters = unadjusted->getParameters(); + auto calleeParameters = calleeType->getParameters(); + for (auto index : indices(originalThunkParameters)) { + auto originalThunkParameter = originalThunkParameters[index]; + if (index < calleeParameters.size()) { + auto calleeParameter = calleeParameters[index]; + SILParameterInfo info = + SILParameterInfo(originalThunkParameter.getInterfaceType(), + calleeParameter.getConvention(), + originalThunkParameter.getDifferentiability()); + parameterInfos.push_back(info); + } else { + parameterInfos.push_back(originalThunkParameter); + } + } + } + + auto result = SILFunctionType::get( + unadjusted->getInvocationGenericSignature().getPointer(), + unadjusted->getExtInfo(), unadjusted->getCoroutineKind(), + unadjusted->getCalleeConvention(), parameterInfos, + unadjusted->getYields(), unadjusted->getResults(), + unadjusted->hasErrorResult() + ? Optional(unadjusted->getErrorResult()) + : llvm::None, + unadjusted->getPatternSubstitutions(), + unadjusted->getInvocationSubstitutions(), function.getASTContext(), + unadjusted->getWitnessMethodConformanceOrInvalid()); + + return result; +} + +SILFunction *PartialApplyLowerer::createThunk(PartialApplyInst *instruction) { + auto calleeType = instruction->getSubstCalleeType(); + auto thunkType = createThunkType(instruction); + + irgen::IRGenMangler Mangler; + auto name = Mangler.mangleAsyncNonconstantPartialApplyThunk( + function.getName(), thunks.size()); + + SILLocation location = RegularLocation::getAutoGeneratedLocation(); + auto *thunk = thunkBuilder.createFunction( + /*linkage=*/SILLinkage::Private, /*name=*/name, + /*type=*/thunkType, + /*genericEnv=*/function.getGenericEnvironment(), /*loc*/ llvm::None, + /*isBareSILFunction=*/IsNotBare, /*isTransparent=*/IsNotTransparent, + /*isSerialized=*/IsNotSerialized, /*isDynamic=*/IsNotDynamic, + ProfileCounter(), + /*isThunk=*/IsThunk, /*subclassScope=*/SubclassScope::NotApplicable, + /*inlineStrategy=*/InlineDefault, + /*effectsKind=*/EffectsKind::Unspecified, + /*InsertBefore=*/nullptr, function.getDebugScope()); + + thunk->setDebugScope(new (function.getModule()) + SILDebugScope(function.getLocation(), thunk)); + + auto *body = thunk->createBasicBlock(); + SILBuilder builder(body); + builder.setCurrentDebugScope(body->getParent()->getDebugScope()); + + SILFunctionConventions fnConv(thunkType, IGM.getSILModule()); + for (auto indirectResult : thunkType->getIndirectFormalResults()) { + auto outTy = + fnConv.getSILType(indirectResult, function.getTypeExpansionContext()); + outTy = thunk->mapTypeIntoContext(outTy); + body->createFunctionArgument(outTy, nullptr); + } + + for (auto parameter : thunkType->getParameters()) { + if (auto *genericEnvironment = thunk->getGenericEnvironment()) { + auto argTy = + genericEnvironment->mapTypeIntoContext(parameter.getInterfaceType()) + ->getCanonicalType(); + parameter = SILParameterInfo(argTy, parameter.getConvention(), + parameter.getDifferentiability()); + } + auto argTy = + fnConv.getSILType(parameter, function.getTypeExpansionContext()); + body->createFunctionArgument(argTy, nullptr); + } + + auto args = body->getSILFunctionArguments(); + auto size = args.size(); + SILValue callee = args[size - 1]; + + llvm::SmallVector forwardedArguments; + for (unsigned index = 0, end = size - 1; index < end; ++index) { + forwardedArguments.push_back(body->getArgument(index)); + } + + if (isConsumedParameter(calleeType->getCalleeConvention())) { + callee = builder.createCopyValue(location, callee); + } + + auto returnValue = builder.createApply( + location, callee, instruction->getSubstitutionMap(), forwardedArguments); + builder.createReturn(location, returnValue); + + assert(function.getDebugScope()->Parent != thunk->getDebugScope()->Parent); + + return thunk; +} + +//===----------------------------------------------------------------------===// +// PartialApplyLowerer Visitor Methods +//===----------------------------------------------------------------------===// + +SILInstruction * +PartialApplyLowerer::visitPartialApplyInst(PartialApplyInst *instruction) { + if (!instruction->getFunctionType()->isAsync()) { + return nullptr; + } + + // If we cannot get the referenced function, then we have a non-constant + // function. IRGen cannot create an AsyncFunctionPointer for the partial + // apply forwarder it will generate for this partial_apply instruction because + // the AsyncFunctionPointers it forms for partial apply forwarders contain + // the same async context size as the function which is partially applied*. + // Without a fixed function which is partially applied, there is no fixed size + // to use for the AsyncFunctionPointer. + // + // * In fact, it emits the @llvm.coro.async.size.replace intrinsic into the + // partial apply forwarder's body which is then processed by LLVM's + // CoroCleanup to rewrite the AsyncFunctionPointer for the forwarder with + // the async context size of the function which is partially applied. In + // any case, a fixed function whose async context size can be used is + // required. + if (instruction->getReferencedFunctionOrNull() != nullptr) { + return nullptr; + } + // if (calleeType->getRepresentation() != + // SILFunctionTypeRepresentation::Thick) { + // return nullptr; + //} + + // A partial apply of a thick, async function: + // + // %closure1 = partial_apply %thick_input(%captures) + // : @async @convention(thick) ( + // Rest..., + // Captures... + // ) + // -> Return + // + // Make two changes: + // (1) Introduce a function + // + // sil thunk( + // %rest... : Rest..., + // %captures... : Captures..., + // %thick_input : @async @convention(thick) ( + // Rest..., + // Captures... + // ) + // -> Return, + // ) + // -> Return + // { + // %return = apply %thick_input(%rest..., %captures...) + // : @async @convention(thick) ( + // Rest..., + // Captures... + // ) + // -> Return + // return %return : $Return + // } + // + // (2) Replace the original instruction + // + // %callee = function_ref @thunk : $@async @convention(thin) + // %closure2 = partial_apply %callee(%captures..., %thick_input) + // : $@async @convention(thin) ( + // Captures..., + // Rest..., + // @async @convention(thick) (Rest..., Captures...) -> Return + // ) + // + // Note that the type of the original's return + // + // %closure1 : $@async @convention(thick) (Rest...) -> Return + // + // matches that of the replacement instruction's return + // + // %closure2 : $@async @convention(thick) (Rest...) -> Return + + // (1) Introduce the thunk. + auto *thunk = createThunk(instruction); + thunks.push_back(thunk); + + // (2) Replace the original partial_apply with a partial_apply of the + // thunk, adding the original callee as the final argument. + llvm::SmallVector arguments; + { + for (auto argument : instruction->getArguments()) { + arguments.push_back(argument); + } + arguments.push_back(instruction->getCallee()); + } + + SILBuilderWithScope originalBuilder(instruction); + // %callee = function_ref @thunk : $@async @convention(thin) ( + // Rest..., + // Captures..., + // @async @convention(thick) ( + // Rest..., + // Captures... + // ) -> Return + // ) -> Return + SILValue thunkRef = + originalBuilder.createFunctionRef(instruction->getLoc(), thunk); + // %closure2 = partial_apply %callee(%captures..., %thick_input) + // : $@async @convention(thin) ( + // Captures..., + // Rest..., + // @async @convention(thick) (Rest..., Captures...) -> Return + // ) + auto *replacement = originalBuilder.createPartialApply( + instruction->getLoc(), thunkRef, thunk->getForwardingSubstitutionMap(), + arguments, + instruction->getType().getAs()->getCalleeConvention(), + instruction->isOnStack(), + GenericSpecializationInformation::create(instruction, originalBuilder)); + + return replacement; +} + +//===----------------------------------------------------------------------===// +// Top Level Entrypoint +//===----------------------------------------------------------------------===// + +namespace { +class PartialApplyLowering : public SILFunctionTransform { + void run() override { + SmallVector thunks; + + auto *function = getFunction(); + SILOptFunctionBuilder thunkBuilder(*this); + PartialApplyLowerer lowerer(*function, *getIRGenModule(), thunkBuilder, + thunks); + if (lowerer.run()) { + invalidateAnalysis(SILAnalysis::InvalidationKind::Everything); + + for (auto thunk : thunks) { + addFunctionToPassManagerWorklist(thunk, function); + } + } + } +}; +} // end anonymous namespace + +SILTransform *irgen::createPartialApplyLowering() { + return new PartialApplyLowering(); +} diff --git a/lib/IRGen/Signature.h b/lib/IRGen/Signature.h index 84c08f9176d99..cbefcf4c8c7ca 100644 --- a/lib/IRGen/Signature.h +++ b/lib/IRGen/Signature.h @@ -87,11 +87,16 @@ namespace { class SignatureExpansion; } +class AsyncInfo { +public: + uint32_t AsyncContextIdx = 0; + uint32_t AsyncResumeFunctionSwiftSelfIdx = 0; +}; + /// A signature represents something which can actually be called. class Signature { - using ExtraData = SimpleExternalUnion; + using ExtraData = + SimpleExternalUnion; llvm::FunctionType *Type; llvm::AttributeList Attributes; @@ -127,6 +132,13 @@ class Signature { static Signature forCoroutineContinuation(IRGenModule &IGM, CanSILFunctionType coroType); + static Signature forAsyncReturn(IRGenModule &IGM, + CanSILFunctionType asyncType); + static Signature forAsyncAwait(IRGenModule &IGM, + CanSILFunctionType asyncType); + static Signature forAsyncEntry(IRGenModule &IGM, + CanSILFunctionType asyncType); + llvm::FunctionType *getType() const { assert(isValid()); return Type; @@ -157,6 +169,20 @@ class Signature { return CoroutineInfo(); } + AsyncInfo getAsyncInfo() const { + assert(isValid()); + if (auto info = ExtraDataStorage.dyn_cast(ExtraDataKind)) + return *info; + return AsyncInfo(); + } + + uint32_t getAsyncContextIndex() const { + return getAsyncInfo().AsyncContextIdx; + } + uint32_t getAsyncResumeFunctionSwiftSelfIndex() const { + return getAsyncInfo().AsyncResumeFunctionSwiftSelfIdx; + } + // The mutators below should generally only be used when building up // a callee. diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index a1851f674128b..9a07752651a28 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -2819,6 +2819,102 @@ static PatternBindingInitializer *findAttributeInitContent( return nullptr; } +bool Parser::isCustomAttributeArgument() { + BacktrackingScope backtrack(*this); + if (skipSingle().hasCodeCompletion()) + return true; + + // If we have any keyword, identifier, or token that follows a function + // type's parameter list, this is a parameter list and not an attribute. + // Alternatively, we might have a token that illustrates we're not going to + // get anything following the attribute, which means the parentheses describe + // what follows the attribute. + return !Tok.isAny( + tok::arrow, tok::kw_throw, tok::kw_throws, tok::kw_rethrows, + tok::r_paren, tok::r_brace, tok::r_square, tok::r_angle) && + !Tok.isContextualKeyword("async") && !Tok.isContextualKeyword("reasync") ; +} + +bool Parser::canParseCustomAttribute() { + if (!canParseType()) + return false; + + if (Tok.isFollowingLParen() && isCustomAttributeArgument()) + skipSingle(); + + return true; +} + +ParserResult Parser::parseCustomAttribute( + SourceLoc atLoc, PatternBindingInitializer *&initContext) { + SyntaxContext->setCreateSyntax(SyntaxKind::CustomAttribute); + + // Parse a custom attribute. + auto type = parseType(diag::expected_type); + if (type.hasCodeCompletion() || type.isNull()) { + if (Tok.is(tok::l_paren) && isCustomAttributeArgument()) + skipSingle(); + + return ParserResult(ParserStatus(type)); + } + + // Parse the optional arguments. + SourceLoc lParenLoc, rParenLoc; + SmallVector args; + SmallVector argLabels; + SmallVector argLabelLocs; + SmallVector trailingClosures; + bool hasInitializer = false; + + // If we're not in a local context, we'll need a context to parse + // initializers into (should we have one). This happens for properties + // and global variables in libraries. + ParserStatus status; + if (Tok.isFollowingLParen() && isCustomAttributeArgument()) { + if (peekToken().is(tok::code_complete)) { + consumeToken(tok::l_paren); + if (CodeCompletion) { + auto typeE = new (Context) TypeExpr(type.get()); + auto CCE = new (Context) CodeCompletionExpr(Tok.getLoc()); + CodeCompletion->completePostfixExprParen(typeE, CCE); + } + consumeToken(tok::code_complete); + skipUntil(tok::r_paren); + consumeIf(tok::r_paren); + status.setHasCodeCompletionAndIsError(); + } else { + // If we have no local context to parse the initial value into, create + // one for the PBD we'll eventually create. This allows us to have + // reasonable DeclContexts for any closures that may live inside of + // initializers. + Optional initParser; + if (!CurDeclContext->isLocalContext()) { + if (!initContext) { + initContext = + new (Context) PatternBindingInitializer(CurDeclContext); + } + + initParser.emplace(*this, initContext); + } + status |= parseExprList(tok::l_paren, tok::r_paren, + /*isPostfix=*/false, /*isExprBasic=*/true, + lParenLoc, args, argLabels, argLabelLocs, + rParenLoc, + trailingClosures, + SyntaxKind::TupleExprElementList); + assert(trailingClosures.empty() && "Cannot parse a trailing closure here"); + hasInitializer = true; + } + } + + // Form the attribute. + auto *TE = new (Context) TypeExpr(type.get()); + auto customAttr = CustomAttr::create(Context, atLoc, TE, hasInitializer, + initContext, lParenLoc, args, argLabels, + argLabelLocs, rParenLoc); + return makeParserResult(status, customAttr); +} + /// \verbatim /// attribute: /// '_silgen_name' '(' identifier ')' @@ -2843,7 +2939,9 @@ static PatternBindingInitializer *findAttributeInitContent( /// but rejected since they have context-sensitive keywords. /// ParserStatus Parser::parseDeclAttribute( - DeclAttributes &Attributes, SourceLoc AtLoc, bool isFromClangAttribute) { + DeclAttributes &Attributes, SourceLoc AtLoc, + PatternBindingInitializer *&initContext, + bool isFromClangAttribute) { // If this not an identifier, the attribute is malformed. if (Tok.isNot(tok::identifier) && Tok.isNot(tok::kw_in) && @@ -2963,74 +3061,11 @@ ParserStatus Parser::parseDeclAttribute( diagnose(Tok, diag::unknown_attribute, "unknown"); } else { // Change the context to create a custom attribute syntax. - SyntaxContext->setCreateSyntax(SyntaxKind::CustomAttribute); - // Parse a custom attribute. - auto type = parseType(diag::expected_type); - if (type.hasCodeCompletion() || type.isNull()) { - if (Tok.is(tok::l_paren)) - skipSingle(); - - return ParserStatus(type); - } - - // Parse the optional arguments. - SourceLoc lParenLoc, rParenLoc; - SmallVector args; - SmallVector argLabels; - SmallVector argLabelLocs; - SmallVector trailingClosures; - bool hasInitializer = false; - ParserStatus status; - - // If we're not in a local context, we'll need a context to parse - // initializers into (should we have one). This happens for properties - // and global variables in libraries. - PatternBindingInitializer *initContext = nullptr; - - if (Tok.isFollowingLParen()) { - if (peekToken().is(tok::code_complete)) { - consumeToken(tok::l_paren); - if (CodeCompletion) { - auto typeE = new (Context) TypeExpr(type.get()); - auto CCE = new (Context) CodeCompletionExpr(Tok.getLoc()); - CodeCompletion->completePostfixExprParen(typeE, CCE); - } - consumeToken(tok::code_complete); - skipUntil(tok::r_paren); - consumeIf(tok::r_paren); - status.setHasCodeCompletionAndIsError(); - } else { - // If we have no local context to parse the initial value into, create - // one for the PBD we'll eventually create. This allows us to have - // reasonable DeclContexts for any closures that may live inside of - // initializers. - Optional initParser; - if (!CurDeclContext->isLocalContext()) { - initContext = findAttributeInitContent(Attributes); - if (!initContext) - initContext = - new (Context) PatternBindingInitializer(CurDeclContext); - - initParser.emplace(*this, initContext); - } - status |= parseExprList(tok::l_paren, tok::r_paren, - /*isPostfix=*/false, /*isExprBasic=*/true, - lParenLoc, args, argLabels, argLabelLocs, - rParenLoc, - trailingClosures, - SyntaxKind::TupleExprElementList); - assert(trailingClosures.empty() && "Cannot parse a trailing closure here"); - hasInitializer = true; - } - } + auto customAttr = parseCustomAttribute(AtLoc, initContext); + if (auto attr = customAttr.getPtrOrNull()) + Attributes.add(attr); - // Form the attribute. - auto *TE = new (Context) TypeExpr(type.get()); - auto attr = CustomAttr::create(Context, AtLoc, TE, hasInitializer, - initContext, lParenLoc, args, argLabels, - argLabelLocs, rParenLoc); - Attributes.add(attr); - return status; + return ParserStatus(customAttr); } // Recover by eating @foo(...) when foo is not known. @@ -3043,7 +3078,8 @@ ParserStatus Parser::parseDeclAttribute( bool Parser::canParseTypeAttribute() { TypeAttributes attrs; // ignored - return !parseTypeAttribute(attrs, /*atLoc=*/SourceLoc(), + PatternBindingInitializer *initContext = nullptr; + return !parseTypeAttribute(attrs, /*atLoc=*/SourceLoc(), initContext, /*justChecking*/ true); } @@ -3204,6 +3240,7 @@ bool Parser::parseConventionAttributeInternal( /// canParseTypeAttribute; don't emit any diagnostics, and there's /// no need to actually record the attribute bool Parser::parseTypeAttribute(TypeAttributes &Attributes, SourceLoc AtLoc, + PatternBindingInitializer *&initContext, bool justChecking) { // If this not an identifier, the attribute is malformed. if (Tok.isNot(tok::identifier) && @@ -3218,15 +3255,11 @@ bool Parser::parseTypeAttribute(TypeAttributes &Attributes, SourceLoc AtLoc, TypeAttrKind attr = TypeAttributes::getAttrKindFromString(Tok.getText()); if (attr == TAK_Count) { - if (justChecking) return true; - auto declAttrID = DeclAttribute::getAttrKindFromString(Tok.getText()); - if (declAttrID == DAK_Count) { - // Not a decl or type attribute. - diagnose(Tok, diag::unknown_attribute, Tok.getText()); - } else { - // Otherwise this is a valid decl attribute so they should have put it on - // the decl instead of the type. + if (declAttrID != DAK_Count) { + // This is a valid decl attribute so they should have put it on the decl + // instead of the type. + if (justChecking) return true; // If this is the first attribute, and if we are on a simple decl, emit a // fixit to move the attribute. Otherwise, we don't have the location of @@ -3246,22 +3279,36 @@ bool Parser::parseTypeAttribute(TypeAttributes &Attributes, SourceLoc AtLoc, .fixItInsert(StructureMarkers.back().Loc, "@" + Tok.getText().str()+" "); } - } - - // Recover by eating @foo(...) when foo is not known. - consumeToken(); - SyntaxParsingContext TokListContext(SyntaxContext, SyntaxKind::TokenList); - if (Tok.is(tok::l_paren) && getEndOfPreviousLoc() == Tok.getLoc()) { - CancellableBacktrackingScope backtrack(*this); - skipSingle(); - // If we found '->', or 'throws' after paren, it's likely a parameter - // of function type. - if (Tok.isNot(tok::arrow, tok::kw_throws, tok::kw_rethrows, - tok::kw_throw)) - backtrack.cancelBacktrack(); + // Recover by eating @foo(...) when foo is not known. + consumeToken(); + SyntaxParsingContext TokListContext(SyntaxContext, SyntaxKind::TokenList); + + if (Tok.is(tok::l_paren) && getEndOfPreviousLoc() == Tok.getLoc()) { + CancellableBacktrackingScope backtrack(*this); + skipSingle(); + // If we found '->', or 'throws' after paren, it's likely a parameter + // of function type. + if (Tok.isNot(tok::arrow, tok::kw_throws, tok::kw_rethrows, + tok::kw_throw)) + backtrack.cancelBacktrack(); + } + + return true; } - return true; + + // If we're just checking, try to parse now. + if (justChecking) + return !canParseCustomAttribute(); + + // Parse as a custom attribute. + auto customAttrResult = parseCustomAttribute(AtLoc, initContext); + if (customAttrResult.isParseErrorOrHasCompletion()) + return true; + + if (auto attr = customAttrResult.get()) + Attributes.addCustomAttr(attr); + return false; } // Ok, it is a valid attribute, eat it, and then process it. @@ -3447,12 +3494,13 @@ ParserStatus Parser::parseDeclAttributeList(DeclAttributes &Attributes) { if (Tok.isNot(tok::at_sign)) return makeParserSuccess(); + PatternBindingInitializer *initContext = nullptr; ParserStatus Status; SyntaxParsingContext AttrListCtx(SyntaxContext, SyntaxKind::AttributeList); do { SyntaxParsingContext AttrCtx(SyntaxContext, SyntaxKind::Attribute); SourceLoc AtLoc = consumeToken(); - Status |= parseDeclAttribute(Attributes, AtLoc); + Status |= parseDeclAttribute(Attributes, AtLoc, initContext); } while (Tok.is(tok::at_sign)); return Status; } @@ -3669,6 +3717,7 @@ bool Parser::parseDeclModifierList(DeclAttributes &Attributes, bool Parser::parseTypeAttributeListPresent(ParamDecl::Specifier &Specifier, SourceLoc &SpecifierLoc, TypeAttributes &Attributes) { + PatternBindingInitializer *initContext = nullptr; Specifier = ParamDecl::Specifier::Default; while (Tok.is(tok::kw_inout) || (Tok.is(tok::identifier) && @@ -3701,7 +3750,7 @@ bool Parser::parseTypeAttributeListPresent(ParamDecl::Specifier &Specifier, Attributes.AtLoc = Tok.getLoc(); SyntaxParsingContext AttrCtx(SyntaxContext, SyntaxKind::Attribute); SourceLoc AtLoc = consumeToken(); - if (parseTypeAttribute(Attributes, AtLoc)) + if (parseTypeAttribute(Attributes, AtLoc, initContext)) return true; } @@ -5807,11 +5856,10 @@ void Parser::skipSILUntilSwiftDecl() { void Parser::skipAnyAttribute() { consumeToken(tok::at_sign); - if (!consumeIf(tok::identifier)) + if (!Tok.is(tok::identifier)) return; - if (consumeIf(tok::l_paren)) - skipUntil(tok::r_paren); + (void)canParseCustomAttribute(); } /// Returns a descriptive name for the given accessor/addressor kind. diff --git a/lib/Parse/ParsedRawSyntaxRecorder.cpp b/lib/Parse/ParsedRawSyntaxRecorder.cpp index 298a075a8861d..78ed9da7cd814 100644 --- a/lib/Parse/ParsedRawSyntaxRecorder.cpp +++ b/lib/Parse/ParsedRawSyntaxRecorder.cpp @@ -27,63 +27,6 @@ using namespace swift; using namespace swift::syntax; -/// Define a macro that creates a \c ParsedRawSyntaxNode. If \c -/// PARSEDRAWSYNTAXNODE_VERIFY_RANGES is defined, it passes the \c Range -/// parameter, otherwise it ignores it at the pre-processor level, which means -/// that \c Range can be an invalid expression. -#ifdef PARSEDRAWSYNTAXNODE_VERIFY_RANGES -#define makeParsedRawSyntaxNode(Opaque, SynKind, TokKind, DataKind, IsMissing, \ - Range) \ - ParsedRawSyntaxNode(Opaque, SynKind, TokKind, DataKind, IsMissing, Range) -#else -#define makeParsedRawSyntaxNode(Opaque, SynKind, TokKind, DataKind, IsMissing, \ - Range) \ - ParsedRawSyntaxNode(Opaque, SynKind, TokKind, DataKind, IsMissing) -#endif - -ParsedRawSyntaxNode -ParsedRawSyntaxRecorder::recordDeferredNode(ParsedRawSyntaxNode &node) { - switch (node.getDataKind()) { - case RecordedOrDeferredNode::Kind::Null: - case RecordedOrDeferredNode::Kind::Recorded: - llvm_unreachable("Not deferred"); - case RecordedOrDeferredNode::Kind::DeferredLayout: { - OpaqueSyntaxNode Data = SPActions->recordDeferredLayout(node.takeData()); - return makeParsedRawSyntaxNode(Data, node.getKind(), node.getTokenKind(), - ParsedRawSyntaxNode::DataKind::Recorded, - node.isMissing(), node.getRange()); - } - case RecordedOrDeferredNode::Kind::DeferredToken: { - OpaqueSyntaxNode Data = SPActions->recordDeferredToken(node.takeData()); - return makeParsedRawSyntaxNode(Data, node.getKind(), node.getTokenKind(), - ParsedRawSyntaxNode::DataKind::Recorded, - node.isMissing(), node.getRange()); - } - } -} - -ParsedRawSyntaxNode -ParsedRawSyntaxRecorder::recordToken(const Token &tok, StringRef leadingTrivia, - StringRef trailingTrivia) { - return recordToken(tok.getKind(), tok.getRange(), leadingTrivia, - trailingTrivia); -} - -ParsedRawSyntaxNode -ParsedRawSyntaxRecorder::recordToken(tok tokKind, CharSourceRange tokRange, - StringRef leadingTrivia, - StringRef trailingTrivia) { - SourceLoc offset = tokRange.getStart().getAdvancedLoc(-leadingTrivia.size()); - unsigned length = - leadingTrivia.size() + tokRange.getByteLength() + trailingTrivia.size(); - CharSourceRange range(offset, length); - OpaqueSyntaxNode n = - SPActions->recordToken(tokKind, leadingTrivia, trailingTrivia, range); - return makeParsedRawSyntaxNode(n, SyntaxKind::Token, tokKind, - ParsedRawSyntaxNode::DataKind::Recorded, - /*IsMissing=*/false, range); -} - ParsedRawSyntaxNode ParsedRawSyntaxRecorder::recordMissingToken(tok tokenKind, SourceLoc loc) { OpaqueSyntaxNode n = SPActions->recordMissingToken(tokenKind, loc); @@ -92,39 +35,6 @@ ParsedRawSyntaxRecorder::recordMissingToken(tok tokenKind, SourceLoc loc) { /*isMissing=*/true, CharSourceRange(loc, 0)); } -ParsedRawSyntaxNode -ParsedRawSyntaxRecorder::recordRawSyntax(SyntaxKind kind, - MutableArrayRef elements) { - assert(kind != SyntaxKind::Token && "Use recordToken to record a token"); -#ifdef PARSEDRAWSYNTAXNODE_VERIFY_RANGES - auto range = ParsedRawSyntaxRecorder::verifyElementRanges(elements); -#endif - - SmallVector subnodes; - if (!elements.empty()) { - for (auto &subnode : elements) { - switch (subnode.getDataKind()) { - case RecordedOrDeferredNode::Kind::Null: - subnodes.push_back(nullptr); - break; - case RecordedOrDeferredNode::Kind::Recorded: - subnodes.push_back(subnode.takeData()); - break; - case RecordedOrDeferredNode::Kind::DeferredLayout: - case RecordedOrDeferredNode::Kind::DeferredToken: { - auto recorded = recordDeferredNode(subnode); - subnodes.push_back(recorded.takeData()); - break; - } - } - } - } - OpaqueSyntaxNode n = SPActions->recordRawSyntax(kind, subnodes); - return makeParsedRawSyntaxNode(n, kind, tok::NUM_TOKENS, - ParsedRawSyntaxNode::DataKind::Recorded, - /*IsMissing=*/false, range); -} - ParsedRawSyntaxNode ParsedRawSyntaxRecorder::recordEmptyRawSyntaxCollection(SyntaxKind kind, SourceLoc loc) { @@ -134,48 +44,6 @@ ParsedRawSyntaxRecorder::recordEmptyRawSyntaxCollection(SyntaxKind kind, /*IsMissing=*/false, CharSourceRange(loc, 0)); } -/// Create a deferred layout node. -ParsedRawSyntaxNode ParsedRawSyntaxRecorder::makeDeferred( - syntax::SyntaxKind k, MutableArrayRef deferredNodes, - SyntaxParsingContext &ctx) { -#ifdef PARSEDRAWSYNTAXNODE_VERIFY_RANGES - auto range = ParsedRawSyntaxRecorder::verifyElementRanges(deferredNodes); -#endif - - RecordedOrDeferredNode *newPtr = - ctx.getScratchAlloc().Allocate( - deferredNodes.size()); - auto children = llvm::makeMutableArrayRef(newPtr, deferredNodes.size()); - for (size_t i = 0; i < deferredNodes.size(); ++i) { - auto &node = deferredNodes[i]; - assert(!node.isRecorded() && - "Cannot create a deferred layout node that has recorded children"); - - children[i] = node.takeRecordedOrDeferredNode(); - } - auto data = SPActions->makeDeferredLayout(k, /*IsMissing=*/false, children); - return makeParsedRawSyntaxNode(data, k, tok::NUM_TOKENS, - ParsedRawSyntaxNode::DataKind::DeferredLayout, - /*IsMissing=*/false, range); -} - -/// Create a deferred token node. -ParsedRawSyntaxNode -ParsedRawSyntaxRecorder::makeDeferred(Token tok, StringRef leadingTrivia, - StringRef trailingTrivia) { - CharSourceRange tokRange = tok.getRange(); - CharSourceRange RangeWithTrivia = CharSourceRange( - tokRange.getStart().getAdvancedLoc(-leadingTrivia.size()), - (unsigned)leadingTrivia.size() + tokRange.getByteLength() + - (unsigned)trailingTrivia.size()); - auto Data = - SPActions->makeDeferredToken(tok.getKind(), leadingTrivia, trailingTrivia, - RangeWithTrivia, /*IsMissing=*/false); - return makeParsedRawSyntaxNode(Data, SyntaxKind::Token, tok.getKind(), - ParsedRawSyntaxNode::DataKind::DeferredToken, - /*IsMissing=*/false, RangeWithTrivia); -} - ParsedRawSyntaxNode ParsedRawSyntaxRecorder::makeDeferredMissing(tok tokKind, SourceLoc loc) { auto Data = SPActions->makeDeferredToken( diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp index 665379c36d99c..a6dbc137585f9 100644 --- a/lib/Parse/Parser.cpp +++ b/lib/Parse/Parser.cpp @@ -647,21 +647,22 @@ SourceLoc Parser::consumeStartingGreater() { return consumeStartingCharacterOfCurrentToken(tok::r_angle); } -void Parser::skipSingle() { +ParserStatus Parser::skipSingle() { + ParserStatus status; switch (Tok.getKind()) { case tok::l_paren: consumeToken(); - skipUntil(tok::r_paren, tok::r_brace); + status |= skipUntil(tok::r_paren, tok::r_brace); consumeIf(tok::r_paren); break; case tok::l_brace: consumeToken(); - skipUntil(tok::r_brace); + status |= skipUntil(tok::r_brace); consumeIf(tok::r_brace); break; case tok::l_square: consumeToken(); - skipUntil(tok::r_square, tok::r_brace); + status |= skipUntil(tok::r_square, tok::r_brace); consumeIf(tok::r_square); break; case tok::pound_if: @@ -669,27 +670,35 @@ void Parser::skipSingle() { case tok::pound_elseif: consumeToken(); // skipUntil also implicitly stops at tok::pound_endif. - skipUntil(tok::pound_else, tok::pound_elseif); + status |= skipUntil(tok::pound_else, tok::pound_elseif); if (Tok.isAny(tok::pound_else, tok::pound_elseif)) - skipSingle(); + status |= skipSingle(); else consumeIf(tok::pound_endif); break; default: + if (Tok.is(tok::code_complete)) + status.setHasCodeCompletionAndIsError(); consumeToken(); break; } + + return status; } -void Parser::skipUntil(tok T1, tok T2) { +ParserStatus Parser::skipUntil(tok T1, tok T2) { + ParserStatus status; + // tok::NUM_TOKENS is a sentinel that means "don't skip". - if (T1 == tok::NUM_TOKENS && T2 == tok::NUM_TOKENS) return; + if (T1 == tok::NUM_TOKENS && T2 == tok::NUM_TOKENS) return status; while (Tok.isNot(T1, T2, tok::eof, tok::pound_endif, tok::pound_else, tok::pound_elseif)) - skipSingle(); + status |= skipSingle(); + + return status; } void Parser::skipUntilAnyOperator() { diff --git a/lib/SIL/IR/OperandOwnership.cpp b/lib/SIL/IR/OperandOwnership.cpp index b298ed3b92929..62e73a0564b6e 100644 --- a/lib/SIL/IR/OperandOwnership.cpp +++ b/lib/SIL/IR/OperandOwnership.cpp @@ -751,7 +751,7 @@ OperandOwnership OperandOwnershipBuiltinClassifier::visitCreateAsyncTaskFuture(BuiltinInst *bi, StringRef attr) { // The function operand is consumed by the new task. - if (&op == &bi->getOperandRef(3)) + if (&op == &bi->getOperandRef(2)) return OperandOwnership::DestroyingConsume; // FIXME: These are considered InteriorPointer because they may propagate a @@ -765,7 +765,7 @@ OperandOwnership OperandOwnershipBuiltinClassifier::visitCreateAsyncTaskGroupFuture(BuiltinInst *bi, StringRef attr) { // The function operand is consumed by the new task. - if (&op == &bi->getOperandRef(4)) + if (&op == &bi->getOperandRef(3)) return OperandOwnership::DestroyingConsume; // FIXME: These are considered InteriorPointer because they may propagate a diff --git a/lib/SIL/IR/SILFunctionType.cpp b/lib/SIL/IR/SILFunctionType.cpp index caee17358ee11..718afece304e4 100644 --- a/lib/SIL/IR/SILFunctionType.cpp +++ b/lib/SIL/IR/SILFunctionType.cpp @@ -4466,6 +4466,11 @@ SILFunctionType::isABICompatibleWith(CanSILFunctionType other, if (getRepresentation() != other->getRepresentation()) return ABICompatibilityCheckResult::DifferentFunctionRepresentations; + // `() async -> ()` is not compatible with `() async -> @error Error`. + if (!hasErrorResult() && other->hasErrorResult() && isAsync()) { + return ABICompatibilityCheckResult::DifferentErrorResultConventions; + } + // Check the results. if (getNumResults() != other->getNumResults()) return ABICompatibilityCheckResult::DifferentNumberOfResults; diff --git a/lib/SIL/IR/SILGlobalVariable.cpp b/lib/SIL/IR/SILGlobalVariable.cpp index 32aeb1470a493..d9519576fac20 100644 --- a/lib/SIL/IR/SILGlobalVariable.cpp +++ b/lib/SIL/IR/SILGlobalVariable.cpp @@ -111,6 +111,11 @@ BuiltinInst *SILGlobalVariable::getOffsetSubtract(const TupleExtractInst *TE, bool SILGlobalVariable::isValidStaticInitializerInst(const SILInstruction *I, SILModule &M) { + for (const Operand &op : I->getAllOperands()) { + // Rule out SILUndef and SILArgument. + if (!isa(op.get())) + return false; + } switch (I->getKind()) { case SILInstructionKind::BuiltinInst: { auto *bi = cast(I); diff --git a/lib/SIL/IR/TypeLowering.cpp b/lib/SIL/IR/TypeLowering.cpp index 5914bb96170ab..1589857cb6577 100644 --- a/lib/SIL/IR/TypeLowering.cpp +++ b/lib/SIL/IR/TypeLowering.cpp @@ -3086,6 +3086,11 @@ TypeConverter::checkForABIDifferences(SILModule &M, // Async/synchronous conversions always need a thunk. if (fnTy1->isAsync() != fnTy2->isAsync()) return ABIDifference::NeedsThunk; + // Usin an async function without an error result in place of an async + // function that needs an error result is not ABI compatible. + if (fnTy2->isAsync() && !fnTy1->hasErrorResult() && + fnTy2->hasErrorResult()) + return ABIDifference::NeedsThunk; // @convention(block) is a single retainable pointer so optionality // change is allowed. diff --git a/lib/SIL/Utils/MemoryLocations.cpp b/lib/SIL/Utils/MemoryLocations.cpp index a354c389a3ff3..bc9618a048b8c 100644 --- a/lib/SIL/Utils/MemoryLocations.cpp +++ b/lib/SIL/Utils/MemoryLocations.cpp @@ -396,10 +396,12 @@ bool MemoryLocations::analyzeAddrProjection( if (isEmptyType(projection->getType(), projection->getFunction())) return false; - unsigned &subLocIdx = subLocationMap[std::make_pair(parentLocIdx, fieldNr)]; + auto key = std::make_pair(parentLocIdx, fieldNr); + unsigned subLocIdx = subLocationMap[key]; if (subLocIdx == 0) { subLocIdx = locations.size(); assert(subLocIdx > 0); + subLocationMap[key] = subLocIdx; locations.push_back(Location(projection, subLocIdx, parentLocIdx)); Location &parentLoc = locations[parentLocIdx]; diff --git a/lib/SILGen/SILGenBuiltin.cpp b/lib/SILGen/SILGenBuiltin.cpp index 6eb88de69575d..8cc0ca104fe41 100644 --- a/lib/SILGen/SILGenBuiltin.cpp +++ b/lib/SILGen/SILGenBuiltin.cpp @@ -1393,7 +1393,6 @@ static ManagedValue emitBuiltinCreateAsyncTaskFuture( ArrayRef args, SGFContext C) { ASTContext &ctx = SGF.getASTContext(); auto flags = args[0].forward(SGF); - auto parentTask = args[1].borrow(SGF, loc).forward(SGF); // Form the metatype of the result type. CanType futureResultType = @@ -1429,7 +1428,7 @@ static ManagedValue emitBuiltinCreateAsyncTaskFuture( AbstractionPattern origParam(genericSig, functionTy); CanType substParamType = functionTy.subst(subs)->getCanonicalType(); auto reabstractedFun = - SGF.emitSubstToOrigValue(loc, args[2], origParam, substParamType); + SGF.emitSubstToOrigValue(loc, args[1], origParam, substParamType); auto function = emitFunctionArgumentForAsyncTaskEntryPoint( SGF, loc, reabstractedFun, futureResultType); @@ -1439,7 +1438,7 @@ static ManagedValue emitBuiltinCreateAsyncTaskFuture( ctx.getIdentifier( getBuiltinName(BuiltinValueKind::CreateAsyncTaskFuture)), SGF.getLoweredType(getAsyncTaskAndContextType(ctx)), subs, - { flags, parentTask, futureResultMetadata, function.forward(SGF) }); + { flags, futureResultMetadata, function.forward(SGF) }); return SGF.emitManagedRValueWithCleanup(apply); } @@ -1449,8 +1448,7 @@ static ManagedValue emitBuiltinCreateAsyncTaskGroupFuture( ArrayRef args, SGFContext C) { ASTContext &ctx = SGF.getASTContext(); auto flags = args[0].forward(SGF); - auto parentTask = args[1].borrow(SGF, loc).forward(SGF); - auto group = args[2].borrow(SGF, loc).forward(SGF); + auto group = args[1].borrow(SGF, loc).forward(SGF); // Form the metatype of the result type. CanType futureResultType = @@ -1468,14 +1466,14 @@ static ManagedValue emitBuiltinCreateAsyncTaskGroupFuture( SGF.B.createMetatype(loc, SGF.getLoweredType(futureResultType))); }).borrow(SGF, loc).forward(SGF); - auto function = emitFunctionArgumentForAsyncTaskEntryPoint(SGF, loc, args[3], + auto function = emitFunctionArgumentForAsyncTaskEntryPoint(SGF, loc, args[2], futureResultType); auto apply = SGF.B.createBuiltin( loc, ctx.getIdentifier( getBuiltinName(BuiltinValueKind::CreateAsyncTaskGroupFuture)), SGF.getLoweredType(getAsyncTaskAndContextType(ctx)), subs, - { flags, parentTask, group, futureResultMetadata, function.forward(SGF) }); + { flags, group, futureResultMetadata, function.forward(SGF) }); return SGF.emitManagedRValueWithCleanup(apply); } diff --git a/lib/SILGen/SILGenFunction.cpp b/lib/SILGen/SILGenFunction.cpp index d5a62e22f66f6..c7cae843bb8de 100644 --- a/lib/SILGen/SILGenFunction.cpp +++ b/lib/SILGen/SILGenFunction.cpp @@ -245,22 +245,16 @@ void SILGenFunction::emitCaptures(SILLocation loc, auto &Diags = getASTContext().Diags; SourceLoc loc; - bool isDeferBody; if (closure.kind == SILDeclRef::Kind::DefaultArgGenerator) { auto *param = getParameterAt(closure.getDecl(), closure.defaultArgIndex); loc = param->getLoc(); - isDeferBody = false; } else { auto f = *closure.getAnyFunctionRef(); loc = f.getLoc(); - isDeferBody = f.isDeferBody(); } - Diags.diagnose(loc, - isDeferBody - ? diag::capture_before_declaration_defer - : diag::capture_before_declaration, + Diags.diagnose(loc, diag::capture_before_declaration, vd->getBaseIdentifier()); Diags.diagnose(vd->getLoc(), diag::captured_value_declared_here); Diags.diagnose(capture.getLoc(), diag::value_captured_here); diff --git a/lib/SILOptimizer/Mandatory/RawSILInstLowering.cpp b/lib/SILOptimizer/Mandatory/RawSILInstLowering.cpp index ee3859c9731fc..e356da148ffbc 100644 --- a/lib/SILOptimizer/Mandatory/RawSILInstLowering.cpp +++ b/lib/SILOptimizer/Mandatory/RawSILInstLowering.cpp @@ -179,8 +179,11 @@ static void lowerAssignByWrapperInstruction(SILBuilderWithScope &b, switch (inst->getMode()) { case AssignByWrapperInst::Unknown: - llvm_unreachable("assign_by_wrapper must have a valid mode"); - + assert(b.getModule().getASTContext().hadError() && + "assign_by_wrapper must have a valid mode"); + // In case DefiniteInitialization already gave up with an error, just + // treat the assign_by_wrapper as an "init". + LLVM_FALLTHROUGH; case AssignByWrapperInst::Initialization: case AssignByWrapperInst::Assign: { SILValue initFn = inst->getInitializer(); diff --git a/lib/SILOptimizer/PassManager/PassPipeline.cpp b/lib/SILOptimizer/PassManager/PassPipeline.cpp index b25f19f343299..3aa77792c63de 100644 --- a/lib/SILOptimizer/PassManager/PassPipeline.cpp +++ b/lib/SILOptimizer/PassManager/PassPipeline.cpp @@ -760,6 +760,7 @@ SILPassPipelinePlan::getIRGenPreparePassPipeline(const SILOptions &Options) { // Insert SIL passes to run during IRGen. // Hoist generic alloc_stack instructions to the entry block to enable better // llvm-ir generation for dynamic alloca instructions. + P.addPartialApplyLowering(); P.addAllocStackHoisting(); P.addLoadableByAddress(); @@ -860,7 +861,7 @@ SILPassPipelinePlan::getOnonePassPipeline(const SILOptions &Options) { P.startPipeline("non-Diagnostic Enabling Mandatory Optimizations"); P.addForEachLoopUnroll(); P.addMandatoryCombine(); - if (P.getOptions().EnableCopyPropagation) { + if (!P.getOptions().DisableCopyPropagation) { // MandatoryCopyPropagation should only be run at -Onone, not -O. P.addMandatoryCopyPropagation(); } diff --git a/lib/SILOptimizer/SILCombiner/SILCombiner.h b/lib/SILOptimizer/SILCombiner/SILCombiner.h index 95210afdf39c1..80dee9c26230f 100644 --- a/lib/SILOptimizer/SILCombiner/SILCombiner.h +++ b/lib/SILOptimizer/SILCombiner/SILCombiner.h @@ -301,6 +301,7 @@ class SILCombiner : SILInstruction *visitMarkDependenceInst(MarkDependenceInst *MDI); SILInstruction *visitClassifyBridgeObjectInst(ClassifyBridgeObjectInst *CBOI); + SILInstruction *visitGlobalValueInst(GlobalValueInst *globalValue); SILInstruction *visitConvertFunctionInst(ConvertFunctionInst *CFI); SILInstruction * visitConvertEscapeToNoEscapeInst(ConvertEscapeToNoEscapeInst *Cvt); diff --git a/lib/SILOptimizer/SILCombiner/SILCombinerMiscVisitors.cpp b/lib/SILOptimizer/SILCombiner/SILCombinerMiscVisitors.cpp index 48ee2d1b87129..3fc1c420846e0 100644 --- a/lib/SILOptimizer/SILCombiner/SILCombinerMiscVisitors.cpp +++ b/lib/SILOptimizer/SILCombiner/SILCombinerMiscVisitors.cpp @@ -2283,3 +2283,40 @@ SILCombiner::visitClassifyBridgeObjectInst(ClassifyBridgeObjectInst *cboi) { return nullptr; } + +/// Returns true if reference counting and debug_value users of a global_value +/// can be deleted. +static bool checkGlobalValueUsers(SILValue val, + SmallVectorImpl &toDelete) { + for (Operand *use : val->getUses()) { + SILInstruction *user = use->getUser(); + if (isa(user) || isa(user)) { + toDelete.push_back(user); + continue; + } + if (auto *upCast = dyn_cast(user)) { + if (!checkGlobalValueUsers(upCast, toDelete)) + return false; + continue; + } + // Projection instructions don't access the object header, so they don't + // prevent deleting reference counting instructions. + if (isa(user) || isa(user)) + continue; + return false; + } + return true; +} + +SILInstruction * +SILCombiner::visitGlobalValueInst(GlobalValueInst *globalValue) { + // Delete all reference count instructions on a global_value if the only other + // users are projections (ref_element_addr and ref_tail_addr). + SmallVector toDelete; + if (!checkGlobalValueUsers(globalValue, toDelete)) + return nullptr; + for (SILInstruction *inst : toDelete) { + eraseInstFromFunction(*inst); + } + return nullptr; +} diff --git a/lib/SILOptimizer/Transforms/SILMem2Reg.cpp b/lib/SILOptimizer/Transforms/SILMem2Reg.cpp index aa7b2a5b5735f..0bc06666be2fd 100644 --- a/lib/SILOptimizer/Transforms/SILMem2Reg.cpp +++ b/lib/SILOptimizer/Transforms/SILMem2Reg.cpp @@ -576,6 +576,18 @@ StackAllocationPromoter::promoteAllocationInBlock(SILBasicBlock *BB) { return LastStore; } +/// Create a tuple value for an empty tuple or a tuple of empty tuples. +SILValue createValueForEmptyTuple(SILType ty, SILInstruction *insertionPoint) { + auto tupleTy = ty.castTo(); + SmallVector elements; + for (unsigned idx = 0, end = tupleTy->getNumElements(); idx < end; ++ idx) { + SILType elementTy = ty.getTupleElementType(idx); + elements.push_back(createValueForEmptyTuple(elementTy, insertionPoint)); + } + SILBuilder builder(insertionPoint); + return builder.createTuple(insertionPoint->getLoc(), ty, elements); +} + void MemoryToRegisters::removeSingleBlockAllocation(AllocStackInst *ASI) { LLVM_DEBUG(llvm::dbgs() << "*** Promoting in-block: " << *ASI); @@ -596,7 +608,7 @@ void MemoryToRegisters::removeSingleBlockAllocation(AllocStackInst *ASI) { if (!RunningVal) { // Loading without a previous store is only acceptable if the type is // Void (= empty tuple) or a tuple of Voids. - RunningVal = SILUndef::get(ASI->getElementType(), *ASI->getFunction()); + RunningVal = createValueForEmptyTuple(ASI->getElementType(), Inst); } replaceLoad(cast(Inst), RunningVal, ASI); ++NumInstRemoved; diff --git a/lib/Sema/CSApply.cpp b/lib/Sema/CSApply.cpp index 5238e092a96c4..5a5b545fdeefb 100644 --- a/lib/Sema/CSApply.cpp +++ b/lib/Sema/CSApply.cpp @@ -6842,6 +6842,22 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType, } } + // If we have a ClosureExpr, then we can safely propagate a global actor + // to the closure without invalidating prior analysis. + fromEI = fromFunc->getExtInfo(); + if (toEI.getGlobalActor() && !fromEI.getGlobalActor()) { + auto newFromFuncType = fromFunc->withExtInfo( + fromEI.withGlobalActor(toEI.getGlobalActor())); + if (applyTypeToClosureExpr(cs, expr, newFromFuncType)) { + fromFunc = newFromFuncType->castTo(); + + // Propagating the global actor bit might have satisfied the entire + // conversion. If so, we're done, otherwise keep converting. + if (fromFunc->isEqual(toType)) + return expr; + } + } + // If we have a ClosureExpr, then we can safely propagate the 'no escape' // bit to the closure without invalidating prior analysis. fromEI = fromFunc->getExtInfo(); diff --git a/lib/Sema/CSBindings.cpp b/lib/Sema/CSBindings.cpp index fa30e996b3430..bad32a94ce0ce 100644 --- a/lib/Sema/CSBindings.cpp +++ b/lib/Sema/CSBindings.cpp @@ -1612,6 +1612,13 @@ bool TypeVarBindingProducer::computeNext() { addNewBinding(binding.withType(LValueType::get(binding.BindingType))); } + // There is a tailored fix for optional key path root references, + // let's not create ambiguity by attempting unwrap when it's + // not allowed. + if (binding.Kind != BindingKind::Subtypes && + getLocator()->isKeyPathRoot() && type->getOptionalObjectType()) + continue; + // Allow solving for T even for a binding kind where that's invalid // if fixes are allowed, because that gives us the opportunity to // match T? values to the T binding by adding an unwrap fix. diff --git a/lib/Sema/CSDiagnostics.cpp b/lib/Sema/CSDiagnostics.cpp index 45b0d382c7313..3f5760975f2f1 100644 --- a/lib/Sema/CSDiagnostics.cpp +++ b/lib/Sema/CSDiagnostics.cpp @@ -1294,6 +1294,21 @@ class VarDeclMultipleReferencesChecker : public ASTWalker { int referencesCount() { return count; } }; +bool DroppedGlobalActorFunctionAttr::diagnoseAsError() { + auto fromFnType = getFromType()->getAs(); + if (!fromFnType) + return false; + + Type fromGlobalActor = fromFnType->getGlobalActor(); + if (!fromGlobalActor) + return false; + + emitDiagnostic( + diag::converting_func_loses_global_actor, getFromType(), getToType(), + fromGlobalActor); + return true; +} + bool MissingOptionalUnwrapFailure::diagnoseAsError() { if (!getUnwrappedType()->isBool()) { if (diagnoseConversionToBool()) @@ -3975,7 +3990,7 @@ bool AllowTypeOrInstanceMemberFailure::diagnoseAsError() { // If this is a reference to a static member by one of the key path // components, let's provide a tailored diagnostic and return because // that is unsupported so there is no fix-it. - if (locator->isForKeyPathComponent()) { + if (locator->isInKeyPathComponent()) { InvalidStaticMemberRefInKeyPath failure(getSolution(), Member, locator); return failure.diagnoseAsError(); } @@ -6936,6 +6951,26 @@ void MissingRawRepresentableInitFailure::fixIt( } } +bool MissingRawValueFailure::diagnoseAsError() { + auto *locator = getLocator(); + + if (locator->isLastElement()) { + MissingConformanceFailure failure(getSolution(), locator, + {RawReprType, ExpectedType}); + + auto diagnosed = failure.diagnoseAsError(); + if (!diagnosed) + return false; + + auto note = emitDiagnostic(diag::note_remapped_type, ".rawValue"); + fixIt(note); + + return true; + } + + return AbstractRawRepresentableFailure::diagnoseAsError(); +} + void MissingRawValueFailure::fixIt(InFlightDiagnostic &diagnostic) const { auto *E = getAsExpr(getAnchor()); if (!E) diff --git a/lib/Sema/CSDiagnostics.h b/lib/Sema/CSDiagnostics.h index abbf26ecf5fa7..329998d592d29 100644 --- a/lib/Sema/CSDiagnostics.h +++ b/lib/Sema/CSDiagnostics.h @@ -730,6 +730,17 @@ class AttributedFuncToTypeConversionFailure final : public ContextualFailure { bool diagnoseParameterUse() const; }; +/// Diagnose failure where a global actor attribute is dropped when +/// trying to convert one function type to another. +class DroppedGlobalActorFunctionAttr final : public ContextualFailure { +public: + DroppedGlobalActorFunctionAttr(const Solution &solution, Type fromType, + Type toType, ConstraintLocator *locator) + : ContextualFailure(solution, fromType, toType, locator) {} + + bool diagnoseAsError() override; +}; + /// Diagnose failures related to use of the unwrapped optional types, /// which require some type of force-unwrap e.g. "!" or "try!". class MissingOptionalUnwrapFailure final : public ContextualFailure { @@ -1576,7 +1587,7 @@ class InvalidMemberRefInKeyPath : public FailureDiagnostic { ConstraintLocator *locator) : FailureDiagnostic(solution, locator), Member(member) { assert(member->hasName()); - assert(locator->isForKeyPathComponent() || + assert(locator->isInKeyPathComponent() || locator->isForKeyPathDynamicMemberLookup()); } @@ -2273,6 +2284,8 @@ class MissingRawValueFailure final : public AbstractRawRepresentableFailure { Type getFromType() const override { return RawReprType; } Type getToType() const override { return ExpectedType; } + bool diagnoseAsError() override; + private: void fixIt(InFlightDiagnostic &diagnostic) const override; }; diff --git a/lib/Sema/CSFix.cpp b/lib/Sema/CSFix.cpp index 02ccf27666273..1c9430b4ac301 100644 --- a/lib/Sema/CSFix.cpp +++ b/lib/Sema/CSFix.cpp @@ -198,6 +198,23 @@ MarkExplicitlyEscaping::create(ConstraintSystem &cs, Type lhs, Type rhs, return new (cs.getAllocator()) MarkExplicitlyEscaping(cs, lhs, rhs, locator); } +bool MarkGlobalActorFunction::diagnose(const Solution &solution, + bool asNote) const { + DroppedGlobalActorFunctionAttr failure( + solution, getFromType(), getToType(), getLocator()); + return failure.diagnose(asNote); +} + +MarkGlobalActorFunction * +MarkGlobalActorFunction::create(ConstraintSystem &cs, Type lhs, Type rhs, + ConstraintLocator *locator) { + if (locator->isLastElement()) + locator = cs.getConstraintLocator( + locator, LocatorPathElt::ArgumentAttribute::forGlobalActor()); + + return new (cs.getAllocator()) MarkGlobalActorFunction(cs, lhs, rhs, locator); +} + bool AddConcurrentAttribute::diagnose(const Solution &solution, bool asNote) const { AttributedFuncToTypeConversionFailure failure( diff --git a/lib/Sema/CSGen.cpp b/lib/Sema/CSGen.cpp index fa123f61752ef..86d77a8abee93 100644 --- a/lib/Sema/CSGen.cpp +++ b/lib/Sema/CSGen.cpp @@ -13,6 +13,7 @@ // This file implements constraint generation for the type checker. // //===----------------------------------------------------------------------===// +#include "TypeCheckConcurrency.h" #include "TypeCheckType.h" #include "TypeChecker.h" #include "swift/AST/ASTVisitor.h" @@ -2045,6 +2046,11 @@ namespace { : TVO_CanBindToHole)); }(); + // For a non-async function type, add the global actor if present. + if (!extInfo.isAsync()) { + extInfo = extInfo.withGlobalActor(getExplicitGlobalActor(closure)); + } + return FunctionType::get(closureParams, resultTy, extInfo); } diff --git a/lib/Sema/CSSimplify.cpp b/lib/Sema/CSSimplify.cpp index 5a26e35143112..38f71d0fb481b 100644 --- a/lib/Sema/CSSimplify.cpp +++ b/lib/Sema/CSSimplify.cpp @@ -2015,6 +2015,29 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2, return getTypeMatchFailure(locator); } + // A global actor can be added or can match, but cannot be removed. + if (func1->getGlobalActor() || func2->getGlobalActor()) { + if (func1->getGlobalActor() && func2->getGlobalActor()) { + // If both have a global actor, match them. + TypeMatchOptions subflags = getDefaultDecompositionOptions(flags); + auto result = matchTypes(func1->getGlobalActor(), func2->getGlobalActor(), ConstraintKind::Equal, subflags, locator); + if (result == SolutionKind::Error) + return getTypeMatchFailure(locator); + } else if (func1->getGlobalActor()) { + // Cannot remove a global actor. + if (!shouldAttemptFixes()) + return getTypeMatchFailure(locator); + + auto *fix = MarkGlobalActorFunction::create( + *this, func1, func2, getConstraintLocator(locator)); + + if (recordFix(fix)) + return getTypeMatchFailure(locator); + } else if (kind < ConstraintKind::Subtype) { + return getTypeMatchFailure(locator); + } + } + // To contextual type increase the score to avoid ambiguity when solver can // find more than one viable binding different only in representation e.g. // let _: (@convention(block) () -> Void)? = Bool.random() ? nil : {} @@ -3243,7 +3266,14 @@ repairViaOptionalUnwrap(ConstraintSystem &cs, Type fromType, Type toType, // behind itself which we can use to better understand // how many levels of optionality have to be unwrapped. if (auto *OEE = dyn_cast(anchor)) { - auto type = cs.getType(OEE->getSubExpr()); + auto *subExpr = OEE->getSubExpr(); + + // First, let's check whether it has been determined that + // it was incorrect to use `?` in this position. + if (cs.hasFixFor(cs.getConstraintLocator(subExpr), FixKind::RemoveUnwrap)) + return true; + + auto type = cs.getType(subExpr); // If the type of sub-expression is optional, type of the // `OptionalEvaluationExpr` could be safely ignored because // it doesn't add any type information. @@ -3449,6 +3479,13 @@ static bool repairOutOfOrderArgumentsInBinaryFunction( bool isOperatorRef = overload->choice.getDecl()->isOperator(); + // If one of the parameters is `inout`, we can't flip the arguments. + { + auto params = fnType->getParams(); + if (params[0].isInOut() != params[1].isInOut()) + return false; + } + auto matchArgToParam = [&](Type argType, Type paramType, ASTNode anchor) { auto *loc = cs.getConstraintLocator(anchor); // If argument (and/or parameter) is a generic type let's not even try this @@ -6013,6 +6050,14 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint( } } + if (auto rawValue = isRawRepresentable(*this, type)) { + if (!rawValue->isTypeVariableOrMember() && + TypeChecker::conformsToProtocol(rawValue, protocol, DC)) { + auto *fix = UseRawValue::create(*this, type, protocolTy, loc); + return recordFix(fix) ? SolutionKind::Error : SolutionKind::Solved; + } + } + auto anchor = locator.getAnchor(); if (isExpr(anchor) && @@ -7751,8 +7796,21 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint( // Record a hole for memberTy to make it possible to form solutions // when contextual result type cannot be deduced e.g. `let _ = x.foo`. - if (auto *memberTypeVar = memberTy->getAs()) - recordPotentialHole(memberTypeVar); + if (auto *memberTypeVar = memberTy->getAs()) { + if (getFixedType(memberTypeVar)) { + // If member has been bound before the base and the base was + // incorrect at that (e.g. fallback to default `Any` type), + // then we need to re-activate all of the constraints + // associated with this member reference otherwise some of + // the constraints could be left unchecked in inactive state. + // This is especially important for key path expressions because + // `key path` constraint can't be retired until all components + // are simplified. + addTypeVariableConstraintsToWorkList(memberTypeVar); + } else { + recordPotentialHole(memberTypeVar); + } + } return SolutionKind::Solved; }; @@ -8871,15 +8929,28 @@ ConstraintSystem::simplifyKeyPathConstraint( return SolutionKind::Solved; // If we have e.g a missing member somewhere, a component type variable - // will have been marked as a potential hole. - // FIXME: This relies on the fact that we only mark an overload type - // variable as a potential hole once we've added a corresponding fix. We - // can't use 'isPlaceholder' instead, as that doesn't handle cases where the - // overload type variable gets bound to another type from the context rather - // than a hole. We need to come up with a better way of handling the - // relationship between key paths and overloads. + // would either be marked as a potential hole or would have a fix. if (llvm::any_of(componentTypeVars, [&](TypeVariableType *tv) { - return tv->getImpl().getLocator()->isForKeyPathComponent() && + auto *locator = tv->getImpl().getLocator(); + + // Result type of a component could be bound to a contextual + // (concrete) type if it's the last component in the chain, + // so the only way to detect errors is to check for fixes. + if (locator->isForKeyPathComponentResult()) { + auto path = locator->getPath(); + auto *componentLoc = + getConstraintLocator(locator->getAnchor(), path.drop_back()); + + if (hasFixFor(componentLoc, FixKind::DefineMemberBasedOnUse) || + hasFixFor(componentLoc, FixKind::UnwrapOptionalBase) || + hasFixFor(componentLoc, + FixKind::UnwrapOptionalBaseWithOptionalResult)) + return true; + } + + // If something inside of a component is marked as a hole, + // let's consider while component to be invalid. + return locator->isInKeyPathComponent() && tv->getImpl().canBindToHole(); })) { return SolutionKind::Solved; @@ -10725,7 +10796,6 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint( case FixKind::AddPropertyWrapperAttribute: case FixKind::ExpandArrayIntoVarargs: case FixKind::UseRawValue: - case FixKind::ExplicitlyConstructRawRepresentable: case FixKind::SpecifyBaseTypeForContextualMember: case FixKind::CoerceToCheckedCast: case FixKind::SpecifyObjectLiteralTypeImport: @@ -10746,6 +10816,17 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint( return recordFix(fix) ? SolutionKind::Error : SolutionKind::Solved; } + case FixKind::ExplicitlyConstructRawRepresentable: { + // Let's increase impact of this fix for binary operators because + // it's possible to get both `.rawValue` and construction fixes for + // different overloads of a binary operator and `.rawValue` is a + // better fix because raw representable has a failable constructor. + return recordFix(fix, + /*impact=*/isExpr(locator.getAnchor()) ? 2 : 1) + ? SolutionKind::Error + : SolutionKind::Solved; + } + case FixKind::TreatRValueAsLValue: { unsigned impact = 1; // If this is an attempt to use result of a function/subscript call as @@ -10871,6 +10952,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint( case FixKind::UseSubscriptOperator: case FixKind::ExplicitlyEscaping: + case FixKind::MarkGlobalActorFunction: case FixKind::RelabelArguments: case FixKind::RemoveCall: case FixKind::RemoveUnwrap: diff --git a/lib/Sema/ConstraintLocator.cpp b/lib/Sema/ConstraintLocator.cpp index 4d39a68143f4f..89f871074dd01 100644 --- a/lib/Sema/ConstraintLocator.cpp +++ b/lib/Sema/ConstraintLocator.cpp @@ -171,12 +171,16 @@ bool ConstraintLocator::isForKeyPathDynamicMemberLookup() const { return !path.empty() && path.back().isKeyPathDynamicMember(); } -bool ConstraintLocator::isForKeyPathComponent() const { +bool ConstraintLocator::isInKeyPathComponent() const { return llvm::any_of(getPath(), [&](const LocatorPathElt &elt) { return elt.isKeyPathComponent(); }); } +bool ConstraintLocator::isForKeyPathComponentResult() const { + return isLastElement(); +} + bool ConstraintLocator::isForGenericParameter() const { return isLastElement(); } @@ -487,6 +491,10 @@ void ConstraintLocator::dump(SourceManager *sm, raw_ostream &out) const { case AttrLoc::Attribute::Concurrent: out << "@concurrent"; break; + + case AttrLoc::Attribute::GlobalActor: + out << "@"; + break; } break; diff --git a/lib/Sema/ConstraintSystem.cpp b/lib/Sema/ConstraintSystem.cpp index 4479186456823..a40d2072267fa 100644 --- a/lib/Sema/ConstraintSystem.cpp +++ b/lib/Sema/ConstraintSystem.cpp @@ -4542,6 +4542,59 @@ Type Solution::resolveInterfaceType(Type type) const { Optional Solution::getFunctionArgApplyInfo(ConstraintLocator *locator) const { + auto &cs = getConstraintSystem(); + + // It's only valid to use `&` in argument positions, but we need + // to figure out exactly where it was used. + if (auto *argExpr = getAsExpr(locator->getAnchor())) { + auto *argList = cs.getParentExpr(argExpr); + assert(argList); + + // `inout` expression might be wrapped in a number of + // parens e.g. `test(((&x)))`. + if (isa(argList)) { + for (;;) { + auto nextParent = cs.getParentExpr(argList); + assert(nextParent && "Incorrect use of `inout` expression"); + + // e.g. `test((&x), x: ...)` + if (isa(nextParent)) { + argList = nextParent; + break; + } + + // e.g. `test(((&x)))` + if (isa(nextParent)) { + argList = nextParent; + continue; + } + + break; + } + } + + unsigned argIdx = 0; + if (auto *tuple = dyn_cast(argList)) { + auto arguments = tuple->getElements(); + + for (auto idx : indices(arguments)) { + if (arguments[idx]->getSemanticsProvidingExpr() == argExpr) { + argIdx = idx; + break; + } + } + } + + auto *call = cs.getParentExpr(argList); + assert(call); + + ParameterTypeFlags flags; + locator = cs.getConstraintLocator( + call, {ConstraintLocator::ApplyArgument, + LocatorPathElt::ApplyArgToParam(argIdx, argIdx, + flags.withInOut(true))}); + } + auto anchor = locator->getAnchor(); auto path = locator->getPath(); @@ -4635,7 +4688,6 @@ Solution::getFunctionArgApplyInfo(ConstraintLocator *locator) const { auto argIdx = applyArgElt->getArgIdx(); auto paramIdx = applyArgElt->getParamIdx(); - auto &cs = getConstraintSystem(); return FunctionArgApplyInfo(cs.getParentExpr(argExpr), argExpr, argIdx, simplifyType(getType(argExpr)), paramIdx, fnInterfaceType, fnType, callee); diff --git a/lib/Sema/PreCheckExpr.cpp b/lib/Sema/PreCheckExpr.cpp index ce2d3654077ed..672b05434137b 100644 --- a/lib/Sema/PreCheckExpr.cpp +++ b/lib/Sema/PreCheckExpr.cpp @@ -352,6 +352,34 @@ static bool isMemberChainTail(Expr *expr, Expr *parent) { return parent == nullptr || !isMemberChainMember(parent); } +static bool isValidForwardReference(ValueDecl *D, DeclContext *DC, + ValueDecl **localDeclAfterUse) { + *localDeclAfterUse = nullptr; + + // References to variables injected by lldb are always valid. + if (isa(D) && cast(D)->isDebuggerVar()) + return true; + + // If we find something in the current context, it must be a forward + // reference, because otherwise if it was in scope, it would have + // been returned by the call to ASTScope::lookupLocalDecls() above. + if (D->getDeclContext()->isLocalContext()) { + do { + if (D->getDeclContext() == DC) { + *localDeclAfterUse = D; + return false; + } + + // If we're inside of a 'defer' context, walk up to the parent + // and check again. We don't want 'defer' bodies to forward + // reference bindings in the immediate outer scope. + } while (isa(DC) && + cast(DC)->isDeferBody() && + (DC = DC->getParent())); + } + return true; +} + /// Bind an UnresolvedDeclRefExpr by performing name lookup and /// returning the resultant expression. Context is the DeclContext used /// for the lookup. @@ -422,24 +450,12 @@ Expr *TypeChecker::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE, Lookup = TypeChecker::lookupUnqualified(DC, LookupName, Loc, lookupOptions); ValueDecl *localDeclAfterUse = nullptr; - auto isValid = [&](ValueDecl *D) { - // References to variables injected by lldb are always valid. - if (isa(D) && cast(D)->isDebuggerVar()) - return true; - - // If we find something in the current context, it must be a forward - // reference, because otherwise if it was in scope, it would have - // been returned by the call to ASTScope::lookupLocalDecls() above. - if (D->getDeclContext()->isLocalContext() && - D->getDeclContext() == DC) { - localDeclAfterUse = D; - return false; - } - return true; - }; AllDeclRefs = findNonMembers(Lookup.innerResults(), UDRE->getRefKind(), - /*breakOnMember=*/true, ResultValues, isValid); + /*breakOnMember=*/true, ResultValues, + [&](ValueDecl *D) { + return isValidForwardReference(D, DC, &localDeclAfterUse); + }); // If local declaration after use is found, check outer results for // better matching candidates. @@ -459,7 +475,10 @@ Expr *TypeChecker::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE, localDeclAfterUse = nullptr; AllDeclRefs = findNonMembers(Lookup.innerResults(), UDRE->getRefKind(), - /*breakOnMember=*/true, ResultValues, isValid); + /*breakOnMember=*/true, ResultValues, + [&](ValueDecl *D) { + return isValidForwardReference(D, DC, &localDeclAfterUse); + }); } } } diff --git a/lib/Sema/TypeCheckAttr.cpp b/lib/Sema/TypeCheckAttr.cpp index 917de6007704e..551b4a05cdf1f 100644 --- a/lib/Sema/TypeCheckAttr.cpp +++ b/lib/Sema/TypeCheckAttr.cpp @@ -2082,71 +2082,79 @@ void AttributeChecker::visitRethrowsAttr(RethrowsAttr *attr) { attr->setInvalid(); } -/// Collect all used generic parameter types from a given type. -static void collectUsedGenericParameters( - Type Ty, SmallPtrSetImpl &ConstrainedGenericParams) { - if (!Ty) - return; +/// Ensure that the requirements provided by the @_specialize attribute +/// can be supported by the SIL EagerSpecializer pass. +static void checkSpecializeAttrRequirements(SpecializeAttr *attr, + GenericSignature originalSig, + GenericSignature specializedSig, + ASTContext &ctx) { + bool hadError = false; + + auto specializedReqs = specializedSig->requirementsNotSatisfiedBy(originalSig); + for (auto specializedReq : specializedReqs) { + if (!specializedReq.getFirstType()->is()) { + ctx.Diags.diagnose(attr->getLocation(), + diag::specialize_attr_only_generic_param_req); + hadError = true; + continue; + } - if (!Ty->hasTypeParameter()) - return; + switch (specializedReq.getKind()) { + case RequirementKind::Conformance: + case RequirementKind::Superclass: + ctx.Diags.diagnose(attr->getLocation(), + diag::specialize_attr_unsupported_kind_of_req); + hadError = true; + break; + + case RequirementKind::SameType: + if (specializedReq.getSecondType()->isTypeParameter()) { + ctx.Diags.diagnose(attr->getLocation(), + diag::specialize_attr_non_concrete_same_type_req); + hadError = true; + } + break; - // Add used generic parameters/archetypes. - Ty.visit([&](Type Ty) { - if (auto GP = dyn_cast(Ty->getCanonicalType())) { - ConstrainedGenericParams.insert(GP); + case RequirementKind::Layout: + break; } - }); -} + } -/// Perform some sanity checks for the requirements provided by -/// the @_specialize attribute. -static void checkSpecializeAttrRequirements( - SpecializeAttr *attr, - AbstractFunctionDecl *FD, - const SmallPtrSet &constrainedGenericParams, - ASTContext &ctx) { - auto genericSig = FD->getGenericSignature(); + if (hadError) + return; if (!attr->isFullSpecialization()) return; - if (constrainedGenericParams.size() == genericSig->getGenericParams().size()) + if (specializedSig->areAllParamsConcrete()) return; - ctx.Diags.diagnose( - attr->getLocation(), diag::specialize_attr_type_parameter_count_mismatch, - genericSig->getGenericParams().size(), constrainedGenericParams.size(), - constrainedGenericParams.size() < genericSig->getGenericParams().size()); + SmallVector unspecializedParams; - if (constrainedGenericParams.size() < genericSig->getGenericParams().size()) { - // Figure out which archetypes are not constrained. - for (auto gp : genericSig->getGenericParams()) { - if (constrainedGenericParams.count(gp->getCanonicalType().getPointer())) - continue; - auto gpDecl = gp->getDecl(); - if (gpDecl) { - ctx.Diags.diagnose(attr->getLocation(), - diag::specialize_attr_missing_constraint, - gpDecl->getName()); - } + for (auto *paramTy : specializedSig->getGenericParams()) { + auto canTy = paramTy->getCanonicalType(); + if (specializedSig->isCanonicalTypeInContext(canTy) && + (!specializedSig->getLayoutConstraint(canTy) || + originalSig->getLayoutConstraint(canTy))) { + unspecializedParams.push_back(paramTy); } } -} -/// Require that the given type either not involve type parameters or be -/// a type parameter. -static bool diagnoseIndirectGenericTypeParam(SourceLoc loc, Type type, - TypeRepr *typeRepr) { - if (type->hasTypeParameter() && !type->is()) { - type->getASTContext().Diags.diagnose( - loc, - diag::specialize_attr_only_generic_param_req) - .highlight(typeRepr->getSourceRange()); - return true; - } + unsigned expectedCount = specializedSig->getGenericParams().size(); + unsigned gotCount = expectedCount - unspecializedParams.size(); - return false; + if (expectedCount == gotCount) + return; + + ctx.Diags.diagnose( + attr->getLocation(), diag::specialize_attr_type_parameter_count_mismatch, + gotCount, expectedCount); + + for (auto paramTy : unspecializedParams) { + ctx.Diags.diagnose(attr->getLocation(), + diag::specialize_attr_missing_constraint, + paramTy->getName()); + } } /// Type check that a set of requirements provided by @_specialize. @@ -2183,93 +2191,9 @@ void AttributeChecker::visitSpecializeAttr(SpecializeAttr *attr) { // First, add the old generic signature. Builder.addGenericSignature(genericSig); - // Set of generic parameters being constrained. It is used to - // determine if a full specialization misses requirements for - // some of the generic parameters. - SmallPtrSet constrainedGenericParams; - // Go over the set of requirements, adding them to the builder. WhereClauseOwner(FD, attr).visitRequirements(TypeResolutionStage::Interface, [&](const Requirement &req, RequirementRepr *reqRepr) { - // Collect all of the generic parameters used by these types. - switch (req.getKind()) { - case RequirementKind::Conformance: - case RequirementKind::SameType: - case RequirementKind::Superclass: - collectUsedGenericParameters(req.getSecondType(), - constrainedGenericParams); - LLVM_FALLTHROUGH; - - case RequirementKind::Layout: - collectUsedGenericParameters(req.getFirstType(), - constrainedGenericParams); - break; - } - - // Check additional constraints. - // FIXME: These likely aren't fundamental limitations. - switch (req.getKind()) { - case RequirementKind::SameType: { - bool firstHasTypeParameter = req.getFirstType()->hasTypeParameter(); - bool secondHasTypeParameter = req.getSecondType()->hasTypeParameter(); - - // Exactly one type can have a type parameter. - if (firstHasTypeParameter == secondHasTypeParameter) { - diagnose(attr->getLocation(), - firstHasTypeParameter - ? diag::specialize_attr_non_concrete_same_type_req - : diag::specialize_attr_only_one_concrete_same_type_req) - .highlight(reqRepr->getSourceRange()); - return false; - } - - // We either need a fully-concrete type or a generic type parameter. - if (diagnoseIndirectGenericTypeParam(attr->getLocation(), - req.getFirstType(), - reqRepr->getFirstTypeRepr()) || - diagnoseIndirectGenericTypeParam(attr->getLocation(), - req.getSecondType(), - reqRepr->getSecondTypeRepr())) { - return false; - } - break; - } - - case RequirementKind::Superclass: - diagnose(attr->getLocation(), - diag::specialize_attr_non_protocol_type_constraint_req) - .highlight(reqRepr->getSourceRange()); - return false; - - case RequirementKind::Conformance: - if (diagnoseIndirectGenericTypeParam(attr->getLocation(), - req.getFirstType(), - reqRepr->getSubjectRepr())) { - return false; - } - - if (!req.getSecondType()->is()) { - diagnose(attr->getLocation(), - diag::specialize_attr_non_protocol_type_constraint_req) - .highlight(reqRepr->getSourceRange()); - return false; - } - - diagnose(attr->getLocation(), - diag::specialize_attr_unsupported_kind_of_req) - .highlight(reqRepr->getSourceRange()); - - return false; - - case RequirementKind::Layout: - if (diagnoseIndirectGenericTypeParam(attr->getLocation(), - req.getFirstType(), - reqRepr->getSubjectRepr())) { - return false; - } - break; - } - // Add the requirement to the generic signature builder. using FloatingRequirementSource = GenericSignatureBuilder::FloatingRequirementSource; @@ -2279,12 +2203,13 @@ void AttributeChecker::visitSpecializeAttr(SpecializeAttr *attr) { return false; }); - // Check the validity of provided requirements. - checkSpecializeAttrRequirements(attr, FD, constrainedGenericParams, Ctx); - // Check the result. auto specializedSig = std::move(Builder).computeGenericSignature( /*allowConcreteGenericParams=*/true); + + // Check the validity of provided requirements. + checkSpecializeAttrRequirements(attr, genericSig, specializedSig, Ctx); + attr->setSpecializedSignature(specializedSig); // Check the target function if there is one. diff --git a/lib/Sema/TypeCheckConcurrency.cpp b/lib/Sema/TypeCheckConcurrency.cpp index 54bf7de331204..21d4f2f8cc02f 100644 --- a/lib/Sema/TypeCheckConcurrency.cpp +++ b/lib/Sema/TypeCheckConcurrency.cpp @@ -442,31 +442,16 @@ VarDecl *GlobalActorInstanceRequest::evaluate( } Optional> -GlobalActorAttributeRequest::evaluate( - Evaluator &evaluator, - llvm::PointerUnion subject) const { - DeclContext *dc; - DeclAttributes *declAttrs; - SourceLoc loc; - if (auto decl = subject.dyn_cast()) { - dc = decl->getDeclContext(); - declAttrs = &decl->getAttrs(); - loc = decl->getLoc(); - } else { - auto closure = subject.get(); - dc = closure; - declAttrs = &closure->getAttrs(); - loc = closure->getLoc(); - } +swift::checkGlobalActorAttributes( + SourceLoc loc, DeclContext *dc, ArrayRef attrs) { ASTContext &ctx = dc->getASTContext(); + CustomAttr *globalActorAttr = nullptr; NominalTypeDecl *globalActorNominal = nullptr; - - for (auto attr : declAttrs->getAttributes()) { - auto mutableAttr = const_cast(attr); + for (auto attr : attrs) { // Figure out which nominal declaration this custom attribute refers to. auto nominal = evaluateOrDefault(ctx.evaluator, - CustomAttrNominalRequest{mutableAttr, dc}, + CustomAttrNominalRequest{attr, dc}, nullptr); // Ignore unresolvable custom attributes. @@ -492,14 +477,48 @@ GlobalActorAttributeRequest::evaluate( if (!globalActorAttr) return None; + return std::make_pair(globalActorAttr, globalActorNominal); +} + +Optional> +GlobalActorAttributeRequest::evaluate( + Evaluator &evaluator, + llvm::PointerUnion subject) const { + DeclContext *dc; + DeclAttributes *declAttrs; + SourceLoc loc; + if (auto decl = subject.dyn_cast()) { + dc = decl->getDeclContext(); + declAttrs = &decl->getAttrs(); + loc = decl->getLoc(); + } else { + auto closure = subject.get(); + dc = closure; + declAttrs = &closure->getAttrs(); + loc = closure->getLoc(); + } + + // Collect the attributes. + SmallVector attrs; + for (auto attr : declAttrs->getAttributes()) { + auto mutableAttr = const_cast(attr); + attrs.push_back(mutableAttr); + } + + // Look for a global actor attribute. + auto result = checkGlobalActorAttributes(loc, dc, attrs); + if (!result) + return None; + // Closures can always have a global actor attached. if (auto closure = subject.dyn_cast()) { - return std::make_pair(globalActorAttr, globalActorNominal); + return result; } // Check that a global actor attribute makes sense on this kind of // declaration. auto decl = subject.get(); + auto globalActorAttr = result->first; if (auto nominal = dyn_cast(decl)) { // Nominal types are okay... if (auto classDecl = dyn_cast(nominal)){ @@ -529,7 +548,26 @@ GlobalActorAttributeRequest::evaluate( return None; } - return std::make_pair(globalActorAttr, globalActorNominal); + return result; +} + +Type swift::getExplicitGlobalActor(ClosureExpr *closure) { + // Look at the explicit attribute. + auto globalActorAttr = evaluateOrDefault( + closure->getASTContext().evaluator, + GlobalActorAttributeRequest{closure}, None); + if (!globalActorAttr) + return Type(); + + Type globalActor = evaluateOrDefault( + closure->getASTContext().evaluator, + CustomAttrTypeRequest{ + globalActorAttr->first, closure, CustomAttrTypeKind::GlobalActor}, + Type()); + if (!globalActor || globalActor->hasError()) + return Type(); + + return globalActor; } /// Determine the isolation rules for a given declaration. @@ -892,8 +930,7 @@ static bool diagnoseNonConcurrentProperty( /// missing. static bool shouldDiagnoseNonConcurrentValueViolations( const LangOptions &langOpts) { - return langOpts.EnableExperimentalConcurrency || - langOpts.WarnConcurrency; + return langOpts.WarnConcurrency; } bool swift::diagnoseNonConcurrentTypesInReference( @@ -2158,34 +2195,16 @@ namespace { // Attempt to resolve the global actor type of a closure. Type resolveGlobalActorType(ClosureExpr *closure) { - auto globalActorAttr = evaluateOrDefault( - ctx.evaluator, GlobalActorAttributeRequest{closure}, None); - if (!globalActorAttr) - return Type(); - - Type globalActor = evaluateOrDefault( - ctx.evaluator, - CustomAttrTypeRequest{ - globalActorAttr->first, closure, CustomAttrTypeKind::GlobalActor}, - Type()); - if (!globalActor || globalActor->hasError()) - return Type(); - - // Actor-isolated closures must be async. - bool isAsync = false; + // Check whether the closure's type has a global actor already. if (Type closureType = closure->getType()) { - if (auto closureFnType = closureType->getAs()) - isAsync = closureFnType->isAsync(); - } - - if (!isAsync) { - ctx.Diags.diagnose( - closure->getLoc(), diag::global_actor_isolated_synchronous_closure, - globalActor); - return Type(); + if (auto closureFnType = closureType->getAs()) { + if (Type globalActor = closureFnType->getGlobalActor()) + return globalActor; + } } - return globalActor; + // Look for an explicit attribute. + return getExplicitGlobalActor(closure); } /// Determine the isolation of a particular closure. @@ -2794,12 +2813,15 @@ void swift::checkOverrideActorIsolation(ValueDecl *value) { overridden->diagnose(diag::overridden_here); } -static bool shouldDiagnoseExistingDataRaces(const DeclContext *dc) { - if (dc->getASTContext().LangOpts.WarnConcurrency) - return true; - +bool swift::contextUsesConcurrencyFeatures(const DeclContext *dc) { while (!dc->isModuleScopeContext()) { if (auto closure = dyn_cast(dc)) { + // A closure with an explicit global actor uses concurrency features. + if (auto explicitClosure = dyn_cast(closure)) { + if (getExplicitGlobalActor(const_cast(explicitClosure))) + return true; + } + // Async and concurrent closures use concurrency features. if (auto closureType = closure->getType()) { if (auto fnType = closureType->getAs()) @@ -2832,8 +2854,8 @@ static bool shouldDiagnoseExistingDataRaces(const DeclContext *dc) { } // If we're in an actor, we're using concurrency features. - if (auto classDecl = dc->getSelfClassDecl()) { - if (classDecl->isActor()) + if (auto nominal = dc->getSelfNominalTypeDecl()) { + if (nominal->isActor()) return true; } @@ -2844,6 +2866,13 @@ static bool shouldDiagnoseExistingDataRaces(const DeclContext *dc) { return false; } +static bool shouldDiagnoseExistingDataRaces(const DeclContext *dc) { + if (dc->getASTContext().LangOpts.WarnConcurrency) + return true; + + return contextUsesConcurrencyFeatures(dc); +} + static DiagnosticBehavior toDiagnosticBehavior(const LangOptions &langOpts, ConcurrentValueCheck check, bool diagnoseImplicit = false) { diff --git a/lib/Sema/TypeCheckConcurrency.h b/lib/Sema/TypeCheckConcurrency.h index 3b400344e763a..67331460dfe8b 100644 --- a/lib/Sema/TypeCheckConcurrency.h +++ b/lib/Sema/TypeCheckConcurrency.h @@ -28,7 +28,9 @@ class ActorIsolation; class AnyFunctionType; class ASTContext; class ClassDecl; +class ClosureExpr; class ConcreteDeclRef; +class CustomAttr; class Decl; class DeclContext; class EnumElementDecl; @@ -175,6 +177,10 @@ class ActorIsolationRestriction { /// overridden declaration. void checkOverrideActorIsolation(ValueDecl *value); +/// Determine whether the given context uses concurrency features, such +/// as async functions or actors. +bool contextUsesConcurrencyFeatures(const DeclContext *dc); + /// Diagnose the presence of any non-concurrent types when referencing a /// given declaration from a particular declaration context. /// @@ -215,6 +221,16 @@ enum class ConcurrentValueCheck { Implicit, }; +/// Given a set of custom attributes, pick out the global actor attributes +/// and perform any necessary resolution and diagnostics, returning the +/// global actor attribute and type it refers to (or \c None). +Optional> +checkGlobalActorAttributes( + SourceLoc loc, DeclContext *dc, ArrayRef attrs); + +/// Get the explicit global actor specified for a closure. +Type getExplicitGlobalActor(ClosureExpr *closure); + /// Check the correctness of the given ConcurrentValue conformance. /// /// \returns true if an error occurred. diff --git a/lib/Sema/TypeCheckDecl.cpp b/lib/Sema/TypeCheckDecl.cpp index 020aa61eb5cbe..b0d48afea7ae4 100644 --- a/lib/Sema/TypeCheckDecl.cpp +++ b/lib/Sema/TypeCheckDecl.cpp @@ -939,7 +939,7 @@ RequirementSignatureRequest::evaluate(Evaluator &evaluator, auto reqSignature = std::move(builder).computeGenericSignature( /*allowConcreteGenericParams=*/false, - /*allowBuilderToMove=*/false); + /*buildingRequirementSignature=*/true); return reqSignature->getRequirements(); } diff --git a/lib/Sema/TypeCheckType.cpp b/lib/Sema/TypeCheckType.cpp index fac7c9fa96518..9cfaff339253d 100644 --- a/lib/Sema/TypeCheckType.cpp +++ b/lib/Sema/TypeCheckType.cpp @@ -1820,7 +1820,8 @@ namespace { bool concurrent = false, const clang::Type *parsedClangFunctionType = nullptr, DifferentiabilityKind diffKind = - DifferentiabilityKind::NonDifferentiable); + DifferentiabilityKind::NonDifferentiable, + Type globalActor = Type()); SmallVector resolveASTFunctionTypeParams( TupleTypeRepr *inputRepr, TypeResolutionOptions options, bool requiresMappingOut, DifferentiabilityKind diffKind); @@ -2089,6 +2090,46 @@ TypeResolver::resolveAttributedType(TypeAttributes &attrs, TypeRepr *repr, options.is(TypeResolverContext::VariadicFunctionInput) && !options.hasBase(TypeResolverContext::EnumElementDecl); + // Resolve global actor. + CustomAttr *globalActorAttr = nullptr; + Type globalActor; + if (isa(repr)) { + auto foundGlobalActor = checkGlobalActorAttributes( + repr->getLoc(), getDeclContext(), + std::vector( + attrs.getCustomAttrs().begin(), attrs.getCustomAttrs().end())); + if (foundGlobalActor) { + globalActorAttr = foundGlobalActor->first; + globalActor = resolveType(globalActorAttr->getTypeRepr(), options); + if (globalActor->hasError()) + globalActor = Type(); + } + } + + // Diagnose custom attributes that haven't been processed yet. + for (auto customAttr : attrs.getCustomAttrs()) { + // If this was the global actor we matched, ignore it. + if (globalActorAttr == customAttr) + continue; + + // If this attribute was marked invalid, ignore it. + if (customAttr->isInvalid()) + continue; + + // Diagnose the attribute, because we don't yet handle custom type + // attributes. + std::string typeName; + if (auto typeRepr = customAttr->getTypeRepr()) { + llvm::raw_string_ostream out(typeName); + typeRepr->print(out); + } else { + typeName = customAttr->getType().getString(); + } + + diagnose(customAttr->getLocation(), diag::unknown_attribute, typeName); + customAttr->setInvalid(); + } + // The type we're working with, in case we want to build it differently // based on the attributes we see. Type ty; @@ -2204,7 +2245,7 @@ TypeResolver::resolveAttributedType(TypeAttributes &attrs, TypeRepr *repr, } } - bool hasFunctionAttr = + bool hasFunctionAttr = globalActor || llvm::any_of(FunctionAttrs, [&attrs](const TypeAttrKind &attr) { return attrs.has(attr); }); @@ -2362,7 +2403,7 @@ TypeResolver::resolveAttributedType(TypeAttributes &attrs, TypeRepr *repr, ty = resolveASTFunctionType(fnRepr, options, rep, /*noescape=*/false, concurrent, parsedClangFunctionType, - diffKind); + diffKind, globalActor); if (!ty || ty->hasError()) return ty; } @@ -2754,7 +2795,7 @@ NeverNullType TypeResolver::resolveASTFunctionType( FunctionTypeRepr *repr, TypeResolutionOptions parentOptions, AnyFunctionType::Representation representation, bool noescape, bool concurrent, const clang::Type *parsedClangFunctionType, - DifferentiabilityKind diffKind) { + DifferentiabilityKind diffKind, Type globalActor) { Optional> saveGenericParams; @@ -2807,7 +2848,7 @@ NeverNullType TypeResolver::resolveASTFunctionType( FunctionType::ExtInfoBuilder extInfoBuilder( FunctionTypeRepresentation::Swift, noescape, repr->isThrowing(), diffKind, - /*clangFunctionType*/ nullptr); + /*clangFunctionType*/ nullptr, Type()); const clang::Type *clangFnType = parsedClangFunctionType; if (shouldStoreClangType(representation) && !clangFnType) @@ -2818,6 +2859,7 @@ NeverNullType TypeResolver::resolveASTFunctionType( .withConcurrent(concurrent) .withAsync(repr->isAsync()) .withClangFunctionType(clangFnType) + .withGlobalActor(globalActor) .build(); // SIL uses polymorphic function types to resolve overloaded member functions. diff --git a/lib/Serialization/Deserialization.cpp b/lib/Serialization/Deserialization.cpp index b317385bf2ec8..231a5efa8163e 100644 --- a/lib/Serialization/Deserialization.cpp +++ b/lib/Serialization/Deserialization.cpp @@ -5099,16 +5099,17 @@ class TypeDeserializer { bool noescape = false, concurrent, async, throws; GenericSignature genericSig; TypeID clangTypeID; + TypeID globalActorTypeID; if (!isGeneric) { decls_block::FunctionTypeLayout::readRecord( scratch, resultID, rawRepresentation, clangTypeID, - noescape, concurrent, async, throws, rawDiffKind); + noescape, concurrent, async, throws, rawDiffKind, globalActorTypeID); } else { GenericSignatureID rawGenericSig; decls_block::GenericFunctionTypeLayout::readRecord( scratch, resultID, rawRepresentation, concurrent, async, throws, - rawDiffKind, rawGenericSig); + rawDiffKind, globalActorTypeID, rawGenericSig); genericSig = MF.getGenericSignature(rawGenericSig); clangTypeID = 0; } @@ -5129,8 +5130,18 @@ class TypeDeserializer { clangFunctionType = loadedClangType.get(); } + Type globalActor; + if (globalActorTypeID) { + auto globalActorTy = MF.getTypeChecked(globalActorTypeID); + if (!globalActorTy) + return globalActorTy.takeError(); + + globalActor = globalActorTy.get(); + } + auto info = FunctionType::ExtInfoBuilder(*representation, noescape, throws, - *diffKind, clangFunctionType) + *diffKind, clangFunctionType, + globalActor) .withConcurrent(concurrent) .withAsync(async) .build(); diff --git a/lib/Serialization/ModuleFormat.h b/lib/Serialization/ModuleFormat.h index ac8b10beafad0..ee8431742f4d4 100644 --- a/lib/Serialization/ModuleFormat.h +++ b/lib/Serialization/ModuleFormat.h @@ -56,7 +56,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0; /// describe what change you made. The content of this comment isn't important; /// it just ensures a conflict if two people change the module format. /// Don't worry about adhering to the 80-column limit for this line. -const uint16_t SWIFTMODULE_VERSION_MINOR = 604; // completionHandlerAsync +const uint16_t SWIFTMODULE_VERSION_MINOR = 605; // global actor function /// A standard hash seed used for all string hashes in a serialized module. /// @@ -999,8 +999,8 @@ namespace decls_block { BCFixed<1>, // concurrent? BCFixed<1>, // async? BCFixed<1>, // throws? - DifferentiabilityKindField // differentiability kind - + DifferentiabilityKindField, // differentiability kind + TypeIDField // global actor // trailed by parameters >; @@ -1077,6 +1077,7 @@ namespace decls_block { BCFixed<1>, // async? BCFixed<1>, // throws? DifferentiabilityKindField, // differentiability kind + TypeIDField, // global actor GenericSignatureIDField // generic signture // trailed by parameters diff --git a/lib/Serialization/Serialization.cpp b/lib/Serialization/Serialization.cpp index c34bc684719ed..646d7529bee56 100644 --- a/lib/Serialization/Serialization.cpp +++ b/lib/Serialization/Serialization.cpp @@ -4358,6 +4358,7 @@ class Serializer::TypeSerializer : public TypeVisitor { S.getASTContext().LangOpts.UseClangFunctionTypes ? S.addClangTypeRef(fnTy->getClangTypeInfo().getType()) : ClangTypeID(0); + auto globalActor = S.addTypeRef(fnTy->getGlobalActor()); unsigned abbrCode = S.DeclTypeAbbrCodes[FunctionTypeLayout::Code]; FunctionTypeLayout::emitRecord(S.Out, S.ScratchRecord, abbrCode, @@ -4368,7 +4369,8 @@ class Serializer::TypeSerializer : public TypeVisitor { fnTy->isConcurrent(), fnTy->isAsync(), fnTy->isThrowing(), - getRawStableDifferentiabilityKind(fnTy->getDifferentiabilityKind())); + getRawStableDifferentiabilityKind(fnTy->getDifferentiabilityKind()), + globalActor); serializeFunctionTypeParams(fnTy); } @@ -4383,6 +4385,7 @@ class Serializer::TypeSerializer : public TypeVisitor { getRawStableFunctionTypeRepresentation(fnTy->getRepresentation()), fnTy->isConcurrent(), fnTy->isAsync(), fnTy->isThrowing(), getRawStableDifferentiabilityKind(fnTy->getDifferentiabilityKind()), + S.addTypeRef(fnTy->getGlobalActor()), S.addGenericSignatureRef(genericSig)); serializeFunctionTypeParams(fnTy); diff --git a/lib/SymbolGraphGen/Symbol.cpp b/lib/SymbolGraphGen/Symbol.cpp index 7814920c738a1..084ba38a66442 100644 --- a/lib/SymbolGraphGen/Symbol.cpp +++ b/lib/SymbolGraphGen/Symbol.cpp @@ -120,7 +120,7 @@ void Symbol::serializeNames(llvm::json::OStream &OS) const { SmallVector PathComponents; getPathComponents(PathComponents); - if (isa(VD)) { + if (isa(VD) || isa(VD)) { SmallString<64> FullyQualifiedTitle; for (const auto *It = PathComponents.begin(); It != PathComponents.end(); ++It) { diff --git a/lib/SymbolGraphGen/SymbolGraphASTWalker.cpp b/lib/SymbolGraphGen/SymbolGraphASTWalker.cpp index 70454652d9c0a..5b868eb2e9218 100644 --- a/lib/SymbolGraphGen/SymbolGraphASTWalker.cpp +++ b/lib/SymbolGraphGen/SymbolGraphASTWalker.cpp @@ -64,12 +64,14 @@ namespace { bool isUnavailableOrObsoleted(const Decl *D) { if (const auto *Avail = D->getAttrs().getUnavailable(D->getASTContext())) { - switch (Avail->getVersionAvailability(D->getASTContext())) { - case AvailableVersionComparison::Unavailable: - case AvailableVersionComparison::Obsoleted: - return true; - default: - break; + if (Avail->Platform != PlatformKind::none) { + switch (Avail->getVersionAvailability(D->getASTContext())) { + case AvailableVersionComparison::Unavailable: + case AvailableVersionComparison::Obsoleted: + return true; + default: + break; + } } } return false; diff --git a/lib/SyntaxParse/SyntaxTreeCreator.cpp b/lib/SyntaxParse/SyntaxTreeCreator.cpp index d46cf59ff8416..dd3b8cee8ee32 100644 --- a/lib/SyntaxParse/SyntaxTreeCreator.cpp +++ b/lib/SyntaxParse/SyntaxTreeCreator.cpp @@ -11,17 +11,18 @@ //===----------------------------------------------------------------------===// #include "swift/SyntaxParse/SyntaxTreeCreator.h" -#include "swift/Syntax/RawSyntax.h" -#include "swift/Syntax/SyntaxVisitor.h" -#include "swift/Syntax/Trivia.h" -#include "swift/Parse/ParsedTrivia.h" -#include "swift/Parse/SyntaxParsingCache.h" -#include "swift/Parse/Token.h" #include "swift/AST/ASTContext.h" #include "swift/AST/DiagnosticsParse.h" #include "swift/AST/Module.h" #include "swift/AST/SourceFile.h" #include "swift/Basic/OwnedString.h" +#include "swift/Parse/ParsedRawSyntaxNode.h" +#include "swift/Parse/ParsedTrivia.h" +#include "swift/Parse/SyntaxParsingCache.h" +#include "swift/Parse/Token.h" +#include "swift/Syntax/RawSyntax.h" +#include "swift/Syntax/SyntaxVisitor.h" +#include "swift/Syntax/Trivia.h" using namespace swift; using namespace swift::syntax; @@ -35,8 +36,10 @@ SyntaxTreeCreator::SyntaxTreeCreator(SourceManager &SM, unsigned bufferID, const char *Data = BufferContent.data(); Arena->copyStringToArenaIfNecessary(Data, BufferContent.size()); ArenaSourceBuffer = StringRef(Data, BufferContent.size()); - Arena->setHotUseMemoryRegion(ArenaSourceBuffer.begin(), - ArenaSourceBuffer.end()); + if (!ArenaSourceBuffer.empty()) { + Arena->setHotUseMemoryRegion(ArenaSourceBuffer.begin(), + ArenaSourceBuffer.end()); + } } SyntaxTreeCreator::~SyntaxTreeCreator() = default; @@ -187,17 +190,25 @@ OpaqueSyntaxNode SyntaxTreeCreator::makeDeferredToken(tok tokenKind, } OpaqueSyntaxNode SyntaxTreeCreator::makeDeferredLayout( - syntax::SyntaxKind k, bool IsMissing, - const ArrayRef &children) { - SmallVector opaqueChildren; - opaqueChildren.reserve(children.size()); + syntax::SyntaxKind kind, bool IsMissing, + const MutableArrayRef &parsedChildren) { + assert(!IsMissing && "Missing layout nodes not implemented yet"); - for (size_t i = 0; i < children.size(); ++i) { - opaqueChildren.push_back(children[i].getOpaque()); + SmallVector children; + children.reserve(parsedChildren.size()); + + size_t TextLength = 0; + for (size_t i = 0; i < parsedChildren.size(); ++i) { + auto Raw = static_cast(parsedChildren[i].takeData()); + if (Raw) { + TextLength += Raw->getTextLength(); + } + children.push_back(Raw); } - // Also see comment in makeDeferredToken - return recordRawSyntax(k, opaqueChildren); + auto raw = RawSyntax::make(kind, children, TextLength, + SourcePresence::Present, Arena); + return static_cast(raw); } OpaqueSyntaxNode diff --git a/stdlib/public/Concurrency/Actor.cpp b/stdlib/public/Concurrency/Actor.cpp index 634d708cbbaa1..a431da98e6a30 100644 --- a/stdlib/public/Concurrency/Actor.cpp +++ b/stdlib/public/Concurrency/Actor.cpp @@ -110,6 +110,12 @@ class ExecutorTrackingInfo { return ActiveExecutor; } + static ExecutorRef getActiveExecutorInThread() { + if (auto activeInfo = ActiveInfoInThread.get()) + return activeInfo->getActiveExecutor(); + return ExecutorRef::generic(); + } + void leave() { ActiveInfoInThread.set(SavedInfo); } @@ -139,12 +145,14 @@ void swift::swift_job_run(Job *job, ExecutorRef executor) { ExecutorTrackingInfo trackingInfo; trackingInfo.enterAndShadow(executor); - runJobInExecutorContext(job, executor); + runJobInEstablishedExecutorContext(job); trackingInfo.leave(); } -void swift::runJobInExecutorContext(Job *job, ExecutorRef executor) { +void swift::runJobInEstablishedExecutorContext(Job *job) { + _swift_tsan_acquire(job); + if (auto task = dyn_cast(job)) { // Update the active task in the current thread. ActiveTask::set(task); @@ -154,24 +162,33 @@ void swift::runJobInExecutorContext(Job *job, ExecutorRef executor) { // on an actor, it should update the task status appropriately; // we don't need to update it afterwards. - task->runInFullyEstablishedContext(executor); + task->runInFullyEstablishedContext(); // Clear the active task. ActiveTask::set(nullptr); } else { // There's no extra bookkeeping to do for simple jobs. - job->runSimpleInFullyEstablishedContext(executor); + job->runSimpleInFullyEstablishedContext(); } + + _swift_tsan_release(job); } AsyncTask *swift::swift_task_getCurrent() { return ActiveTask::get(); } -void swift::_swift_task_clearCurrent() { +AsyncTask *swift::_swift_task_clearCurrent() { + auto task = ActiveTask::get(); ActiveTask::set(nullptr); + return task; +} + +ExecutorRef swift::swift_task_getCurrentExecutor() { + return ExecutorTrackingInfo::getActiveExecutorInThread(); } + /*****************************************************************************/ /*********************** DEFAULT ACTOR IMPLEMENTATION ************************/ /*****************************************************************************/ @@ -187,7 +204,7 @@ class ProcessInlineJob : public Job { : Job({JobKind::DefaultActorInline, priority}, &process) {} SWIFT_CC(swiftasync) - static void process(Job *job, ExecutorRef executor); + static void process(Job *job); static bool classof(const Job *job) { return job->Flags.getKind() == JobKind::DefaultActorInline; @@ -204,7 +221,7 @@ class ProcessOutOfLineJob : public Job { Actor(actor) {} SWIFT_CC(swiftasync) - static void process(Job *job, ExecutorRef executor); + static void process(Job *job); static bool classof(const Job *job) { return job->Flags.getKind() == JobKind::DefaultActorSeparate; @@ -660,7 +677,7 @@ class ProcessOverrideJob : public Job { } SWIFT_CC(swiftasync) - static void process(Job *job, ExecutorRef _executor); + static void process(Job *job); static bool classof(const Job *job) { return job->Flags.getKind() == JobKind::DefaultActorOverride; @@ -1129,8 +1146,7 @@ static void processDefaultActor(DefaultActorImpl *currentActor, } // Run the job. - auto executor = ExecutorRef::forDefaultActor(asAbstract(currentActor)); - runJobInExecutorContext(job, executor); + runJobInEstablishedExecutorContext(job); // The current actor may have changed after the job. // If it's become nil, or not a default actor, we have nothing to do. @@ -1153,7 +1169,7 @@ static void processDefaultActor(DefaultActorImpl *currentActor, swift_release(actor); } -void ProcessInlineJob::process(Job *job, ExecutorRef _executor) { +void ProcessInlineJob::process(Job *job) { DefaultActorImpl *actor = DefaultActorImpl::fromInlineJob(job); // Pull the priority out of the job before we do anything that might @@ -1166,7 +1182,7 @@ void ProcessInlineJob::process(Job *job, ExecutorRef _executor) { return processDefaultActor(actor, runner); } -void ProcessOutOfLineJob::process(Job *job, ExecutorRef _executor) { +void ProcessOutOfLineJob::process(Job *job) { auto self = cast(job); DefaultActorImpl *actor = self->Actor; @@ -1182,7 +1198,7 @@ void ProcessOutOfLineJob::process(Job *job, ExecutorRef _executor) { return processDefaultActor(actor, runner); } -void ProcessOverrideJob::process(Job *job, ExecutorRef _executor) { +void ProcessOverrideJob::process(Job *job) { auto self = cast(job); // Pull the actor and priority out of the job. @@ -1378,11 +1394,11 @@ static void runOnAssumedThread(AsyncTask *task, ExecutorRef executor, // want these frames to potentially accumulate linearly. if (activeTrackingInfo != &trackingInfo) { // FIXME: force tail call - return task->runInFullyEstablishedContext(executor); + return task->runInFullyEstablishedContext(); } // Otherwise, run the new task. - task->runInFullyEstablishedContext(executor); + task->runInFullyEstablishedContext(); // Leave the tracking frame, and give up the current actor if // we have one. @@ -1398,17 +1414,27 @@ static void runOnAssumedThread(AsyncTask *task, ExecutorRef executor, } SWIFT_CC(swiftasync) -void swift::swift_task_switch(AsyncTask *task, ExecutorRef currentExecutor, +void swift::swift_task_switch(SWIFT_ASYNC_CONTEXT AsyncContext *resumeContext, + TaskContinuationFunction *resumeFunction, ExecutorRef newExecutor) { - assert(task && "no task provided"); + auto currentExecutor = ExecutorTrackingInfo::getActiveExecutorInThread(); // If the current executor is compatible with running the new executor, - // just continue running. + // we can just immediately continue running with the resume function + // we were passed in. if (!currentExecutor.mustSwitchToRun(newExecutor)) { // FIXME: force tail call - return task->runInFullyEstablishedContext(currentExecutor); + return resumeFunction(resumeContext); } + auto task = swift_task_getCurrent(); + assert(task && "no current task!"); + + // Park the task for simplicity instead of trying to thread the + // initial resumption information into everything below. + task->ResumeContext = resumeContext; + task->ResumeTask = resumeFunction; + // Okay, we semantically need to switch. auto runner = RunningJobInfo::forOther(task->getPriority()); @@ -1435,6 +1461,8 @@ void swift::swift_task_switch(AsyncTask *task, ExecutorRef currentExecutor, void swift::swift_task_enqueue(Job *job, ExecutorRef executor) { assert(job && "no job provided"); + _swift_tsan_release(job); + if (executor.isGeneric()) return swift_task_enqueueGlobal(job); diff --git a/stdlib/public/Concurrency/AsyncCall.h b/stdlib/public/Concurrency/AsyncCall.h index 84056ab0d120d..7a4ab0bc9d4c3 100644 --- a/stdlib/public/Concurrency/AsyncCall.h +++ b/stdlib/public/Concurrency/AsyncCall.h @@ -104,11 +104,10 @@ struct AsyncFrameStorage( - flags, resumeFunction, resumeToExecutor, resumeToContext) { + flags, resumeFunction, resumeToContext) { initializeHelper(this->data(), args...); } @@ -135,11 +134,10 @@ struct AsyncCalleeContext : AsyncFrameStorage { template AsyncCalleeContext(TaskContinuationFunction *resumeFunction, - ExecutorRef resumeToExecutor, CallerContext *resumeToContext, Args... args) : AsyncFrameStorage(AsyncContextKind::Ordinary, - resumeFunction, resumeToExecutor, + resumeFunction, resumeToContext, args...) {} CallerContext *getParent() const { @@ -150,33 +148,30 @@ struct AsyncCalleeContext : AsyncFrameStorage { /// Push a context to call a function. template static AsyncCalleeContext * -pushAsyncContext(AsyncTask *task, ExecutorRef executor, - CallerContext *callerContext, size_t calleeContextSize, +pushAsyncContext(CallerContext *callerContext, size_t calleeContextSize, TaskContinuationFunction *resumeFunction, Args... args) { using CalleeContext = AsyncCalleeContext; assert(calleeContextSize >= sizeof(CalleeContext)); - void *rawCalleeContext = swift_task_alloc(task, calleeContextSize); - return new (rawCalleeContext) CalleeContext(resumeFunction, executor, + void *rawCalleeContext = swift_task_alloc(calleeContextSize); + return new (rawCalleeContext) CalleeContext(resumeFunction, callerContext, args...); } /// Make an asynchronous call. template SWIFT_CC(swiftasync) -static void callAsync(AsyncTask *task, - ExecutorRef executor, - CallerContext *callerContext, +static void callAsync(CallerContext *callerContext, TaskContinuationFunction *resumeFunction, const typename CalleeSignature::FunctionPointer *function, Args... args) { auto calleeContextSize = function->ExpectedContextSize; - auto calleeContext = pushAsyncContext(task, executor, callerContext, + auto calleeContext = pushAsyncContext(callerContext, calleeContextSize, resumeFunction, args...); - return function->Function(task, executor, calleeContext); + return function->Function(calleeContext); } /// Given that that we've just entered the caller's continuation function @@ -184,9 +179,9 @@ static void callAsync(AsyncTask *task, /// callee's context and return the caller's context. template static typename CalleeContext::CallerContext * -popAsyncContext(AsyncTask *task, CalleeContext *calleeContext) { +popAsyncContext(CalleeContext *calleeContext) { auto callerContext = calleeContext->getParent(); - swift_task_dealloc(task, calleeContext); + swift_task_dealloc(calleeContext); return callerContext; } diff --git a/stdlib/public/Concurrency/CMakeLists.txt b/stdlib/public/Concurrency/CMakeLists.txt index 060de9c0c50e9..c76ca5cc58e1a 100644 --- a/stdlib/public/Concurrency/CMakeLists.txt +++ b/stdlib/public/Concurrency/CMakeLists.txt @@ -65,6 +65,7 @@ add_swift_target_library(swift_Concurrency ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} I TaskGroup.swift TaskLocal.cpp TaskLocal.swift + ThreadSanitizer.cpp Mutex.cpp ${swift_concurrency_objc_sources} diff --git a/stdlib/public/Concurrency/Task.cpp b/stdlib/public/Concurrency/Task.cpp index a25497916dc68..cf7b9877e04f5 100644 --- a/stdlib/public/Concurrency/Task.cpp +++ b/stdlib/public/Concurrency/Task.cpp @@ -66,10 +66,12 @@ FutureFragment::Status AsyncTask::waitFuture(AsyncTask *waitingTask) { switch (queueHead.getStatus()) { case Status::Error: case Status::Success: + _swift_tsan_acquire(static_cast(this)); // The task is done; we don't need to wait. return queueHead.getStatus(); case Status::Executing: + _swift_tsan_release(static_cast(waitingTask)); // Task is now complete. We'll need to add ourselves to the queue. break; } @@ -89,7 +91,7 @@ FutureFragment::Status AsyncTask::waitFuture(AsyncTask *waitingTask) { } } -void AsyncTask::completeFuture(AsyncContext *context, ExecutorRef executor) { +void AsyncTask::completeFuture(AsyncContext *context) { using Status = FutureFragment::Status; using WaitQueueItem = FutureFragment::WaitQueueItem; @@ -97,13 +99,18 @@ void AsyncTask::completeFuture(AsyncContext *context, ExecutorRef executor) { auto fragment = futureFragment(); // If an error was thrown, save it in the future fragment. - auto futureContext = static_cast(context); + auto asyncContextPrefix = reinterpret_cast( + reinterpret_cast(context) - sizeof(FutureAsyncContextPrefix)); bool hadErrorResult = false; - if (auto errorObject = *futureContext->errorResult) { - fragment->getError() = errorObject; + auto errorObject = asyncContextPrefix->errorResult; + printf("asyncTask::completeFuture errorObject: %p\n", errorObject); + fragment->getError() = errorObject; + if (errorObject) { hadErrorResult = true; } + _swift_tsan_release(static_cast(this)); + // Update the status to signal completion. auto newQueueHead = WaitQueueItem::get( hadErrorResult ? Status::Error : Status::Success, @@ -118,7 +125,7 @@ void AsyncTask::completeFuture(AsyncContext *context, ExecutorRef executor) { // then we must offer into the parent group that we completed, // so it may `next()` poll completed child tasks in completion order. auto group = groupChildFragment()->getGroup(); - group->offer(this, context, executor); + group->offer(this, context); } // Schedule every waiting task on the executor. @@ -137,6 +144,8 @@ void AsyncTask::completeFuture(AsyncContext *context, ExecutorRef executor) { waitingContext->fillWithSuccess(fragment); } + _swift_tsan_acquire(static_cast(waitingTask)); + // Enqueue the waiter on the global executor. // TODO: allow waiters to fill in a suggested executor swift_task_enqueueGlobal(waitingTask); @@ -213,10 +222,16 @@ const void *const swift::_swift_concurrency_debug_asyncTaskMetadata = /// The function that we put in the context of a simple task /// to handle the final return. SWIFT_CC(swiftasync) -static void completeTask(AsyncTask *task, ExecutorRef executor, - SWIFT_ASYNC_CONTEXT AsyncContext *context) { +static void completeTask(SWIFT_ASYNC_CONTEXT AsyncContext *context, + SWIFT_CONTEXT SwiftError *error) { // Set that there's no longer a running task in the current thread. - _swift_task_clearCurrent(); + auto task = _swift_task_clearCurrent(); + assert(task && "completing task, but there is no active task registered"); + + // Store the error result. + auto asyncContextPrefix = reinterpret_cast( + reinterpret_cast(context) - sizeof(AsyncContextPrefix)); + asyncContextPrefix->errorResult = error; // Destroy and deallocate any remaining task local items. // We need to do this before we destroy the task local deallocator. @@ -228,7 +243,7 @@ static void completeTask(AsyncTask *task, ExecutorRef executor, // Complete the future. if (task->isFuture()) { - task->completeFuture(context, executor); + task->completeFuture(context); } // TODO: set something in the status? @@ -243,19 +258,45 @@ static void completeTask(AsyncTask *task, ExecutorRef executor, /// The function that we put in the context of a simple task /// to handle the final return from a closure. SWIFT_CC(swiftasync) -static void completeTaskWithClosure(AsyncTask *task, ExecutorRef executor, - SWIFT_ASYNC_CONTEXT AsyncContext *context) { +static void completeTaskWithClosure(SWIFT_ASYNC_CONTEXT AsyncContext *context, + SWIFT_CONTEXT SwiftError *error) { // Release the closure context. - auto contextWithClosure = static_cast(context); - swift_release(contextWithClosure->closureContext); + auto asyncContextPrefix = reinterpret_cast( + reinterpret_cast(context) - sizeof(AsyncContextPrefix)); + + swift_release(asyncContextPrefix->closureContext); // Clean up the rest of the task. - return completeTask(task, executor, context); + return completeTask(context, error); +} + +SWIFT_CC(swiftasync) +static void non_future_adapter(SWIFT_ASYNC_CONTEXT AsyncContext *_context) { + auto asyncContextPrefix = reinterpret_cast( + reinterpret_cast(_context) - sizeof(AsyncContextPrefix)); + return asyncContextPrefix->asyncEntryPoint( + _context, asyncContextPrefix->closureContext); +} + +SWIFT_CC(swiftasync) +static void future_adapter(SWIFT_ASYNC_CONTEXT AsyncContext *_context) { + auto asyncContextPrefix = reinterpret_cast( + reinterpret_cast(_context) - sizeof(FutureAsyncContextPrefix)); + return asyncContextPrefix->asyncEntryPoint( + asyncContextPrefix->indirectResult, _context, + asyncContextPrefix->closureContext); +} + +SWIFT_CC(swiftasync) +static void task_wait_throwing_resume_adapter(SWIFT_ASYNC_CONTEXT AsyncContext *_context) { + + auto context = static_cast(_context); + return context->asyncResumeEntryPoint(_context, context->errorResult); } /// All `swift_task_create*` variants funnel into this common implementation. static AsyncTaskAndContext swift_task_create_group_future_impl( - JobFlags flags, AsyncTask *parent, TaskGroup *group, + JobFlags flags, TaskGroup *group, const Metadata *futureResultType, FutureAsyncSignature::FunctionType *function, HeapObject * /* +1 */ closureContext, @@ -263,9 +304,14 @@ static AsyncTaskAndContext swift_task_create_group_future_impl( assert((futureResultType != nullptr) == flags.task_isFuture()); assert(!flags.task_isFuture() || initialContextSize >= sizeof(FutureAsyncContext)); - assert((parent != nullptr) == flags.task_isChildTask()); assert((group != nullptr) == flags.task_isGroupChildTask()); + AsyncTask *parent = nullptr; + if (flags.task_isChildTask()) { + parent = swift_task_getCurrent(); + assert(parent != nullptr && "creating a child task with no active task"); + } + // Figure out the size of the header. size_t headerSize = sizeof(AsyncTask); @@ -279,6 +325,11 @@ static AsyncTaskAndContext swift_task_create_group_future_impl( if (futureResultType) { headerSize += FutureFragment::fragmentSize(futureResultType); + // Add the future async context prefix. + headerSize += sizeof(FutureAsyncContextPrefix); + } else { + // Add the async context prefix. + headerSize += sizeof(AsyncContextPrefix); } headerSize = llvm::alignTo(headerSize, llvm::Align(alignof(AsyncContext))); @@ -295,6 +346,34 @@ static AsyncTaskAndContext swift_task_create_group_future_impl( reinterpret_cast( reinterpret_cast(allocation) + headerSize); + // We can't just use `function` because it uses the new async function entry + // ABI -- passing parameters, closure context, indirect result addresses + // directly -- but AsyncTask->ResumeTask expects the signature to be + // `void (*, *, swiftasync *)`. + // Instead we use an adapter. This adaptor should use the storage prefixed to + // the async context to get at the parameters. + // See e.g. FutureAsyncContextPrefix. + + if (!futureResultType) { + auto asyncContextPrefix = reinterpret_cast( + reinterpret_cast(allocation) + headerSize - + sizeof(AsyncContextPrefix)); + asyncContextPrefix->asyncEntryPoint = + reinterpret_cast(function); + asyncContextPrefix->closureContext = closureContext; + function = non_future_adapter; + assert(sizeof(AsyncContextPrefix) == 3 * sizeof(void *)); + } else { + auto asyncContextPrefix = reinterpret_cast( + reinterpret_cast(allocation) + headerSize - + sizeof(FutureAsyncContextPrefix)); + asyncContextPrefix->asyncEntryPoint = + reinterpret_cast(function); + function = future_adapter; + asyncContextPrefix->closureContext = closureContext; + assert(sizeof(FutureAsyncContextPrefix) == 4 * sizeof(void *)); + } + // Initialize the task so that resuming it will run the given // function on the initial context. AsyncTask *task = @@ -322,25 +401,13 @@ static AsyncTaskAndContext swift_task_create_group_future_impl( // Set up the context for the future so there is no error, and a successful // result will be written into the future fragment's storage. auto futureContext = static_cast(initialContext); - futureContext->errorResult = &futureFragment->getError(); - futureContext->indirectResult = futureFragment->getStoragePtr(); + auto futureAsyncContextPrefix = + reinterpret_cast( + reinterpret_cast(allocation) + headerSize - + sizeof(FutureAsyncContextPrefix)); + futureAsyncContextPrefix->indirectResult = futureFragment->getStoragePtr(); } - // Stash the closure context in the future if there's room. - // We do this unconditionally because a null context value could still in - // theory be an expected context value (for instance, a captured boolean - // value could be represented as either nullptr or (void*)-1 on platforms - // where swift_retain ignores negative values). If the given entry point - // is not a closure invocation function, then stashing null into the context - // should be harmless, since it's just unused junk space at this point. - if (initialContextSize >= sizeof(FutureClosureAsyncContext)) { - auto futureClosureContext - = static_cast(initialContext); - - futureClosureContext->closureContext = closureContext; - } else { - assert(!closureContext && "got a context but nowhere to put it?!"); - } // Perform additional linking between parent and child task. if (parent) { @@ -360,8 +427,8 @@ static AsyncTaskAndContext swift_task_create_group_future_impl( // as if they might be null, even though the only time they ever might // be is the final hop. Store a signed null instead. initialContext->Parent = nullptr; - initialContext->ResumeParent - = closureContext ? &completeTaskWithClosure : &completeTask; + initialContext->ResumeParent = reinterpret_cast( + closureContext ? &completeTaskWithClosure : &completeTask); initialContext->ResumeParentExecutor = ExecutorRef::generic(); initialContext->Flags = AsyncContextKind::Ordinary; initialContext->Flags.setShouldNotDeallocateInCallee(true); @@ -381,75 +448,53 @@ static AsyncTaskAndContext swift_task_create_group_future_impl( } AsyncTaskAndContext -swift::swift_task_create_f(JobFlags flags, AsyncTask *parent, +swift::swift_task_create_f(JobFlags flags, ThinNullaryAsyncSignature::FunctionType *function, size_t initialContextSize) { return swift_task_create_future_f( - flags, parent, nullptr, function, initialContextSize); + flags, nullptr, function, initialContextSize); } AsyncTaskAndContext swift::swift_task_create_future_f( - JobFlags flags, AsyncTask *parent, + JobFlags flags, const Metadata *futureResultType, FutureAsyncSignature::FunctionType *function, size_t initialContextSize) { assert(!flags.task_isGroupChildTask() && "use swift_task_create_group_future_f to initialize task group child tasks"); return swift_task_create_group_future_f( - flags, parent, /*group=*/nullptr, futureResultType, + flags, /*group=*/nullptr, futureResultType, function, initialContextSize); } AsyncTaskAndContext swift::swift_task_create_group_future_f( - JobFlags flags, AsyncTask *parent, TaskGroup *group, + JobFlags flags, TaskGroup *group, const Metadata *futureResultType, FutureAsyncSignature::FunctionType *function, size_t initialContextSize) { - return swift_task_create_group_future_impl(flags, parent, group, + return swift_task_create_group_future_impl(flags, group, futureResultType, function, nullptr, initialContextSize); } -namespace { -/// The header of a function context (closure captures) of -/// a thick async function with a non-null context. -struct ThickAsyncFunctionContext: HeapObject { - uint32_t ExpectedContextSize; -}; - /// Extract the entry point address and initial context size from an async closure value. template SWIFT_ALWAYS_INLINE // so this doesn't hang out as a ptrauth gadget std::pair getAsyncClosureEntryPointAndContextSize(void *function, HeapObject *functionContext) { - // If the function context is non-null, then the function pointer is - // an ordinary function pointer. - if (functionContext) { - function = swift_auth_code(function, AuthDiscriminator); - size_t contextSize = - static_cast(functionContext) - ->ExpectedContextSize; - return {reinterpret_cast(function), - contextSize}; - // Otherwise, the function pointer is an async function pointer. - } else { - auto fnPtr = + auto fnPtr = reinterpret_cast *>(function); #if SWIFT_PTRAUTH - fnPtr = (const AsyncFunctionPointer *)ptrauth_auth_data( - (void *)fnPtr, ptrauth_key_process_independent_code, - AuthDiscriminator); + fnPtr = (const AsyncFunctionPointer *)ptrauth_auth_data( + (void *)fnPtr, ptrauth_key_process_independent_code, AuthDiscriminator); #endif - return { - reinterpret_cast(fnPtr->Function.get()), - fnPtr->ExpectedContextSize}; - } -} + return {reinterpret_cast( + fnPtr->Function.get()), + fnPtr->ExpectedContextSize}; } AsyncTaskAndContext swift::swift_task_create_future(JobFlags flags, - AsyncTask *parent, const Metadata *futureResultType, void *closureEntry, HeapObject * /* +1 */ closureContext) { @@ -462,14 +507,14 @@ AsyncTaskAndContext swift::swift_task_create_future(JobFlags flags, >(closureEntry, closureContext); return swift_task_create_group_future_impl( - flags, parent, nullptr, futureResultType, + flags, nullptr, futureResultType, taskEntry, closureContext, initialContextSize); } AsyncTaskAndContext swift::swift_task_create_group_future( - JobFlags flags, AsyncTask *parent, TaskGroup *group, + JobFlags flags, TaskGroup *group, const Metadata *futureResultType, void *closureEntry, HeapObject * /*+1*/closureContext) { @@ -481,23 +526,30 @@ swift::swift_task_create_group_future( SpecialPointerAuthDiscriminators::AsyncFutureFunction >(closureEntry, closureContext); return swift_task_create_group_future_impl( - flags, parent, group, futureResultType, + flags, group, futureResultType, taskEntry, closureContext, initialContextSize); } -void swift::swift_task_future_wait( - AsyncTask *waitingTask, ExecutorRef executor, - SWIFT_ASYNC_CONTEXT AsyncContext *rawContext) { +SWIFT_CC(swiftasync) +void swift::swift_task_future_wait(OpaqueValue *result, + SWIFT_ASYNC_CONTEXT AsyncContext *rawContext, + AsyncTask *task, Metadata *T) { // Suspend the waiting task. + auto waitingTask = swift_task_getCurrent(); waitingTask->ResumeTask = rawContext->ResumeParent; waitingTask->ResumeContext = rawContext; + // Stash the result pointer for when we resume later. auto context = static_cast(rawContext); - auto task = context->task; + context->asyncResumeEntryPoint = nullptr; + context->successResultPointer = result; + context->errorResult = nullptr; + // Wait on the future. assert(task->isFuture()); + switch (task->waitFuture(waitingTask)) { case FutureFragment::Status::Executing: // The waiting task has been queued on the future. @@ -507,25 +559,34 @@ void swift::swift_task_future_wait( // Run the task with a successful result. context->fillWithSuccess(task->futureFragment()); // FIXME: force tail call - return waitingTask->runInFullyEstablishedContext(executor); + return waitingTask->runInFullyEstablishedContext(); case FutureFragment::Status::Error: fatalError(0, "future reported an error, but wait cannot throw"); } } -void swift::swift_task_future_wait_throwing( - AsyncTask *waitingTask, ExecutorRef executor, - SWIFT_ASYNC_CONTEXT AsyncContext *rawContext) { +SWIFT_CC(swiftasync) +void swift::swift_task_future_wait_throwing(OpaqueValue *result, + SWIFT_ASYNC_CONTEXT AsyncContext *rawContext, AsyncTask *task, + Metadata *T) { + auto waitingTask = swift_task_getCurrent(); // Suspend the waiting task. - waitingTask->ResumeTask = rawContext->ResumeParent; + auto originalResumeParent = + reinterpret_cast( + rawContext->ResumeParent); + waitingTask->ResumeTask = task_wait_throwing_resume_adapter; waitingTask->ResumeContext = rawContext; + // Stash the result pointer for when we resume later. auto context = static_cast(rawContext); - auto task = context->task; + context->successResultPointer = result; + context->asyncResumeEntryPoint = originalResumeParent; + context->errorResult = nullptr; // Wait on the future. assert(task->isFuture()); + switch (task->waitFuture(waitingTask)) { case FutureFragment::Status::Executing: // The waiting task has been queued on the future. @@ -535,13 +596,13 @@ void swift::swift_task_future_wait_throwing( // Run the task with a successful result. context->fillWithSuccess(task->futureFragment()); // FIXME: force tail call - return waitingTask->runInFullyEstablishedContext(executor); + return waitingTask->runInFullyEstablishedContext(); case FutureFragment::Status::Error: // Run the task with an error result. context->fillWithError(task->futureFragment()); // FIXME: force tail call - return waitingTask->runInFullyEstablishedContext(executor); + return waitingTask->runInFullyEstablishedContext(); } } @@ -602,37 +663,39 @@ using RunAndBlockCalleeContext = /// Second half of the runAndBlock async function. SWIFT_CC(swiftasync) -static void runAndBlock_finish(AsyncTask *task, ExecutorRef executor, - SWIFT_ASYNC_CONTEXT AsyncContext *_context) { +static void runAndBlock_finish(SWIFT_ASYNC_CONTEXT AsyncContext *_context) { auto calleeContext = static_cast(_context); - auto context = popAsyncContext(task, calleeContext); + + auto context = popAsyncContext(calleeContext); context->Semaphore->signal(); - return context->ResumeParent(task, executor, context); + return context->ResumeParent(context); } /// First half of the runAndBlock async function. SWIFT_CC(swiftasync) -static void runAndBlock_start(AsyncTask *task, ExecutorRef executor, - SWIFT_ASYNC_CONTEXT AsyncContext *_context) { +static void runAndBlock_start(SWIFT_ASYNC_CONTEXT AsyncContext *_context, + SWIFT_CONTEXT HeapObject *closureContext) { auto callerContext = static_cast(_context); RunAndBlockSignature::FunctionType *function; size_t calleeContextSize; auto functionContext = callerContext->FunctionContext; + assert(closureContext == functionContext); std::tie(function, calleeContextSize) = getAsyncClosureEntryPointAndContextSize< RunAndBlockSignature, SpecialPointerAuthDiscriminators::AsyncRunAndBlockFunction >(const_cast(callerContext->Function), functionContext); - + auto calleeContext = - pushAsyncContext(task, executor, callerContext, + pushAsyncContext(callerContext, calleeContextSize, &runAndBlock_finish, functionContext); - return function(task, executor, calleeContext); + return reinterpret_cast(function)( + calleeContext, functionContext); } // TODO: Remove this hack. @@ -642,10 +705,11 @@ void swift::swift_task_runAndBlockThread(const void *function, // Set up a task that runs the runAndBlock async function above. auto flags = JobFlags(JobKind::Task, JobPriority::Default); - auto pair = swift_task_create_f(flags, - /*parent*/ nullptr, - &runAndBlock_start, - sizeof(RunAndBlockContext)); + auto pair = swift_task_create_f( + flags, + reinterpret_cast( + &runAndBlock_start), + sizeof(RunAndBlockContext)); auto context = static_cast(pair.InitialContext); context->Function = function; context->FunctionContext = functionContext; @@ -721,21 +785,21 @@ bool swift::swift_task_isCancelled(AsyncTask *task) { CancellationNotificationStatusRecord* swift::swift_task_addCancellationHandler( - AsyncTask *task, CancellationNotificationStatusRecord::FunctionType handler) { + CancellationNotificationStatusRecord::FunctionType handler) { void *allocation = - swift_task_alloc(task, sizeof(CancellationNotificationStatusRecord)); + swift_task_alloc(sizeof(CancellationNotificationStatusRecord)); auto *record = new (allocation) CancellationNotificationStatusRecord( handler, /*arg=*/nullptr); - swift_task_addStatusRecord(task, record); + swift_task_addStatusRecord(record); return record; } void swift::swift_task_removeCancellationHandler( - AsyncTask *task, CancellationNotificationStatusRecord *record) { - swift_task_removeStatusRecord(task, record); - swift_task_dealloc(task, record); + CancellationNotificationStatusRecord *record) { + swift_task_removeStatusRecord(record); + swift_task_dealloc(record); } SWIFT_CC(swift) diff --git a/stdlib/public/Concurrency/Task.swift b/stdlib/public/Concurrency/Task.swift index b6049bc5af32c..e4e8b399f7c32 100644 --- a/stdlib/public/Concurrency/Task.swift +++ b/stdlib/public/Concurrency/Task.swift @@ -402,7 +402,7 @@ extension Task { flags.isFuture = true // Create the asynchronous task future. - let (task, _) = Builtin.createAsyncTaskFuture(flags.bits, nil, operation) + let (task, _) = Builtin.createAsyncTaskFuture(flags.bits, operation) // Enqueue the resulting job. _enqueueJobGlobal(Builtin.convertTaskToJob(task)) @@ -454,7 +454,7 @@ extension Task { flags.isFuture = true // Create the asynchronous task future. - let (task, _) = Builtin.createAsyncTaskFuture(flags.bits, nil, operation) + let (task, _) = Builtin.createAsyncTaskFuture(flags.bits, operation) // Enqueue the resulting job. _enqueueJobGlobal(Builtin.convertTaskToJob(task)) @@ -487,7 +487,7 @@ extension Task { flags.isFuture = true // Create the asynchronous task future. - let (task, _) = Builtin.createAsyncTaskFuture(flags.bits, nil, {}) + let (task, _) = Builtin.createAsyncTaskFuture(flags.bits, {}) // Enqueue the resulting job. _enqueueJobGlobalWithDelay(duration, Builtin.convertTaskToJob(task)) @@ -657,7 +657,7 @@ public func _runChildTask( // Create the asynchronous task future. let (task, _) = Builtin.createAsyncTaskFuture( - flags.bits, currentTask, operation) + flags.bits, operation) // Enqueue the resulting job. _enqueueJobGlobal(Builtin.convertTaskToJob(task)) diff --git a/stdlib/public/Concurrency/TaskAlloc.cpp b/stdlib/public/Concurrency/TaskAlloc.cpp index 80f36c23eb4d9..fddbf967e7833 100644 --- a/stdlib/public/Concurrency/TaskAlloc.cpp +++ b/stdlib/public/Concurrency/TaskAlloc.cpp @@ -66,10 +66,18 @@ void swift::_swift_task_alloc_destroy(AsyncTask *task) { allocator(task).~TaskAllocator(); } -void *swift::swift_task_alloc(AsyncTask *task, size_t size) { +void *swift::swift_task_alloc(size_t size) { + return allocator(swift_task_getCurrent()).alloc(size); +} + +void *swift::_swift_task_alloc_specific(AsyncTask *task, size_t size) { return allocator(task).alloc(size); } -void swift::swift_task_dealloc(AsyncTask *task, void *ptr) { +void swift::swift_task_dealloc(void *ptr) { + allocator(swift_task_getCurrent()).dealloc(ptr); +} + +void swift::_swift_task_dealloc_specific(AsyncTask *task, void *ptr) { allocator(task).dealloc(ptr); } diff --git a/stdlib/public/Concurrency/TaskCancellation.swift b/stdlib/public/Concurrency/TaskCancellation.swift index 90a89d26f3def..4da5e8efb1d38 100644 --- a/stdlib/public/Concurrency/TaskCancellation.swift +++ b/stdlib/public/Concurrency/TaskCancellation.swift @@ -78,8 +78,8 @@ extension Task { return try await operation() } - let record = _taskAddCancellationHandler(task: task, handler: handler) - defer { _taskRemoveCancellationHandler(task: task, record: record) } + let record = _taskAddCancellationHandler(handler: handler) + defer { _taskRemoveCancellationHandler(record: record) } return try await operation() } @@ -96,13 +96,9 @@ extension Task { } @_silgen_name("swift_task_addCancellationHandler") -func _taskAddCancellationHandler( - task: Builtin.NativeObject, - handler: @concurrent () -> () -) -> UnsafeRawPointer /*CancellationNotificationStatusRecord*/ +func _taskAddCancellationHandler(handler: @concurrent () -> ()) -> UnsafeRawPointer /*CancellationNotificationStatusRecord*/ @_silgen_name("swift_task_removeCancellationHandler") func _taskRemoveCancellationHandler( - task: Builtin.NativeObject, record: UnsafeRawPointer /*CancellationNotificationStatusRecord*/ ) diff --git a/stdlib/public/Concurrency/TaskGroup.cpp b/stdlib/public/Concurrency/TaskGroup.cpp index 76e6f3a3ac097..c8a0177872166 100644 --- a/stdlib/public/Concurrency/TaskGroup.cpp +++ b/stdlib/public/Concurrency/TaskGroup.cpp @@ -308,7 +308,7 @@ class TaskGroupImpl: public TaskGroupTaskStatusRecord { } /// Destroy the storage associated with the group. - void destroy(AsyncTask *task); + void destroy(); bool isEmpty() { auto oldStatus = GroupStatus{status.load(std::memory_order_relaxed)}; @@ -323,7 +323,7 @@ class TaskGroupImpl: public TaskGroupTaskStatusRecord { /// Cancel the task group and all tasks within it. /// /// Returns `true` if this is the first time cancelling the group, false otherwise. - bool cancelAll(AsyncTask *task); + bool cancelAll(); GroupStatus statusCancel() { auto old = status.fetch_or(GroupStatus::cancelled, @@ -405,7 +405,7 @@ class TaskGroupImpl: public TaskGroupTaskStatusRecord { /// If possible, and an existing task is already waiting on next(), this will /// schedule it immediately. If not, the result is enqueued and will be picked /// up whenever a task calls next() the next time. - void offer(AsyncTask *completed, AsyncContext *context, ExecutorRef executor); + void offer(AsyncTask *completed, AsyncContext *context); /// Attempt to dequeue ready tasks and complete the waitingTask. /// @@ -444,7 +444,7 @@ static TaskGroup *asAbstract(TaskGroupImpl *group) { // ==== initialize ------------------------------------------------------------- // Initializes into the preallocated _group an actual TaskGroupImpl. -void swift::swift_taskGroup_initialize(AsyncTask *task, TaskGroup *group) { +void swift::swift_taskGroup_initialize(TaskGroup *group) { // // nasty trick, but we want to keep the record inside the group as we'll need // // to remove it from the task as the group is destroyed, as well as interact // // with it every time we add child tasks; so it is useful to pre-create it here @@ -463,17 +463,17 @@ void swift::swift_taskGroup_initialize(AsyncTask *task, TaskGroup *group) { assert(impl == record && "the group IS the task record"); // ok, now that the group actually is initialized: attach it to the task - swift_task_addStatusRecord(task, record); + swift_task_addStatusRecord(record); } // ============================================================================= // ==== create ----------------------------------------------------------------- -TaskGroup* swift::swift_taskGroup_create(AsyncTask *task) { +TaskGroup* swift::swift_taskGroup_create() { // TODO: John suggested we should rather create from a builtin, which would allow us to optimize allocations even more? - void *allocation = swift_task_alloc(task, sizeof(TaskGroup)); + void *allocation = swift_task_alloc(sizeof(TaskGroup)); auto group = reinterpret_cast(allocation); - swift_taskGroup_initialize(task, group); + swift_taskGroup_initialize(group); return group; } @@ -488,13 +488,13 @@ void swift::swift_taskGroup_attachChild(TaskGroup *group, AsyncTask *child) { // ============================================================================= // ==== destroy ---------------------------------------------------------------- -void swift::swift_taskGroup_destroy(AsyncTask *task, TaskGroup *group) { - asImpl(group)->destroy(task); +void swift::swift_taskGroup_destroy(TaskGroup *group) { + asImpl(group)->destroy(); } -void TaskGroupImpl::destroy(AsyncTask *task) { +void TaskGroupImpl::destroy() { // First, remove the group from the task and deallocate the record - swift_task_removeStatusRecord(task, getTaskRecord()); + swift_task_removeStatusRecord(getTaskRecord()); mutex.lock(); // TODO: remove lock, and use status for synchronization // Release all ready tasks which are kept retained, the group destroyed, @@ -508,18 +508,17 @@ void TaskGroupImpl::destroy(AsyncTask *task) { mutex.unlock(); // TODO: remove fragment lock, and use status for synchronization // TODO: get the parent task, do we need to store it? - swift_task_dealloc(task, this); + swift_task_dealloc(this); } // ============================================================================= // ==== offer ------------------------------------------------------------------ -void TaskGroup::offer(AsyncTask *completedTask, AsyncContext *context, - ExecutorRef completingExecutor) { - asImpl(this)->offer(completedTask, context, completingExecutor); +void TaskGroup::offer(AsyncTask *completedTask, AsyncContext *context) { + asImpl(this)->offer(completedTask, context); } -static void fillGroupNextResult(TaskFutureWaitAsyncContext *context, +static void fillGroupNextResult(TaskGroupNextAsyncContext *context, PollResult result) { /// Fill in the result value switch (result.status) { @@ -553,8 +552,7 @@ static void fillGroupNextResult(TaskFutureWaitAsyncContext *context, } } -void TaskGroupImpl::offer(AsyncTask *completedTask, AsyncContext *context, - ExecutorRef completingExecutor) { +void TaskGroupImpl::offer(AsyncTask *completedTask, AsyncContext *context) { assert(completedTask); assert(completedTask->isFuture()); assert(completedTask->hasChildFragment()); @@ -581,10 +579,11 @@ void TaskGroupImpl::offer(AsyncTask *completedTask, AsyncContext *context, // W:n R:0 P:1 -> W:y R:1 P:3 // complete immediately, 2 more pending tasks auto assumed = statusAddReadyAssumeAcquire(); - // If an error was thrown, save it in the future fragment. - auto futureContext = static_cast(context); + auto asyncContextPrefix = reinterpret_cast( + reinterpret_cast(context) - sizeof(FutureAsyncContextPrefix)); bool hadErrorResult = false; - if (auto errorObject = *futureContext->errorResult) { + auto errorObject = asyncContextPrefix->errorResult; + if (errorObject) { // instead we need to enqueue this result: hadErrorResult = true; } @@ -609,8 +608,9 @@ void TaskGroupImpl::offer(AsyncTask *completedTask, AsyncContext *context, mutex.unlock(); // TODO: remove fragment lock, and use status for synchronization auto waitingContext = - static_cast( + static_cast( waitingTask->ResumeContext); + fillGroupNextResult(waitingContext, result); // TODO: allow the caller to suggest an executor @@ -642,21 +642,35 @@ void TaskGroupImpl::offer(AsyncTask *completedTask, AsyncContext *context, return; } +SWIFT_CC(swiftasync) +static void +task_group_wait_resume_adapter(SWIFT_ASYNC_CONTEXT AsyncContext *_context) { + + auto context = static_cast(_context); + return context->asyncResumeEntryPoint(_context, context->errorResult); +} + // ============================================================================= // ==== group.next() implementation (wait_next and groupPoll) ------------------ - SWIFT_CC(swiftasync) void swift::swift_taskGroup_wait_next_throwing( - AsyncTask *waitingTask, - ExecutorRef executor, - SWIFT_ASYNC_CONTEXT AsyncContext *rawContext) { - waitingTask->ResumeTask = rawContext->ResumeParent; + OpaqueValue *resultPointer, SWIFT_ASYNC_CONTEXT AsyncContext *rawContext, + TaskGroup *_group, const Metadata *successType) { + auto waitingTask = swift_task_getCurrent(); + auto originalResumeParent = + reinterpret_cast( + rawContext->ResumeParent); + waitingTask->ResumeTask = task_group_wait_resume_adapter; waitingTask->ResumeContext = rawContext; - auto context = static_cast(rawContext); - auto task = context->task; + auto context = static_cast(rawContext); + context->errorResult = nullptr; + context->asyncResumeEntryPoint = originalResumeParent; + context->successResultPointer = resultPointer; + context->group = _group; + context->successType = successType; + auto group = asImpl(context->group); - assert(waitingTask == task && "attempted to wait on group.next() from other task, which is illegal!"); assert(group && "swift_taskGroup_wait_next_throwing was passed context without group!"); PollResult polled = group->poll(waitingTask); @@ -670,7 +684,7 @@ void swift::swift_taskGroup_wait_next_throwing( case PollStatus::Error: case PollStatus::Success: fillGroupNextResult(context, polled); - return waitingTask->runInFullyEstablishedContext(executor); + return waitingTask->runInFullyEstablishedContext(); } } @@ -778,18 +792,18 @@ bool swift::swift_taskGroup_isEmpty(TaskGroup *group) { // ============================================================================= // ==== isCancelled ------------------------------------------------------------ -bool swift::swift_taskGroup_isCancelled(AsyncTask *task, TaskGroup *group) { +bool swift::swift_taskGroup_isCancelled(TaskGroup *group) { return asImpl(group)->isCancelled(); } // ============================================================================= // ==== cancelAll -------------------------------------------------------------- -void swift::swift_taskGroup_cancelAll(AsyncTask *task, TaskGroup *group) { - asImpl(group)->cancelAll(task); +void swift::swift_taskGroup_cancelAll(TaskGroup *group) { + asImpl(group)->cancelAll(); } -bool TaskGroupImpl::cancelAll(AsyncTask *task) { +bool TaskGroupImpl::cancelAll() { // store the cancelled bit auto old = statusCancel(); if (old.isCancelled()) { @@ -798,7 +812,7 @@ bool TaskGroupImpl::cancelAll(AsyncTask *task) { } // cancel all existing tasks within the group - swift_task_cancel_group_child_tasks(task, asAbstract(this)); + swift_task_cancel_group_child_tasks(asAbstract(this)); return true; } diff --git a/stdlib/public/Concurrency/TaskGroup.swift b/stdlib/public/Concurrency/TaskGroup.swift index 1d16ab048d7b8..52d98fe269d6b 100644 --- a/stdlib/public/Concurrency/TaskGroup.swift +++ b/stdlib/public/Concurrency/TaskGroup.swift @@ -66,7 +66,7 @@ extension Task { body: (inout Task.Group) async throws -> BodyResult ) async rethrows -> BodyResult { let task = Builtin.getCurrentAsyncTask() - let _group = _taskGroupCreate(task: task) + let _group = _taskGroupCreate() var group: Task.Group! = Task.Group(task: task, group: _group) // Run the withGroup body. @@ -74,13 +74,13 @@ extension Task { let result = try await body(&group) await group._tearDown() group = nil - _taskGroupDestroy(task: task, group: _group) + _taskGroupDestroy(group: _group) return result } catch { group.cancelAll() await group._tearDown() group = nil - _taskGroupDestroy(task: task, group: _group) + _taskGroupDestroy(group: _group) throw error } } @@ -143,7 +143,7 @@ extension Task { // Create the asynchronous task future. let (childTask, _) = Builtin.createAsyncTaskGroupFuture( - flags.bits, _task, _group, operation) + flags.bits, _group, operation) // Attach it to the group's task record in the current task. _taskGroupAttachChild(group: _group, child: childTask) @@ -218,7 +218,7 @@ extension Task { """) #endif - return try await _taskGroupWaitNext(waitingTask: _task, group: _group) + return try await _taskGroupWaitNext(group: _group) } /// Query whether the group has any remaining tasks. @@ -245,7 +245,7 @@ extension Task { /// - SeeAlso: `Task.isCancelled` /// - SeeAlso: `TaskGroup.isCancelled` public func cancelAll() { - _taskGroupCancelAll(task: _task, group: _group) + _taskGroupCancelAll(group: _group) } /// Returns `true` if the group was cancelled, e.g. by `cancelAll`. @@ -258,7 +258,7 @@ extension Task { /// `false` otherwise. public var isCancelled: Bool { return _taskIsCancelled(_task) || - _taskGroupIsCancelled(task: _task, group: _group) + _taskGroupIsCancelled(group: _group) } } } @@ -342,9 +342,7 @@ func _swiftRelease( ) @_silgen_name("swift_taskGroup_create") -func _taskGroupCreate( - task: Builtin.NativeObject -) -> Builtin.RawPointer +func _taskGroupCreate() -> Builtin.RawPointer /// Attach task group child to the group group to the task. @_silgen_name("swift_taskGroup_attachChild") @@ -354,10 +352,7 @@ func _taskGroupAttachChild( ) -> UnsafeRawPointer /*ChildTaskStatusRecord*/ @_silgen_name("swift_taskGroup_destroy") -func _taskGroupDestroy( - task: Builtin.NativeObject, - group: __owned Builtin.RawPointer -) +func _taskGroupDestroy(group: __owned Builtin.RawPointer) @_silgen_name("swift_taskGroup_addPending") func _taskGroupAddPendingTask( @@ -365,24 +360,15 @@ func _taskGroupAddPendingTask( ) -> Bool @_silgen_name("swift_taskGroup_cancelAll") -func _taskGroupCancelAll( - task: Builtin.NativeObject, - group: Builtin.RawPointer -) +func _taskGroupCancelAll(group: Builtin.RawPointer) /// Checks ONLY if the group was specifically cancelled. /// The task itself being cancelled must be checked separately. @_silgen_name("swift_taskGroup_isCancelled") -func _taskGroupIsCancelled( - task: Builtin.NativeObject, - group: Builtin.RawPointer -) -> Bool +func _taskGroupIsCancelled(group: Builtin.RawPointer) -> Bool @_silgen_name("swift_taskGroup_wait_next_throwing") -func _taskGroupWaitNext( - waitingTask: Builtin.NativeObject, - group: Builtin.RawPointer -) async throws -> T? +func _taskGroupWaitNext(group: Builtin.RawPointer) async throws -> T? enum PollStatus: Int { case empty = 0 diff --git a/stdlib/public/Concurrency/TaskLocal.cpp b/stdlib/public/Concurrency/TaskLocal.cpp index 734cafd46a0b4..eee76dc9ed1a3 100644 --- a/stdlib/public/Concurrency/TaskLocal.cpp +++ b/stdlib/public/Concurrency/TaskLocal.cpp @@ -14,6 +14,7 @@ #include "swift/Runtime/Concurrency.h" #include "swift/ABI/Task.h" #include "swift/ABI/Metadata.h" +#include "TaskPrivate.h" using namespace swift; @@ -51,7 +52,7 @@ TaskLocal::Item* TaskLocal::Item::createParentLink(AsyncTask *task, AsyncTask *parent) { size_t amountToAllocate = Item::itemSize(/*valueType*/nullptr); // assert(amountToAllocate % MaximumAlignment == 0); // TODO: do we need this? - void *allocation = swift_task_alloc(task, amountToAllocate); + void *allocation = _swift_task_alloc_specific(task, amountToAllocate); Item *item = new(allocation) Item(); auto parentHead = parent->Local.head; @@ -95,7 +96,7 @@ TaskLocal::Item::createLink(AsyncTask *task, assert(task); size_t amountToAllocate = Item::itemSize(valueType); // assert(amountToAllocate % MaximumAlignment == 0); // TODO: do we need this? - void *allocation = swift_task_alloc(task, amountToAllocate); + void *allocation = _swift_task_alloc_specific(task, amountToAllocate); Item *item = new(allocation) Item(keyType, valueType); auto next = task->Local.head; @@ -115,7 +116,7 @@ void TaskLocal::Item::destroy(AsyncTask *task) { valueType->vw_destroy(getStoragePtr()); } - swift_task_dealloc(task, this); + _swift_task_dealloc_specific(task, this); } void TaskLocal::Storage::destroy(AsyncTask *task) { diff --git a/stdlib/public/Concurrency/TaskPrivate.h b/stdlib/public/Concurrency/TaskPrivate.h index e4a7c47325083..453a2f6b99453 100644 --- a/stdlib/public/Concurrency/TaskPrivate.h +++ b/stdlib/public/Concurrency/TaskPrivate.h @@ -34,13 +34,23 @@ void _swift_task_alloc_initialize(AsyncTask *task); /// Destroy the task-local allocator in the given task. void _swift_task_alloc_destroy(AsyncTask *task); -/// Given that we've already set the given executor as the active +/// Allocate task-local memory on behalf of a specific task, +/// not necessarily the current one. Generally this should only be +/// done on behalf of a child task. +void *_swift_task_alloc_specific(AsyncTask *task, size_t size); + +/// dellocate task-local memory on behalf of a specific task, +/// not necessarily the current one. Generally this should only be +/// done on behalf of a child task. +void _swift_task_dealloc_specific(AsyncTask *task, void *ptr); + +/// Given that we've already set the right executor as the active /// executor, run the given job. This does additional bookkeeping /// related to the active task. -void runJobInExecutorContext(Job *job, ExecutorRef executor); +void runJobInEstablishedExecutorContext(Job *job); /// Clear the active task reference for the current thread. -void _swift_task_clearCurrent(); +AsyncTask *_swift_task_clearCurrent(); #if defined(SWIFT_STDLIB_SINGLE_THREADED_RUNTIME) #define SWIFT_CONCURRENCY_COOPERATIVE_GLOBAL_EXECUTOR 1 @@ -56,48 +66,75 @@ void donateThreadToGlobalExecutorUntil(bool (*condition)(void*), void *context); #endif +/// release() establishes a happens-before relation with a preceding acquire() +/// on the same address. +void _swift_tsan_acquire(void *addr); +void _swift_tsan_release(void *addr); + // ==== ------------------------------------------------------------------------ namespace { -/// An asynchronous context within a task that describes a general "Future". +/// The layout of a context to call one of the following functions: +/// +/// @_silgen_name("swift_task_future_wait") +/// func _taskFutureGet(_ task: Builtin.NativeObject) async -> T +/// +/// @_silgen_name("swift_task_future_wait_throwing") +/// func _taskFutureGetThrowing(_ task: Builtin.NativeObject) async throws -> T /// -/// This type matches the ABI of a function ` () async throws -> T`, which -/// is the type used by `Task.runDetached` and `Task.group.add` to create -/// futures. class TaskFutureWaitAsyncContext : public AsyncContext { public: - // Error result is always present. - SwiftError **errorResult = nullptr; + SwiftError *errorResult; OpaqueValue *successResultPointer; - // FIXME: Currently, this is always here, but it isn't technically - // necessary. - void* Self; + AsyncVoidClosureResumeEntryPoint *__ptrauth_swift_task_resume_function + asyncResumeEntryPoint; - // Arguments. - AsyncTask *task; + void fillWithSuccess(AsyncTask::FutureFragment *future) { + fillWithSuccess(future->getStoragePtr(), future->getResultType(), + successResultPointer); + } + void fillWithSuccess(OpaqueValue *src, const Metadata *successType, + OpaqueValue *result) { + successType->vw_initializeWithCopy(result, src); + } + + void fillWithError(AsyncTask::FutureFragment *future) { + fillWithError(future->getError()); + } + void fillWithError(SwiftError *error) { + errorResult = error; + swift_errorRetain(error); + } +}; + +/// The layout of a frame to call the following function: +/// +/// @_silgen_name("swift_taskGroup_wait_next_throwing") +/// func _taskGroupWaitNext(group: Builtin.RawPointer) async throws -> T? +/// +class TaskGroupNextAsyncContext : public AsyncContext { +public: + SwiftError *errorResult; + + OpaqueValue *successResultPointer; + + AsyncVoidClosureResumeEntryPoint *__ptrauth_swift_task_resume_function + asyncResumeEntryPoint; - // Only in swift_taskGroup_wait_next_throwing. + // Arguments. TaskGroup *group; - // Only in swift_taskGroup_wait_next_throwing. - const Metadata *successType; - using AsyncContext::AsyncContext; + const Metadata *successType; - void fillWithSuccess(AsyncTask::FutureFragment *future) { - fillWithSuccess(future->getStoragePtr(), future->getResultType()); - } void fillWithSuccess(OpaqueValue *src, const Metadata *successType) { successType->vw_initializeWithCopy(successResultPointer, src); } - void fillWithError(AsyncTask::FutureFragment *future) { - fillWithError(future->getError()); - } void fillWithError(SwiftError *error) { - *errorResult = error; + errorResult = error; swift_errorRetain(error); } }; diff --git a/stdlib/public/Concurrency/TaskStatus.cpp b/stdlib/public/Concurrency/TaskStatus.cpp index c954ef466a2f3..3579495a82756 100644 --- a/stdlib/public/Concurrency/TaskStatus.cpp +++ b/stdlib/public/Concurrency/TaskStatus.cpp @@ -270,8 +270,9 @@ static void releaseStatusRecordLock(AsyncTask *task, /*************************** RECORD MANAGEMENT ****************************/ /**************************************************************************/ -bool swift::swift_task_addStatusRecord(AsyncTask *task, - TaskStatusRecord *newRecord) { +bool swift::swift_task_addStatusRecord(TaskStatusRecord *newRecord) { + auto task = swift_task_getCurrent(); + // Load the current state. We can use a relaxed load because we're // synchronous with the task. auto oldStatus = task->Status.load(std::memory_order_relaxed); @@ -297,8 +298,9 @@ bool swift::swift_task_addStatusRecord(AsyncTask *task, } } -bool swift::swift_task_tryAddStatusRecord(AsyncTask *task, - TaskStatusRecord *newRecord) { +bool swift::swift_task_tryAddStatusRecord(TaskStatusRecord *newRecord) { + auto task = swift_task_getCurrent(); + // Load the current state. We can use a relaxed load because we're // synchronous with the task. auto oldStatus = task->Status.load(std::memory_order_relaxed); @@ -332,8 +334,9 @@ bool swift::swift_task_tryAddStatusRecord(AsyncTask *task, } } -bool swift::swift_task_removeStatusRecord(AsyncTask *task, - TaskStatusRecord *record) { +bool swift::swift_task_removeStatusRecord(TaskStatusRecord *record) { + auto task = swift_task_getCurrent(); + // Load the current state. auto oldStatus = task->Status.load(std::memory_order_relaxed); @@ -400,16 +403,16 @@ bool swift::swift_task_removeStatusRecord(AsyncTask *task, // ==== Child tasks ------------------------------------------------------------ ChildTaskStatusRecord* -swift::swift_task_attachChild(AsyncTask *parent, AsyncTask *child) { +swift::swift_task_attachChild(AsyncTask *child) { void *allocation = malloc(sizeof(swift::ChildTaskStatusRecord)); auto record = new (allocation) swift::ChildTaskStatusRecord(child); - swift_task_addStatusRecord(parent, record); + swift_task_addStatusRecord(record); return record; } void -swift::swift_task_detachChild(AsyncTask *parent, ChildTaskStatusRecord *record) { - swift_task_removeStatusRecord(parent, record); +swift::swift_task_detachChild(ChildTaskStatusRecord *record) { + swift_task_removeStatusRecord(record); } /****************************** CANCELLATION ******************************/ @@ -525,7 +528,7 @@ void swift::swift_task_cancel(AsyncTask *task) { releaseStatusRecordLock(task, cancelledStatus, recordLockRecord); } -void swift::swift_task_cancel_group_child_tasks(AsyncTask *task, TaskGroup *group) { +void swift::swift_task_cancel_group_child_tasks(TaskGroup *group) { Optional recordLockRecord; // Acquire the status record lock. @@ -533,6 +536,7 @@ void swift::swift_task_cancel_group_child_tasks(AsyncTask *task, TaskGroup *grou // We purposefully DO NOT make this a cancellation by itself. // We are cancelling the task group, and all tasks it contains. // We are NOT cancelling the entire parent task though. + auto task = swift_task_getCurrent(); auto oldStatus = acquireStatusRecordLock(task, recordLockRecord, /*forCancellation*/ false); // Carry out the cancellation operations associated with all diff --git a/stdlib/public/Concurrency/ThreadSanitizer.cpp b/stdlib/public/Concurrency/ThreadSanitizer.cpp new file mode 100644 index 0000000000000..b63eb87995585 --- /dev/null +++ b/stdlib/public/Concurrency/ThreadSanitizer.cpp @@ -0,0 +1,73 @@ +//===--- ThreadSanitizer.cpp - Thread Sanitizer support -------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// +// +// Thread Sanitizer support for the Swift Task runtime +// +//===----------------------------------------------------------------------===// + +#include "TaskPrivate.h" + +#if defined(_WIN32) +#define NOMINMAX +#include +#elif defined(__wasi__) + +#else +#include +#endif + +namespace { +using TSanFunc = void(void *); +TSanFunc *tsan_acquire, *tsan_release; + +#if defined(__wasi__) + +swift::swift_once_t initOnceToken; +void initializeThreadSanitizer(void *unused) {} + +#else + +TSanFunc *loadSymbol(const char *name) { +#if defined(_WIN32) + return (TSanFunc *)GetProcAddress(GetModuleHandle(NULL), name); +#else + return (TSanFunc *)dlsym(RTLD_DEFAULT, name); +#endif +} + +swift::swift_once_t initOnceToken; +void initializeThreadSanitizer(void *unused) { + tsan_acquire = loadSymbol("__tsan_acquire"); + tsan_release = loadSymbol("__tsan_release"); +} +#endif +} // anonymous namespace + +void swift::_swift_tsan_acquire(void *addr) { + swift_once(&initOnceToken, initializeThreadSanitizer, nullptr); + if (tsan_acquire) { + tsan_acquire(addr); + } +} + +void swift::_swift_tsan_release(void *addr) { + swift_once(&initOnceToken, initializeThreadSanitizer, nullptr); + if (tsan_release) { + tsan_release(addr); + } +} + +SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(c) +void swift_task_set_tsan_hooks(TSanFunc *acquire, TSanFunc *release) { + tsan_acquire = acquire; + tsan_release = release; +} diff --git a/stdlib/public/runtime/EnvironmentVariables.def b/stdlib/public/runtime/EnvironmentVariables.def index 494cb03b888cd..73e35690b0b71 100644 --- a/stdlib/public/runtime/EnvironmentVariables.def +++ b/stdlib/public/runtime/EnvironmentVariables.def @@ -53,6 +53,10 @@ VARIABLE(SWIFT_DEBUG_VALIDATE_SHARED_CACHE_PROTOCOL_CONFORMANCES, bool, false, "Validate shared cache protocol conformance results against the " "lists of conformances in the shared cache images.") +VARIABLE(SWIFT_DEBUG_ENABLE_SHARED_CACHE_PROTOCOL_CONFORMANCES, bool, true, + "Enable querying precomputed protocol conformances in the shared " + "cache.") + #endif #undef VARIABLE diff --git a/stdlib/public/runtime/MetadataLookup.cpp b/stdlib/public/runtime/MetadataLookup.cpp index 0b521eef690ee..94b18b5bd58ce 100644 --- a/stdlib/public/runtime/MetadataLookup.cpp +++ b/stdlib/public/runtime/MetadataLookup.cpp @@ -1499,8 +1499,58 @@ class DecodedMetadataBuilder { result); } + struct BuiltLayoutConstraint { + bool operator==(BuiltLayoutConstraint rhs) const { return true; } + operator bool() const { return true; } + }; + using BuiltLayoutConstraint = BuiltLayoutConstraint; + BuiltLayoutConstraint getLayoutConstraint(LayoutConstraintKind kind) { + return {}; + } + BuiltLayoutConstraint + getLayoutConstraintWithSizeAlign(LayoutConstraintKind kind, unsigned size, + unsigned alignment) { + return {}; + } + +#if LLVM_PTR_SIZE == 4 + /// Unfortunately the alignment of TypeRef is too large to squeeze in 3 extra + /// bits on (some?) 32-bit systems. + class BigBuiltTypeIntPair { + BuiltType Ptr; + RequirementKind Int; + + public: + BigBuiltTypeIntPair(BuiltType ptr, RequirementKind i) : Ptr(ptr), Int(i) {} + RequirementKind getInt() const { return Int; } + BuiltType getPointer() const { return Ptr; } + uint64_t getOpaqueValue() const { + return (uint64_t)Ptr | ((uint64_t)Int << 32); + } + }; +#endif + + struct Requirement : public RequirementBase, + +#endif + BuiltLayoutConstraint> { + Requirement(RequirementKind kind, BuiltType first, BuiltType second) + : RequirementBase(kind, first, second) {} + Requirement(RequirementKind kind, BuiltType first, + BuiltLayoutConstraint second) + : RequirementBase(kind, first, second) {} + }; + using BuiltRequirement = Requirement; + TypeLookupErrorOr createImplFunctionType( Demangle::ImplParameterConvention calleeConvention, + BuiltRequirement *witnessMethodConformanceRequirement, + llvm::ArrayRef genericParameters, + llvm::ArrayRef requirements, llvm::ArrayRef> params, llvm::ArrayRef> results, llvm::Optional> errorResult, @@ -1568,51 +1618,6 @@ class DecodedMetadataBuilder { using BuiltSILBoxField = llvm::PointerIntPair; using BuiltSubstitution = std::pair; - struct BuiltLayoutConstraint { - bool operator==(BuiltLayoutConstraint rhs) const { return true; } - operator bool() const { return true; } - }; - using BuiltLayoutConstraint = BuiltLayoutConstraint; - BuiltLayoutConstraint getLayoutConstraint(LayoutConstraintKind kind) { - return {}; - } - BuiltLayoutConstraint - getLayoutConstraintWithSizeAlign(LayoutConstraintKind kind, unsigned size, - unsigned alignment) { - return {}; - } - -#if LLVM_PTR_SIZE == 4 - /// Unfortunately the alignment of TypeRef is too large to squeeze in 3 extra - /// bits on (some?) 32-bit systems. - class BigBuiltTypeIntPair { - BuiltType Ptr; - RequirementKind Int; - public: - BigBuiltTypeIntPair(BuiltType ptr, RequirementKind i) : Ptr(ptr), Int(i) {} - RequirementKind getInt() const { return Int; } - BuiltType getPointer() const { return Ptr; } - uint64_t getOpaqueValue() const { - return (uint64_t)Ptr | ((uint64_t)Int << 32); - } - }; -#endif - - struct Requirement : public RequirementBase, - -#endif - BuiltLayoutConstraint> { - Requirement(RequirementKind kind, BuiltType first, BuiltType second) - : RequirementBase(kind, first, second) {} - Requirement(RequirementKind kind, BuiltType first, - BuiltLayoutConstraint second) - : RequirementBase(kind, first, second) {} - }; - using BuiltRequirement = Requirement; TypeLookupErrorOr createSILBoxTypeWithLayout( llvm::ArrayRef Fields, diff --git a/stdlib/public/runtime/ProtocolConformance.cpp b/stdlib/public/runtime/ProtocolConformance.cpp index c5ca685a12bcb..d660349b7b094 100644 --- a/stdlib/public/runtime/ProtocolConformance.cpp +++ b/stdlib/public/runtime/ProtocolConformance.cpp @@ -303,25 +303,27 @@ struct ConformanceState { #if USE_DYLD_SHARED_CACHE_CONFORMANCE_TABLES if (__builtin_available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)) { - if (&_dyld_swift_optimizations_version) { - if (_dyld_swift_optimizations_version() == - DYLD_EXPECTED_SWIFT_OPTIMIZATIONS_VERSION) { - size_t length; - dyldSharedCacheStart = - (uintptr_t)_dyld_get_shared_cache_range(&length); - dyldSharedCacheEnd = - dyldSharedCacheStart ? dyldSharedCacheStart + length : 0; - validateSharedCacheResults = runtime::environment:: - SWIFT_DEBUG_VALIDATE_SHARED_CACHE_PROTOCOL_CONFORMANCES(); - SHARED_CACHE_LOG("Shared cache range is %#lx-%#lx", - dyldSharedCacheStart, dyldSharedCacheEnd); - } else { - SHARED_CACHE_LOG( - "Disabling shared cache optimizations due to unknown " - "optimizations version %u", - _dyld_swift_optimizations_version()); - dyldSharedCacheStart = 0; - dyldSharedCacheEnd = 0; + if (runtime::environment::SWIFT_DEBUG_ENABLE_SHARED_CACHE_PROTOCOL_CONFORMANCES()) { + if (&_dyld_swift_optimizations_version) { + if (_dyld_swift_optimizations_version() == + DYLD_EXPECTED_SWIFT_OPTIMIZATIONS_VERSION) { + size_t length; + dyldSharedCacheStart = + (uintptr_t)_dyld_get_shared_cache_range(&length); + dyldSharedCacheEnd = + dyldSharedCacheStart ? dyldSharedCacheStart + length : 0; + validateSharedCacheResults = runtime::environment:: + SWIFT_DEBUG_VALIDATE_SHARED_CACHE_PROTOCOL_CONFORMANCES(); + SHARED_CACHE_LOG("Shared cache range is %#lx-%#lx", + dyldSharedCacheStart, dyldSharedCacheEnd); + } else { + SHARED_CACHE_LOG( + "Disabling shared cache optimizations due to unknown " + "optimizations version %u", + _dyld_swift_optimizations_version()); + dyldSharedCacheStart = 0; + dyldSharedCacheEnd = 0; + } } } } @@ -608,8 +610,8 @@ static void validateSharedCacheResults( }; if (dyldCachedConformanceDescriptor) { - if (!std::find(conformances.begin(), conformances.end(), - dyldCachedConformanceDescriptor)) { + if (std::find(conformances.begin(), conformances.end(), + dyldCachedConformanceDescriptor) == conformances.end()) { auto typeName = swift_getTypeName(type, true); swift::fatalError( 0, @@ -775,7 +777,10 @@ swift_conformsToProtocolImpl(const Metadata *const type, } if (dyldCachedConformanceDescriptor) { - auto witness = dyldCachedConformanceDescriptor->getWitnessTable(type); + ConformanceCandidate candidate(*dyldCachedConformanceDescriptor); + auto *matchingType = candidate.getMatchingType(type); + assert(matchingType); + auto witness = dyldCachedConformanceDescriptor->getWitnessTable(matchingType); C.cacheResult(type, protocol, witness, /*always cache*/ 0); SHARED_CACHE_LOG("Caching generic conformance to %s found in shared cache", protocol->Name.get()); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f9e8cf866c326..80467c585be5a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -54,7 +54,6 @@ function(get_test_dependencies SDK result_var_name) sil-opt sil-passpipeline-dumper swift-frontend - swift-api-digester swift-demangle swift-demangle-yamldump swift-dependency-tool diff --git a/test/ClangImporter/newtype_conformance.swift b/test/ClangImporter/newtype_conformance.swift index 2e7a718f36640..a408b9a094b96 100644 --- a/test/ClangImporter/newtype_conformance.swift +++ b/test/ClangImporter/newtype_conformance.swift @@ -22,6 +22,7 @@ func testNewTypeWrapper(x: NSNotification.Name, y: NSNotification.Name) { acceptEquatable(x) acceptHashable(x) acceptComparable(x) // expected-error {{global function 'acceptComparable' requires that 'NSNotification.Name' conform to 'Comparable'}} + // expected-note@-1 {{did you mean to use '.rawValue'?}} {{19-19=.rawValue}} _ = x == y _ = x != y diff --git a/test/Concurrency/Runtime/actor_counters.swift b/test/Concurrency/Runtime/actor_counters.swift index c996400a25b47..514ba9bd69b59 100644 --- a/test/Concurrency/Runtime/actor_counters.swift +++ b/test/Concurrency/Runtime/actor_counters.swift @@ -63,6 +63,12 @@ func runTest(numCounters: Int, numWorkers: Int, numIterations: Int) async { @main struct Main { static func main() async { - await runTest(numCounters: 10, numWorkers: 100, numIterations: 1000) + // Useful for debugging: specify counter/worker/iteration counts + let args = CommandLine.arguments + let counters = args.count >= 2 ? Int(args[1])! : 10 + let workers = args.count >= 3 ? Int(args[2])! : 100 + let iterations = args.count >= 4 ? Int(args[3])! : 1000 + print("counters: \(counters), workers: \(workers), iterations: \(iterations)") + await runTest(numCounters: counters, numWorkers: workers, numIterations: iterations) } } diff --git a/test/Concurrency/Runtime/async_task_handle_cancellation.swift b/test/Concurrency/Runtime/async_task_handle_cancellation.swift index a0924b34dd576..9426b0f750b4e 100644 --- a/test/Concurrency/Runtime/async_task_handle_cancellation.swift +++ b/test/Concurrency/Runtime/async_task_handle_cancellation.swift @@ -3,8 +3,6 @@ // REQUIRES: executable_test // REQUIRES: concurrency -// XFAIL: OS=windows-msvc - @main struct Main { static func main() async { let handle = Task.runDetached { diff --git a/test/Concurrency/actor_call_implicitly_async.swift b/test/Concurrency/actor_call_implicitly_async.swift index 316b49fe599bb..e24f0c028774a 100644 --- a/test/Concurrency/actor_call_implicitly_async.swift +++ b/test/Concurrency/actor_call_implicitly_async.swift @@ -1,4 +1,4 @@ -// RUN: %target-typecheck-verify-swift -enable-experimental-concurrency +// RUN: %target-typecheck-verify-swift -enable-experimental-concurrency -warn-concurrency // REQUIRES: concurrency actor BankAccount { diff --git a/test/Concurrency/actor_isolation.swift b/test/Concurrency/actor_isolation.swift index ec65a00f63472..b3eabdf9928be 100644 --- a/test/Concurrency/actor_isolation.swift +++ b/test/Concurrency/actor_isolation.swift @@ -1,4 +1,4 @@ -// RUN: %target-typecheck-verify-swift -enable-experimental-concurrency +// RUN: %target-typecheck-verify-swift -enable-experimental-concurrency -warn-concurrency // REQUIRES: concurrency let immutableGlobal: String = "hello" @@ -372,7 +372,7 @@ func testGlobalActorClosures() { return 17 } - acceptConcurrentClosure { @SomeGlobalActor in 5 } // expected-error{{closure isolated to global actor 'SomeGlobalActor' must be 'async'}} + acceptConcurrentClosure { @SomeGlobalActor in 5 } // expected-error{{converting function value of type '@SomeGlobalActor @concurrent () -> Int' to '@concurrent () -> Int' loses global actor 'SomeGlobalActor'}} } extension MyActor { diff --git a/test/Concurrency/actor_keypath_isolation.swift b/test/Concurrency/actor_keypath_isolation.swift index 724a20d3d4cd2..717883680ed82 100644 --- a/test/Concurrency/actor_keypath_isolation.swift +++ b/test/Concurrency/actor_keypath_isolation.swift @@ -1,4 +1,4 @@ -// RUN: %target-typecheck-verify-swift -enable-experimental-concurrency +// RUN: %target-typecheck-verify-swift -enable-experimental-concurrency -warn-concurrency // REQUIRES: concurrency class Box { @@ -19,7 +19,7 @@ actor Door { var getOnlyInt : Int { get { 0 } } - + @actorIndependent(unsafe) var unsafeIndependent : Int = 0 @MainActor var globActor_mutable : Int = 0 @@ -68,7 +68,7 @@ func tryNonConcurrentValue() { func tryKeypaths() { _ = \Door.unsafeGlobActor_immutable - _ = \Door.unsafeGlobActor_mutable + _ = \Door.unsafeGlobActor_mutable // expected-error{{cannot form key path to actor-isolated property 'unsafeGlobActor_mutable'}} _ = \Door.immutable _ = \Door.unsafeIndependent @@ -87,4 +87,4 @@ func tryKeypaths() { _ = \Door.globActor_mutable // expected-error{{cannot form key path to actor-isolated property 'globActor_mutable'}} _ = \Door.[0] // expected-error{{cannot form key path to actor-isolated subscript 'subscript(_:)'}} _ = \Door.["hello"] // expected-error{{cannot form key path to actor-isolated subscript 'subscript(_:)'}} -} \ No newline at end of file +} diff --git a/test/Concurrency/concurrent_value_checking.swift b/test/Concurrency/concurrent_value_checking.swift index b452f3ca647d1..8846ef30a5722 100644 --- a/test/Concurrency/concurrent_value_checking.swift +++ b/test/Concurrency/concurrent_value_checking.swift @@ -1,4 +1,4 @@ -// RUN: %target-typecheck-verify-swift -enable-experimental-concurrency +// RUN: %target-typecheck-verify-swift -enable-experimental-concurrency -warn-concurrency // REQUIRES: concurrency class NotConcurrent { } diff --git a/test/Concurrency/global_actor_function_types.swift b/test/Concurrency/global_actor_function_types.swift new file mode 100644 index 0000000000000..9532a6387443d --- /dev/null +++ b/test/Concurrency/global_actor_function_types.swift @@ -0,0 +1,111 @@ +// RUN: %target-typecheck-verify-swift -enable-experimental-concurrency +// REQUIRES: concurrency + +actor SomeActor { } + +@globalActor +struct SomeGlobalActor { + static let shared = SomeActor() +} + +@globalActor +struct OtherGlobalActor { + static let shared = SomeActor() +} + +func testConversions(f: @escaping @SomeGlobalActor (Int) -> Void, g: @escaping (Int) -> Void) { + let _: Int = f // expected-error{{cannot convert value of type '@SomeGlobalActor (Int) -> Void' to specified type 'Int'}} + + let _: (Int) -> Void = f // expected-error{{converting function value of type '@SomeGlobalActor (Int) -> Void' to '(Int) -> Void' loses global actor 'SomeGlobalActor'}} + let _: @SomeGlobalActor (Int) -> Void = g // okay + + // FIXME: this could be better. + let _: @OtherGlobalActor (Int) -> Void = f // expected-error{{cannot convert value of type 'SomeGlobalActor' to specified type 'OtherGlobalActor'}} +} + +@SomeGlobalActor func onSomeGlobalActor() -> Int { 5 } +@SomeGlobalActor(unsafe) func onSomeGlobalActorUnsafe() -> Int { 5 } + +@OtherGlobalActor func onOtherGlobalActor() -> Int { 5 } // expected-note{{calls to global function 'onOtherGlobalActor()' from outside of its actor context are implicitly asynchronous}} +@OtherGlobalActor(unsafe) func onOtherGlobalActorUnsafe() -> Int { 5 } // expected-note 2{{calls to global function 'onOtherGlobalActorUnsafe()' from outside of its actor context are implicitly asynchronous}} + +func someSlowOperation() async -> Int { 5 } + +func acceptOnSomeGlobalActor(_: @SomeGlobalActor () -> T) { } + +func testClosures() async { + // Global actors on synchronous closures become part of the type + let cl1 = { @SomeGlobalActor in + onSomeGlobalActor() + } + let _: Double = cl1 // expected-error{{cannot convert value of type '@SomeGlobalActor () -> Int' to specified type 'Double'}} + + // Global actors on async closures do not become part of the type + let cl2 = { @SomeGlobalActor in + await someSlowOperation() + } + let _: Double = cl2 // expected-error{{cannot convert value of type '() async -> Int' to specified type 'Double'}} + + // okay to be explicit + acceptOnSomeGlobalActor { @SomeGlobalActor in + onSomeGlobalActor() + } + + // Infer from context + acceptOnSomeGlobalActor { + onSomeGlobalActor() + } + + acceptOnSomeGlobalActor { () -> Int in + let i = onSomeGlobalActor() + return i + } + + acceptOnSomeGlobalActor { () -> Int in + let i = onOtherGlobalActorUnsafe() // expected-error{{global function 'onOtherGlobalActorUnsafe()' isolated to global actor 'OtherGlobalActor' can not be referenced from different global actor 'SomeGlobalActor' in a synchronous context}} + return i + } +} + +func testClosuresOld() { + acceptOnSomeGlobalActor { () -> Int in + let i = onSomeGlobalActor() + return i + } + + acceptOnSomeGlobalActor { () -> Int in + let i = onSomeGlobalActorUnsafe() + return i + } + + acceptOnSomeGlobalActor { () -> Int in + let i = onOtherGlobalActor() // expected-error{{global function 'onOtherGlobalActor()' isolated to global actor 'OtherGlobalActor' can not be referenced from different global actor 'SomeGlobalActor' in a synchronous context}} + return i + } + + acceptOnSomeGlobalActor { () -> Int in + let i = onOtherGlobalActorUnsafe() + return i + } + + acceptOnSomeGlobalActor { @SomeGlobalActor () -> Int in + let i = onOtherGlobalActorUnsafe() // expected-error{{global function 'onOtherGlobalActorUnsafe()' isolated to global actor 'OtherGlobalActor' can not be referenced from different global actor 'SomeGlobalActor' in a synchronous context}} + return i + } +} + +// Test conversions that happen in various structural positions. +struct X { } // expected-note{{arguments to generic parameter 'T' ('() -> Void' and '@SomeGlobalActor () -> Void') are expected to be equal}} + +func f(_: (@SomeGlobalActor () -> Void)?) { } + +func g(fn: (() -> Void)?) { + f(fn) +} + +func f2(_ x: X<@SomeGlobalActor () -> Void>) { + g2(x) // expected-error{{converting function value of type '@SomeGlobalActor () -> Void' to '() -> Void' loses global actor 'SomeGlobalActor'}} +} +func g2(_ x: X<() -> Void>) { + f2(x) // expected-error{{cannot convert value of type 'X<() -> Void>' to expected argument type 'X<@SomeGlobalActor () -> Void>'}} +} diff --git a/test/Constraints/fixes.swift b/test/Constraints/fixes.swift index 98f9624122788..4221d7b6cdec2 100644 --- a/test/Constraints/fixes.swift +++ b/test/Constraints/fixes.swift @@ -359,5 +359,5 @@ func testKeyPathSubscriptArgFixes(_ fn: @escaping () -> Int) { func sr12426(a: Any, _ str: String?) { a == str // expected-error {{binary operator '==' cannot be applied to operands of type 'Any' and 'String?'}} - // expected-note@-1 {{overloads for '==' exist with these partially matching parameter lists: (CodingUserInfoKey, CodingUserInfoKey), (String, String)}} + // expected-note@-1 {{overloads for '==' exist with these partially matching parameter lists: (String, String)}} } diff --git a/test/Constraints/optional.swift b/test/Constraints/optional.swift index 5da356f8267e5..0efb211ba6f95 100644 --- a/test/Constraints/optional.swift +++ b/test/Constraints/optional.swift @@ -425,8 +425,9 @@ func test_force_unwrap_not_being_too_eager() { // rdar://problem/57097401 func invalidOptionalChaining(a: Any) { - a == "="? // expected-error {{binary operator '==' cannot be applied to operands of type 'Any' and 'String?'}} - // expected-note@-1 {{overloads for '==' exist with these partially matching parameter lists: (CodingUserInfoKey, CodingUserInfoKey), (FloatingPointSign, FloatingPointSign), (String, String), (Unicode.CanonicalCombiningClass, Unicode.CanonicalCombiningClass)}} + a == "="? // expected-error {{cannot use optional chaining on non-optional value of type 'String'}} + // expected-error@-1 {{protocol 'Any' as a type cannot conform to 'Equatable'}} + // expected-note@-2 {{requirement from conditional conformance of 'Any?' to 'Equatable'}} expected-note@-2 {{only concrete types such as structs, enums and classes can conform to protocols}} } // SR-12309 - Force unwrapping 'nil' compiles without warning @@ -459,3 +460,27 @@ func sr_12309() { return (((nil))) // Ok } } + +// rdar://75146811 - crash due to incrrect inout type +func rdar75146811() { + func test(_: UnsafeMutablePointer) {} + func test_tuple(_: UnsafeMutablePointer, x: Int) {} + func test_named(x: UnsafeMutablePointer) {} + + var arr: [Double]! = [] + + test(&arr) // expected-error {{cannot convert value of type '[Double]?' to expected argument type 'Double'}} + test((&arr)) // expected-error {{use of extraneous '&'}} + // expected-error@-1 {{cannot convert value of type '[Double]?' to expected argument type 'Double'}} + test(&(arr)) // expected-error {{cannot convert value of type '[Double]?' to expected argument type 'Double'}} + + test_tuple(&arr, x: 0) // expected-error {{cannot convert value of type '[Double]?' to expected argument type 'Double'}} + test_tuple((&arr), x: 0) // expected-error {{use of extraneous '&'}} + // expected-error@-1 {{cannot convert value of type '[Double]?' to expected argument type 'Double'}} + test_tuple(&(arr), x: 0) // expected-error {{cannot convert value of type '[Double]?' to expected argument type 'Double'}} + + test_named(x: &arr) // expected-error {{cannot convert value of type '[Double]?' to expected argument type 'Double'}} + test_named(x: (&arr)) // expected-error {{use of extraneous '&'}} + // expected-error@-1 {{cannot convert value of type '[Double]?' to expected argument type 'Double'}} + test_named(x: &(arr)) // expected-error {{cannot convert value of type '[Double]?' to expected argument type 'Double'}} +} diff --git a/test/DebugInfo/async-args.swift b/test/DebugInfo/async-args.swift index dd7aeefa29404..74af407485c1f 100644 --- a/test/DebugInfo/async-args.swift +++ b/test/DebugInfo/async-args.swift @@ -2,7 +2,6 @@ // RUN: -module-name M -enable-experimental-concurrency \ // RUN: -parse-as-library | %FileCheck %s // REQUIRES: concurrency -// UNSUPPORTED: CPU=arm64e func use(_ t: T) {} func forceSplit() async { @@ -10,25 +9,24 @@ func forceSplit() async { func withGenericArg(_ msg: T) async { // This odd debug info is part of a contract with CoroSplit/CoroFrame to fix // this up after coroutine splitting. - // CHECK-LABEL: {{^define .*}} @"$s1M14withGenericArgyyxYlF"(%swift.task* %0, %swift.executor* %1, %swift.context* swiftasync %2) - // CHECK: call void @llvm.dbg.declare(metadata %swift.context* %2, + // CHECK-LABEL: {{^define .*}} @"$s1M14withGenericArgyyxYlF"(%swift.context* swiftasync %0 + // CHECK: call void @llvm.dbg.declare(metadata %swift.context* %0, // CHECK-SAME: metadata ![[MSG:[0-9]+]], metadata !DIExpression( // CHECK-SAME: DW_OP_plus_uconst, {{[0-9]+}}, DW_OP_deref)) - // CHECK: call void @llvm.dbg.declare(metadata %swift.context* %2, + // CHECK: call void @llvm.dbg.declare(metadata %swift.context* %0, // CHECK-SAME: metadata ![[TAU:[0-9]+]], metadata !DIExpression( // CHECK-SAME: DW_OP_plus_uconst, {{[0-9]+}})) await forceSplit() - // CHECK-LABEL: {{^define .*}} @"$s1M14withGenericArgyyxYlF.resume.0"(i8* %0, i8* %1, i8* swiftasync %2) - // CHECK: call void @llvm.dbg.declare(metadata i8* %2, - // CHECK-SAME: metadata ![[TAU_R:[0-9]+]], metadata !DIExpression( + // CHECK-LABEL: {{^define .*}} @"$s1M14withGenericArgyyxYlF.resume.0"(i8* swiftasync %0) + // CHECK: call void @llvm.dbg.declare(metadata i8* %0, + // CHECK-SAME: metadata ![[MSG_R:[0-9]+]], metadata !DIExpression(DW_OP_deref, // CHECK-SAME: DW_OP_plus_uconst, [[OFFSET:[0-9]+]], - // CHECK-SAME: DW_OP_plus_uconst, {{[0-9]+}})) - // CHECK: call void @llvm.dbg.declare(metadata i8* %2, - // CHECK-SAME: metadata ![[MSG_R:[0-9]+]], metadata !DIExpression( - // CHECK-SAME: DW_OP_plus_uconst, [[OFFSET]], // CHECK-SAME: DW_OP_plus_uconst, {{[0-9]+}}, DW_OP_deref)) - + // CHECK: call void @llvm.dbg.declare(metadata i8* %0, + // CHECK-SAME: metadata ![[TAU_R:[0-9]+]], metadata !DIExpression(DW_OP_deref, + // CHECK-SAME: DW_OP_plus_uconst, [[OFFSET]], + // CHECK-SAME: DW_OP_plus_uconst, {{[0-9]+}})) use(msg) } // CHECK-LABEL: {{^define }} @@ -39,6 +37,5 @@ func withGenericArg(_ msg: T) async { } // CHECK: ![[MSG]] = !DILocalVariable(name: "msg", arg: 1, // CHECK: ![[TAU]] = !DILocalVariable(name: "$\CF\84_0_0", -// CHECK: ![[TAU_R]] = !DILocalVariable(name: "$\CF\84_0_0", // CHECK: ![[MSG_R]] = !DILocalVariable(name: "msg", arg: 1, - +// CHECK: ![[TAU_R]] = !DILocalVariable(name: "$\CF\84_0_0", diff --git a/test/DebugInfo/async-direct-arg.swift b/test/DebugInfo/async-direct-arg.swift index d984aa3f95f42..3ff071b4137ab 100644 --- a/test/DebugInfo/async-direct-arg.swift +++ b/test/DebugInfo/async-direct-arg.swift @@ -3,7 +3,7 @@ // RUN: -parse-as-library | %FileCheck %s --check-prefix=CHECK // REQUIRES: concurrency -// UNSUPPORTED: CPU=arm64e +// REQUIRES: rdar74588568 // Test that x is described as a direct dbg.declare of the incoming function // argument. @@ -11,9 +11,9 @@ // CHECK-LABEL: define {{.*}} void @"$s1a3fibyS2iYF.resume.0" // CHECK: call void @llvm.dbg.declare // CHECK: call void @llvm.dbg.declare -// CHECK: call void @llvm.dbg.declare(metadata {{.*}}%2, metadata ![[X0:[0-9]+]], {{.*}}!DIExpression(DW_OP +// CHECK: call void @llvm.dbg.declare(metadata {{.*}}%0, metadata ![[X0:[0-9]+]], {{.*}}!DIExpression(DW_OP // CHECK-LABEL: define {{.*}} void @"$s1a3fibyS2iYF.resume.1" -// FIXME: call void @llvm.dbg.declare(metadata {{.*}}%2, metadata ![[X1:[0-9]+]], {{.*}}!DIExpression(DW_OP +// FIXME: call void @llvm.dbg.declare(metadata {{.*}}%0, metadata ![[X1:[0-9]+]], {{.*}}!DIExpression(DW_OP // CHECK: ![[X0]] = !DILocalVariable(name: "x" // FIXME: ![[X1]] = !DILocalVariable(name: "x" diff --git a/test/DebugInfo/async-let-await.swift b/test/DebugInfo/async-let-await.swift index 19b46dc9dce34..3b4132a54a827 100644 --- a/test/DebugInfo/async-let-await.swift +++ b/test/DebugInfo/async-let-await.swift @@ -1,6 +1,6 @@ // RUN: %target-swift-frontend %s -emit-ir -g -o - \ // RUN: -module-name M -enable-experimental-concurrency \ -// RUN: -parse-as-library | %FileCheck %s +// RUN: -parse-as-library | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize // REQUIRES: concurrency // UNSUPPORTED: CPU=arm64e @@ -12,7 +12,7 @@ public func getVegetables() async -> [String] { public func chopVegetables() async throws -> [String] { let veggies = await getVegetables() // CHECK-NOT: {{^define }} - // CHECK: call void @llvm.dbg.declare(metadata i8* %2, metadata ![[V:[0-9]+]], metadata !DIExpression(DW_OP_deref + // CHECK: call void @llvm.dbg.declare(metadata i8* %0, metadata ![[V:[0-9]+]], metadata !DIExpression(DW_OP_deref // CHECK: ![[V]] = !DILocalVariable(name: "veggies" return veggies.map { "chopped \($0)" } } diff --git a/test/DebugInfo/async-lifetime-extension.swift b/test/DebugInfo/async-lifetime-extension.swift index eb39e2b8a5133..ee59d8e4f4904 100644 --- a/test/DebugInfo/async-lifetime-extension.swift +++ b/test/DebugInfo/async-lifetime-extension.swift @@ -10,16 +10,16 @@ // CHECK-LABEL: define {{.*}} void @"$s1a4fiboyS2iYF.resume.0" // CHECK-NEXT: entryresume.0: -// CHECK-NEXT: call void @llvm.dbg.declare(metadata {{.*}}%2, metadata ![[RHS:[0-9]+]], {{.*}}!DIExpression(DW_OP -// CHECK-NEXT: call void @llvm.dbg.declare(metadata {{.*}}%2, metadata ![[R:[0-9]+]], {{.*}}!DIExpression(DW_OP -// CHECK-NEXT: call void @llvm.dbg.declare(metadata {{.*}}%2, metadata ![[LHS:[0-9]+]], {{.*}}!DIExpression(DW_OP -// CHECK-NEXT: call void @llvm.dbg.declare(metadata {{.*}}%2, metadata ![[N:[0-9]+]], {{.*}}!DIExpression(DW_OP +// CHECK-NEXT: call void @llvm.dbg.declare(metadata {{.*}}%0, metadata ![[RHS:[0-9]+]], {{.*}}!DIExpression(DW_OP +// CHECK-NEXT: call void @llvm.dbg.declare(metadata {{.*}}%0, metadata ![[LHS:[0-9]+]], {{.*}}!DIExpression(DW_OP +// CHECK-NEXT: call void @llvm.dbg.declare(metadata {{.*}}%0, metadata ![[N:[0-9]+]], {{.*}}!DIExpression(DW_OP +// CHECK-NEXT: call void @llvm.dbg.declare(metadata {{.*}}%0, metadata ![[R:[0-9]+]], {{.*}}!DIExpression(DW_OP // CHECK-NOT: {{ ret }} // CHECK: call void asm sideeffect "" // CHECK: ![[RHS]] = !DILocalVariable(name: "rhs" -// CHECK: ![[R]] = !DILocalVariable(name: "retval" // CHECK: ![[LHS]] = !DILocalVariable(name: "lhs" // CHECK: ![[N]] = !DILocalVariable(name: "n" +// CHECK: ![[R]] = !DILocalVariable(name: "retval" public func fibo(_ n: Int) async -> Int { var retval = n if retval < 2 { return 1 } diff --git a/test/DebugInfo/async-local-var.swift b/test/DebugInfo/async-local-var.swift index b63a670c4e8b4..cda251dcd65f0 100644 --- a/test/DebugInfo/async-local-var.swift +++ b/test/DebugInfo/async-local-var.swift @@ -17,7 +17,7 @@ public func makeDinner() async throws -> String { // CHECK-LABEL: define {{.*}} void @"$s1a10makeDinnerSSyYKF.resume.0" // CHECK-NEXT: entryresume.0: // CHECK-NOT: {{ ret }} -// CHECK: call void @llvm.dbg.declare(metadata {{.*}}%2, metadata ![[LOCAL:[0-9]+]], {{.*}}!DIExpression(DW_OP_deref +// CHECK: call void @llvm.dbg.declare(metadata {{.*}}%0, metadata ![[LOCAL:[0-9]+]], {{.*}}!DIExpression(DW_OP_deref // CHECK: ![[LOCAL]] = !DILocalVariable(name: "local" return local } diff --git a/test/Demangle/Inputs/manglings.txt b/test/Demangle/Inputs/manglings.txt index f7630970fac4e..0bcabcc2a8cfe 100644 --- a/test/Demangle/Inputs/manglings.txt +++ b/test/Demangle/Inputs/manglings.txt @@ -94,6 +94,7 @@ _$SSC3fooyS2d_SdtFTO ---> {T:_$SSC3fooyS2d_SdtF} @nonobjc __C_Synthesized.foo(Sw _$S3foo3barC3bas3zimyAaEC_tFTo ---> {T:_$S3foo3barC3bas3zimyAaEC_tF,C} @objc foo.bar.bas(zim: foo.zim) -> () _$SSC3fooyS2d_SdtFTO ---> {T:_$SSC3fooyS2d_SdtF} @nonobjc __C_Synthesized.foo(Swift.Double, Swift.Double) -> Swift.Double _$sTA.123 ---> {T:} partial apply forwarder with unmangled suffix ".123" +$s4main3fooyySiFyyXEfU_TA.1 ---> {T:} closure #1 () -> () in main.foo(Swift.Int) -> ()partial apply forwarder with unmangled suffix ".1" _TTDFC3foo3bar3basfT3zimCS_3zim_T_ ---> dynamic foo.bar.bas(zim: foo.zim) -> () _TFC3foo3bar3basfT3zimCS_3zim_T_ ---> foo.bar.bas(zim: foo.zim) -> () _TF3foooi1pFTCS_3barVS_3bas_OS_3zim ---> foo.+ infix(foo.bar, foo.bas) -> foo.zim @@ -388,3 +389,7 @@ $sS2f8mangling3FooV13TangentVectorVIegydd_SfAESfIegydd_TJOp ---> autodiff self-r $s13test_mangling3fooyS2f_S2ftFWJrSpSr ---> reverse-mode differentiability witness for test_mangling.foo(Swift.Float, Swift.Float, Swift.Float) -> Swift.Float with respect to parameters {0} and results {0} $s13test_mangling3fooyS2f_xq_t16_Differentiation14DifferentiableR_r0_lFAcDRzAcDR_r0_lWJrUSSpSr ---> reverse-mode differentiability witness for test_mangling.foo(Swift.Float, A, B) -> Swift.Float with respect to parameters {1, 2} and results {0} with $s5async1hyyS2iJXEF ---> async.h(@concurrent (Swift.Int) -> Swift.Int) -> () +$s12create_pa_f2Tw_ ---> (0) thunk for non-constant partial apply in create_pa_f2 +$s12create_pa_f2Tw0_ ---> (1) thunk for non-constant partial apply in create_pa_f2 +$s5Actor02MyA0C17testAsyncFunctionyyYKFTY0_ ---> (1) suspend resume partial function for Actor.MyActor.testAsyncFunction() async throws -> () +$s5Actor02MyA0C17testAsyncFunctionyyYKFTQ1_ ---> (2) await resume partial function for Actor.MyActor.testAsyncFunction() async throws -> () diff --git a/test/Driver/linker-args-order-linux.swift b/test/Driver/linker-args-order-linux.swift index 9ee7a634c2c6d..aea4aa0a28299 100644 --- a/test/Driver/linker-args-order-linux.swift +++ b/test/Driver/linker-args-order-linux.swift @@ -6,4 +6,4 @@ print("hello world!") // RUN: %target-swiftc_driver -driver-print-jobs -static-stdlib -o %t/static-stdlib %s -Xlinker --no-allow-multiple-definition 2>&1| %FileCheck %s // CHECK: {{.*}}/swift-frontend -frontend -c -primary-file {{.*}}/linker-args-order-linux.swift // CHECK: {{.*}}/swift-autolink-extract{{.*}} -// CHECK: {{.*}}swiftrt.o /{{.*}}/linker-args-order-linux-{{[a-z0-9]+}}.o @/{{.*}}/linker-args-order-linux-{{[a-z0-9]+}}.autolink {{.*}} @{{.*}}/static-stdlib-args.lnk {{.*}} -Xlinker --no-allow-multiple-definition +// CHECK: {{.*}}swiftrt.o /{{.*}}/linker-args-order-linux-{{[a-z0-9]+}}.o -Xlinker --start-group @/{{.*}}/linker-args-order-linux-{{[a-z0-9]+}}.autolink -Xlinker --end-group {{.*}} @{{.*}}/static-stdlib-args.lnk {{.*}} -Xlinker --no-allow-multiple-definition diff --git a/test/Generics/conditional_requirement_inference.swift b/test/Generics/conditional_requirement_inference.swift new file mode 100644 index 0000000000000..92b523a9115ba --- /dev/null +++ b/test/Generics/conditional_requirement_inference.swift @@ -0,0 +1,53 @@ +// RUN: %target-typecheck-verify-swift +// RUN: not %target-swift-frontend -typecheck -debug-generic-signatures %s 2>&1 | %FileCheck %s + + +// Valid example +struct EquatableBox { + // CHECK: Generic signature: , U : Equatable> + func withArray(_: U) where T == Array {} +} + + +// A very elaborate invalid example (see comment in mergeP1AndP2()) +struct G {} + +protocol P {} +extension G : P where T : P {} + +protocol P1 { + associatedtype T + associatedtype U where U == G + associatedtype R : P1 +} + +protocol P2 { + associatedtype U : P + associatedtype R : P2 +} + +func takesP(_: T.Type) {} +// expected-note@-1 {{where 'T' = 'T.T'}} +// expected-note@-2 {{where 'T' = 'T.R.T'}} +// expected-note@-3 {{where 'T' = 'T.R.R.T'}} +// expected-note@-4 {{where 'T' = 'T.R.R.R.T'}} + +// CHECK: Generic signature: +func mergeP1AndP2(_: T) { + // P1 implies that T.(R)*.U == G, and P2 implies that T.(R)*.U : P. + // + // These together would seem to imply that G : P, therefore + // the conditional conformance G : P should imply that T.(R)*.T : P. + // + // However, this would require us to infer an infinite number of + // conformance requirements in the signature of mergeP1AndP2() of the + // form T.(R)*.T : P. + // + // Since we're unable to represent that, make sure that a) we don't crash, + // b) we reject the conformance T.(R)*.T : P. + + takesP(T.T.self) // expected-error {{global function 'takesP' requires that 'T.T' conform to 'P'}} + takesP(T.R.T.self) // expected-error {{global function 'takesP' requires that 'T.R.T' conform to 'P'}} + takesP(T.R.R.T.self) // expected-error {{global function 'takesP' requires that 'T.R.R.T' conform to 'P'}} + takesP(T.R.R.R.T.self) // expected-error {{global function 'takesP' requires that 'T.R.R.R.T' conform to 'P'}} +} \ No newline at end of file diff --git a/test/Generics/rdar65263302.swift b/test/Generics/rdar65263302.swift new file mode 100644 index 0000000000000..caafdd610c6b6 --- /dev/null +++ b/test/Generics/rdar65263302.swift @@ -0,0 +1,24 @@ +// RUN: %target-swift-frontend -typecheck -debug-generic-signatures %s 2>&1 | %FileCheck %s +// RUN: %target-swift-frontend -verify -emit-ir %s + +public protocol P { + associatedtype Element +} + +public class C: P { + public typealias Element = O.Element +} + +// CHECK: Generic signature: , O : P, E : P, O.Element == E.Element> +public func toe1(_: T, _: O, _: E, _: T.Element) + where T : P, // expected-warning {{redundant conformance constraint 'T': 'P'}} + O : P, + O.Element == T.Element, + T : C {} // expected-note {{conformance constraint 'T': 'P' implied here}} + +// CHECK: Generic signature: , O : P, E : P, O.Element == E.Element> +public func toe2(_: T, _: O, _: E, _: T.Element) + where O : P, + O.Element == T.Element, + T : C {} + diff --git a/test/Generics/rdar75171977.swift b/test/Generics/rdar75171977.swift new file mode 100644 index 0000000000000..52b7e87770115 --- /dev/null +++ b/test/Generics/rdar75171977.swift @@ -0,0 +1,17 @@ +// RUN: %target-swift-frontend -verify -emit-ir %s + +public protocol P1 {} + +public protocol P2 { + associatedtype A : P1 + associatedtype B : P2 + func f() +} + +public extension P2 where B.A == A { + func f() {} +} + +public class C: P2 { + public typealias A = B.A +} diff --git a/test/Generics/validate_stdlib_generic_signatures.swift b/test/Generics/validate_stdlib_generic_signatures.swift index eb905b0107c37..8c10241634628 100644 --- a/test/Generics/validate_stdlib_generic_signatures.swift +++ b/test/Generics/validate_stdlib_generic_signatures.swift @@ -1,9 +1,4 @@ // Verifies that all of the generic signatures in the standard library are // minimal and canonical. -// RUN: not %target-typecheck-verify-swift -verify-generic-signatures Swift 2>&1 | %FileCheck %s - -// CHECK-NOT: error: -// CHECK-DAG: error: unexpected error produced: generic requirement 'Ï„_0_0.Index : Strideable' is redundant in <Ï„_0_0 where Ï„_0_0 : RandomAccessCollection, Ï„_0_0.Index : Strideable, Ï„_0_0.Indices == Range<Ï„_0_0.Index>, Ï„_0_0.Index.Stride == Int> -// CHECK-DAG: error: diagnostic produced elsewhere: generic requirement 'Ï„_0_0.Index : Strideable' is redundant in <Ï„_0_0 where Ï„_0_0 : RandomAccessCollection, Ï„_0_0.Index : Strideable, Ï„_0_0.Indices == Range<Ï„_0_0.Index>, Ï„_0_0.Index.Stride == Int> -// CHECK-NOT: error: +// RUN: %target-typecheck-verify-swift -verify-generic-signatures Swift diff --git a/test/IRGen/async.swift b/test/IRGen/async.swift index c57ca7458ba88..87552fef0a86a 100644 --- a/test/IRGen/async.swift +++ b/test/IRGen/async.swift @@ -16,8 +16,8 @@ public class SomeClass {} @_silgen_name("swift_task_future_wait") public func task_future_wait(_ task: __owned SomeClass) async throws -> Int -// CHECK: define{{.*}} swift{{(tail)?}}cc void @"$s5async8testThisyyAA9SomeClassCnYF"(%swift.task* %0, %swift.executor* %1, %swift.context* swiftasync %2) -// CHECK-64: call swiftcc i8* @swift_task_alloc(%swift.task* %{{[0-9]+}}, i64 64) +// CHECK: define{{.*}} swift{{(tail)?}}cc void @"$s5async8testThisyyAA9SomeClassCnYF"(%swift.context* swiftasync %0{{.*}} +// CHECK-64: call swiftcc i8* @swift_task_alloc(i64 64) // CHECK: {{(must)?}}tail call swift{{(tail)?}}cc void @swift_task_future_wait( public func testThis(_ task: __owned SomeClass) async { do { diff --git a/test/IRGen/async/Inputs/class_open-1instance-void_to_void.swift b/test/IRGen/async/Inputs/class_open-1instance-void_to_void.swift index 889b3bf7620d1..19529d79cef65 100644 --- a/test/IRGen/async/Inputs/class_open-1instance-void_to_void.swift +++ b/test/IRGen/async/Inputs/class_open-1instance-void_to_void.swift @@ -6,8 +6,8 @@ func printGeneric(_ t: T) { // CHECK-LL: @"$s4main6call_fyyAA1CCYFTu" = {{(dllexport )?}}{{(protected )?}}global %swift.async_func_pointer // CHECK-LL: @"$s4main1CC1fyyYFTu" = {{(dllexport )?}}{{(protected )?}}global %swift.async_func_pointer -// CHECK-LL: define {{(dllexport )?}}{{(protected )?}}swift{{(tail)?}}cc void @"$s4main6call_fyyAA1CCYF"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} -// CHECK-LL: define {{(dllexport )?}}{{(protected )?}}swift{{(tail)?}}cc void @"$s4main1CC1fyyYF"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define {{(dllexport )?}}{{(protected )?}}swift{{(tail)?}}cc void @"$s4main6call_fyyAA1CCYF"( +// CHECK-LL: define {{(dllexport )?}}{{(protected )?}}swift{{(tail)?}}cc void @"$s4main1CC1fyyYF"( public func call_f(_ c: C) async { print("entering call_f") await c.f() diff --git a/test/IRGen/async/builtins.sil b/test/IRGen/async/builtins.sil index c04df9a4d6f9b..9c6cd2ad30af9 100644 --- a/test/IRGen/async/builtins.sil +++ b/test/IRGen/async/builtins.sil @@ -8,12 +8,10 @@ sil_stage canonical import Builtin import Swift -// CHECK-LABEL: define hidden swift{{(tail)?}}cc void @get_task(%swift.task* %0, %swift.executor* %1, %swift.context* swiftasync %2) +// CHECK-LABEL: define hidden swift{{(tail)?}}cc void @get_task(%swift.context* swiftasync %0) sil hidden [ossa] @get_task : $@async @convention(thin) () -> @owned Builtin.NativeObject { bb0: - // CHECK: [[TASKLOC:%.*]] = alloca %swift.task* - // CHECK: store %swift.task* %0, %swift.task** [[TASKLOC]] - // CHECK: [[TASK:%.*]] = load %swift.task*, %swift.task** [[TASKLOC]] + // CHECK: [[TASK:%.*]] = call swiftcc %swift.task* @swift_task_getCurrent() // CHECK: [[TASKRC:%.*]] = bitcast %swift.task* [[TASK]] to %swift.refcounted* %0 = builtin "getCurrentAsyncTask"() : $Builtin.NativeObject // CHECK-NEXT: [[TASK_COPY:%.*]] = call %swift.refcounted* @swift_retain(%swift.refcounted* returned [[TASKRC]]) @@ -33,42 +31,28 @@ bb0(%0 : @guaranteed $Builtin.NativeObject): } // CHECK-LABEL: define hidden swift{{(tail)?}}cc void @launch_future -sil hidden [ossa] @launch_future : $@convention(method) (Int, Optional, @guaranteed @async @callee_owned @substituted <Ï„_0_0> () -> (@out Ï„_0_0, @error Error) for , @in_guaranteed T) -> () { -bb0(%0 : $Int, %1: @unowned $Optional, %2: @guaranteed $@async @callee_owned @substituted <Ï„_0_0> () -> (@out Ï„_0_0, @error Error) for , %3: $*T): - %copy = copy_value %1 : $Optional - // CHECK-32: [[TEMP:%.*]] = inttoptr i32 %1 to %swift.refcounted* - // CHECK-64: [[TEMP:%.*]] = inttoptr i64 %1 to %swift.refcounted* - %4 = begin_borrow %copy : $Optional - %5 = copy_value %2 : $@async @callee_owned @substituted <Ï„_0_0> () -> (@out Ï„_0_0, @error Error) for - // CHECK: call %swift.refcounted* @swift_retain(%swift.refcounted* returned [[TEMP]]) - // CHECK: call %swift.refcounted* @swift_retain(%swift.refcounted* returned [[FN_CONTEXT:%.*]]) +sil hidden [ossa] @launch_future : $@convention(method) (Int, @guaranteed @async @callee_owned @substituted <Ï„_0_0> () -> (@out Ï„_0_0, @error Error) for , @in_guaranteed T) -> () { +bb0(%0 : $Int, %1: @guaranteed $@async @callee_owned @substituted <Ï„_0_0> () -> (@out Ï„_0_0, @error Error) for , %3: $*T): + %5 = copy_value %1 : $@async @callee_owned @substituted <Ï„_0_0> () -> (@out Ï„_0_0, @error Error) for + // CHECK: call %swift.refcounted* @swift_retain(%swift.refcounted* returned [[FN_CONTEXT:%2]]) %9 = metatype $@thick T.Type %10 = init_existential_metatype %9 : $@thick T.Type, $@thick Any.Type // CHECK: [[NEW_TASK_AND_CONTEXT:%.*]] = call swift{{(tail)?}}cc %swift.async_task_and_context @swift_task_create_future( - %20 = builtin "createAsyncTaskFuture"(%0 : $Int, %4 : $Optional, %10 : $@thick Any.Type, %5 : $@async @callee_owned @substituted <Ï„_0_0> () -> (@out Ï„_0_0, @error Error) for ) : $(Builtin.NativeObject, Builtin.RawPointer) - end_borrow %4 : $Optional - destroy_value %copy : $Optional + %20 = builtin "createAsyncTaskFuture"(%0 : $Int, %10 : $@thick Any.Type, %5 : $@async @callee_owned @substituted <Ï„_0_0> () -> (@out Ï„_0_0, @error Error) for ) : $(Builtin.NativeObject, Builtin.RawPointer) destroy_value %20 : $(Builtin.NativeObject, Builtin.RawPointer) %21 = tuple () return %21 : $() } // CHECK-LABEL: define hidden swift{{(tail)?}}cc void @launch_void_future -sil hidden [ossa] @launch_void_future : $@convention(method) (Int, Optional, @guaranteed @async @callee_owned @substituted <Ï„_0_0> () -> (@out Ï„_0_0, @error Error) for <()>) -> () { -bb0(%0 : $Int, %1: @unowned $Optional, %2: @guaranteed $@async @callee_owned @substituted <Ï„_0_0> () -> (@out Ï„_0_0, @error Error) for <()>): - %copy = copy_value %1 : $Optional - %4 = begin_borrow %copy : $Optional - %5 = copy_value %2 : $@async @callee_owned @substituted <Ï„_0_0> () -> (@out Ï„_0_0, @error Error) for <()> - // CHECK-32: [[TEMP:%.*]] = inttoptr i32 %1 to %swift.refcounted* - // CHECK-64: [[TEMP:%.*]] = inttoptr i64 %1 to %swift.refcounted* - // CHECK: call %swift.refcounted* @swift_retain(%swift.refcounted* returned [[TEMP]]) - // CHECK: call %swift.refcounted* @swift_retain(%swift.refcounted* returned [[FN_CONTEXT:%.*]]) +sil hidden [ossa] @launch_void_future : $@convention(method) (Int, @guaranteed @async @callee_owned @substituted <Ï„_0_0> () -> (@out Ï„_0_0, @error Error) for <()>) -> () { +bb0(%0 : $Int, %1: @guaranteed $@async @callee_owned @substituted <Ï„_0_0> () -> (@out Ï„_0_0, @error Error) for <()>): + %5 = copy_value %1 : $@async @callee_owned @substituted <Ï„_0_0> () -> (@out Ï„_0_0, @error Error) for <()> + // CHECK: call %swift.refcounted* @swift_retain(%swift.refcounted* returned [[FN_CONTEXT:%2]]) %8 = metatype $@thick ().Type // user: %9 %9 = init_existential_metatype %8 : $@thick ().Type, $@thick Any.Type // user: %10 // CHECK: [[NEW_TASK_AND_CONTEXT:%.*]] = call swift{{(tail)?}}cc %swift.async_task_and_context @swift_task_create_future( - %20 = builtin "createAsyncTaskFuture"<()>(%0 : $Int, %4 : $Optional, %9 : $@thick Any.Type, %5 : $@async @callee_owned @substituted <Ï„_0_0> () -> (@out Ï„_0_0, @error Error) for <()>) : $(Builtin.NativeObject, Builtin.RawPointer) - end_borrow %4 : $Optional - destroy_value %copy : $Optional + %20 = builtin "createAsyncTaskFuture"<()>(%0 : $Int, %9 : $@thick Any.Type, %5 : $@async @callee_owned @substituted <Ï„_0_0> () -> (@out Ï„_0_0, @error Error) for <()>) : $(Builtin.NativeObject, Builtin.RawPointer) destroy_value %20 : $(Builtin.NativeObject, Builtin.RawPointer) %21 = tuple () return %21 : $() diff --git a/test/IRGen/async/class_resilience.swift b/test/IRGen/async/class_resilience.swift index 69878ad9aad27..aac4480fd7bca 100644 --- a/test/IRGen/async/class_resilience.swift +++ b/test/IRGen/async/class_resilience.swift @@ -41,14 +41,14 @@ open class MyBaseClass { // CHECK-LABEL: @"$s16class_resilience9MyDerivedCMn" = hidden constant // CHECK-SAME: %swift.async_func_pointer* @"$s16class_resilience9MyDerivedC4waitSiyYF010resilient_A09BaseClassCADxyYFTVTu" -// CHECK-LABEL: define {{(dllexport )?}}{{(protected )?}}swift{{(tail)?}}cc void @"$s16class_resilience14callsAwaitableyx010resilient_A09BaseClassCyxGYlF"(%swift.task* %0, %swift.executor* %1, %swift.context* swiftasync %2) +// CHECK-LABEL: define {{(dllexport )?}}{{(protected )?}}swift{{(tail)?}}cc void @"$s16class_resilience14callsAwaitableyx010resilient_A09BaseClassCyxGYlF"(%swift.opaque* noalias nocapture %0, %swift.context* swiftasync %1{{.*}}) // CHECK: %swift.async_func_pointer* @"$s15resilient_class9BaseClassC4waitxyYFTjTu" // CHECK: ret void public func callsAwaitable(_ c: BaseClass) async -> T { return await c.wait() } -// CHECK-LABEL: define {{(dllexport )?}}{{(protected )?}}swift{{(tail)?}}cc void @"$s16class_resilience11MyBaseClassC4waitxyYFTj"(%swift.task* %0, %swift.executor* %1, %swift.context* swiftasync %2) #0 { +// CHECK-LABEL: define {{(dllexport )?}}{{(protected )?}}swift{{(tail)?}}cc void @"$s16class_resilience11MyBaseClassC4waitxyYFTj"(%swift.opaque* noalias nocapture %0, %swift.context* swiftasync %1, %T16class_resilience11MyBaseClassC* swiftself %2) #0 { class MyDerived : BaseClass { override func wait() async -> Int { diff --git a/test/IRGen/async/get_async_continuation.sil b/test/IRGen/async/get_async_continuation.sil index 0bcce8854fca4..7cf3e3aa340da 100644 --- a/test/IRGen/async/get_async_continuation.sil +++ b/test/IRGen/async/get_async_continuation.sil @@ -14,15 +14,13 @@ bb0: } // CHECK-LABEL: define{{.*}} @async_continuation( -// CHECK: [[tsk_addr:%.*]] = alloca %swift.task* -// CHECK: [[exe_addr:%.*]] = alloca %swift.executor* // CHECK: [[ctxt_addr:%.*]] = alloca %swift.context* // CHECK: [[cont_context:%.*]] = alloca %swift.async_continuation_context // CHECK: [[result_storage:%.*]] = alloca i32 // CHECK: call token @llvm.coro.id.async // CHECK: call i8* @llvm.coro.begin( // Create a Builtin.RawUnsafeContinuation. -// CHECK: [[tsk:%.*]] = load %swift.task*, %swift.task** [[tsk_addr]] +// CHECK: [[tsk:%.*]] = call swiftcc %swift.task* @swift_task_getCurrent() // CHECK: [[continuation:%.*]] = bitcast %swift.task* [[tsk]] to i8* // Initialize the async continuation context. // CHECK: [[context_addr:%.*]] = getelementptr inbounds %swift.async_continuation_context, %swift.async_continuation_context* [[cont_context]], i32 0, i32 0 @@ -41,9 +39,6 @@ bb0: // CHECK: [[result_addr:%.*]] = getelementptr inbounds %swift.async_continuation_context, %swift.async_continuation_context* [[cont_context]], i32 0, i32 3 // CHECK: [[result_storage_as_opaque:%.*]] = bitcast i32* [[result_storage]] to %swift.opaque* // CHECK: store %swift.opaque* [[result_storage_as_opaque]], %swift.opaque** [[result_addr]] -// CHECK: [[exectuor_addr:%.*]] = getelementptr inbounds %swift.async_continuation_context, %swift.async_continuation_context* [[cont_context]], i32 0, i32 4 -// CHECK: [[exe:%.*]] = load %swift.executor*, %swift.executor** [[exe_addr]] -// CHECK: store %swift.executor* [[exe]], %swift.executor** [[exectuor_addr]] // Initialize the async task with the continuation function and async continuation context. // CHECK: [[continuation_fn_addr:%.*]] = getelementptr inbounds %swift.task, %swift.task* [[tsk]], i32 0, i32 4 // CHECK: [[continuation_fn:%.*]] = call i8* @llvm.coro.async.resume() @@ -88,7 +83,7 @@ bb0: // CHECK: unreachable // CHECK: await.async.maybe.resume: -// CHECK: call { i8*, i8*, i8* } (i32, i8*, i8*, ...) @llvm.coro.suspend.async{{.*}}({{.*}} @__swift_async_resume_project_context +// CHECK: call { i8* } (i32, i8*, i8*, ...) @llvm.coro.suspend.async{{.*}}({{.*}} @__swift_async_resume_project_context // Abort if we are the first to arrive at the continuation point we must wait // on the await to arrive. // CHECK: [[first_at_sync_pt:%.*]] = cmpxchg {{(i64|i32)}}* [[synchronization_addr_before_await]], {{(i64|i32)}} 0, {{(i64|i32)}} 1 release acquire diff --git a/test/IRGen/async/hop_to_executor.sil b/test/IRGen/async/hop_to_executor.sil index d79a3d6c229be..fb8f9a6f09754 100644 --- a/test/IRGen/async/hop_to_executor.sil +++ b/test/IRGen/async/hop_to_executor.sil @@ -11,25 +11,14 @@ import _Concurrency final actor MyActor { } -// CHECK-LABEL: define{{.*}} void @test_simple(%swift.task* %0, %swift.executor* %1, %swift.context* swiftasync %2) -// CHECK: [[TASK_LOC:%[0-9]+]] = alloca %swift.task* -// CHECK: [[CTX:%[0-9]+]] = bitcast %swift.context* %2 -// CHECK-32: [[ACTOR_ADDR:%[0-9]+]] = getelementptr inbounds <{ %swift.context*, void (%swift.task*, %swift.executor*, %swift.context*)*, %swift.executor*, i32, %swift.error**, %T4test7MyActorC* }>, {{.*}} [[CTX]], i32 0, i32 5 -// CHECK-64: [[ACTOR_ADDR:%[0-9]+]] = getelementptr inbounds <{ %swift.context*, void (%swift.task*, %swift.executor*, %swift.context*)*, %swift.executor*, i32, [4 x i8], %swift.error**, %T4test7MyActorC* }>, {{.*}} [[CTX]], i32 0, i32 6 -// CHECK: [[ACTOR:%[0-9]+]] = load %T4test7MyActorC*, %T4test7MyActorC** [[ACTOR_ADDR]] +// CHECK-LABEL: define{{.*}} void @test_simple(%swift.context* swiftasync %0, %T4test7MyActorC* swiftself %1) +// CHECK: [[CTX:%[0-9]+]] = bitcast %swift.context* %0 // CHECK: [[RESUME:%[0-9]+]] = call i8* @llvm.coro.async.resume() -// CHECK: [[TASK:%[0-9]+]] = load %swift.task*, %swift.task** [[TASK_LOC]] -// CHECK-arm64e: [[RESUME_ADDR:%[0-9]+]] = getelementptr inbounds %swift.task, %swift.task* [[TASK]], i32 0, i32 4 -// CHECK-arm64e: [[RESUME_ADDR_INT:%[0-9]+]] = ptrtoint i8** [[RESUME_ADDR]] to i64 -// CHECK-arm64e: [[PTRAUTH_BLEND:%[0-9]+]] = call i64 @llvm.ptrauth.blend.i64(i64 [[RESUME_ADDR_INT]], i64 11330) -// CHECK-arm64e: [[RESUME_INT:%[0-9]+]] = ptrtoint i8* [[RESUME]] to i64 -// CHECK-arm64e: [[SIGNED_INT:%[0-9]+]] = call i64 @llvm.ptrauth.sign.i64(i64 [[RESUME_INT]], i32 0, i64 [[PTRAUTH_BLEND]]) -// CHECK-arm64e: [[SIGNED_RESUME:%[0-9]+]] = inttoptr i64 [[SIGNED_INT]] to i8* -// CHECK: [[CAST_ACTOR:%[0-9]+]] = bitcast %T4test7MyActorC* [[ACTOR]] to %swift.executor* -// CHECK-x86_64: call {{.*}} @llvm.coro.suspend.async{{.*}}(i32 2, i8* [[RESUME]], i8* bitcast (i8* (i8*)* @__swift_async_resume_get_context to i8*), i8* bitcast (void (i8*, %swift.executor*, %swift.task*, %swift.executor*, %swift.context*)* @__swift_suspend_point to i8*), i8* [[RESUME]], %swift.executor* [[CAST_ACTOR]], %swift.task* [[TASK]], %swift.executor* {{%[0-9]+}}, %swift.context* {{%[0-9]+}}) -// CHECK-arm64e: call {{.*}} @llvm.coro.suspend.async{{.*}}(i32 2, i8* [[RESUME]], i8* bitcast (i8* (i8*)* @__swift_async_resume_get_context to i8*), i8* bitcast (void (i8*, %swift.executor*, %swift.task*, %swift.executor*, %swift.context*)* @__swift_suspend_point to i8*), i8* [[SIGNED_RESUME]], %swift.executor* [[CAST_ACTOR]], %swift.task* [[TASK]], %swift.executor* {{%[0-9]+}}, %swift.context* {{%[0-9]+}}) -// CHECK: [[RET_CONTINUATION:%.*]] = bitcast void (%swift.task*, %swift.executor*, %swift.context*)* {{.*}} to i8* -// CHECK: call i1 (i8*, i1, ...) @llvm.coro.end.async(i8* {{.*}}, i1 false, void (i8*, %swift.task*, %swift.executor*, %swift.context*)* @[[TAIL_CALL_FUNC:.*]], i8* [[RET_CONTINUATION]] +// CHECK: [[CAST_ACTOR:%[0-9]+]] = bitcast %T4test7MyActorC* %1 to %swift.executor* +// CHECK-x86_64: call {{.*}} @llvm.coro.suspend.async{{.*}}(i32 0, i8* [[RESUME]], i8* bitcast (i8* (i8*)* @__swift_async_resume_get_context to i8*), i8* bitcast (void (i8*, %swift.executor*, %swift.context*)* @__swift_suspend_point to i8*), i8* [[RESUME]], %swift.executor* [[CAST_ACTOR]], %swift.context* {{%[0-9]+}}) +// CHECK-arm64e: call {{.*}} @llvm.coro.suspend.async{{.*}}(i32 0, i8* [[RESUME]], i8* bitcast (i8* (i8*)* @__swift_async_resume_get_context to i8*), i8* bitcast (void (i8*, %swift.executor*, %swift.context*)* @__swift_suspend_point to i8*), i8* [[RESUME]], %swift.executor* [[CAST_ACTOR]], %swift.context* {{%[0-9]+}}) +// CHECK: [[RET_CONTINUATION:%.*]] = bitcast void (%swift.context*)* {{.*}} to i8* +// CHECK: call i1 (i8*, i1, ...) @llvm.coro.end.async(i8* {{.*}}, i1 false, void (i8*, %swift.context*)* @[[TAIL_CALL_FUNC:.*]], i8* [[RET_CONTINUATION]] // CHECK: unreachable sil @test_simple : $@convention(method) @async (@guaranteed MyActor) -> () { @@ -40,22 +29,16 @@ bb0(%0 : $MyActor): } // CHECK-LABEL: define internal swift{{(tail)?}}cc void @__swift_suspend_point -// CHECK-SAME: (i8* %0, %swift.executor* %1, %swift.task* %2, %swift.executor* %3, %swift.context* [[CTXT:%[^,]+]]) -// CHECK: [[RESUME_ADDR:%[0-9]+]] = getelementptr inbounds %swift.task, %swift.task* %2, i32 0, i32 4 -// CHECK: store i8* %0, i8** [[RESUME_ADDR]] -// CHECK: [[CTXT_ADDR:%[0-9]+]] = getelementptr inbounds %swift.task, %swift.task* %2, i32 0, i32 5 -// CHECK-arm64e: [[CTXT_ADDR_INT:%[^,]+]] = ptrtoint %swift.context** [[CTXT_ADDR]] to i64 -// CHECK-arm64e: [[PTRAUTH_BLEND:%[^,]+]] = call i64 @llvm.ptrauth.blend.i64(i64 [[CTXT_ADDR_INT]], i64 30010) -// CHECK-arm64e: [[CTXT_INT:%[^,]+]] = ptrtoint %swift.context* [[CTXT]] to i64 -// CHECK-arm64e: [[PTRAUTH_SIGN:%[^,]+]] = call i64 @llvm.ptrauth.sign.i64(i64 [[CTXT_INT]], i32 2, i64 [[PTRAUTH_BLEND]]) -// CHECK-arm64e: [[CTXT:%[^,]+]] = inttoptr i64 [[PTRAUTH_SIGN]] to %swift.context* -// CHECK: store %swift.context* [[CTXT]], %swift.context** [[CTXT_ADDR]] -// CHECK: {{(must)?}}tail call swift{{(tail)?}}cc void @swift_task_switch(%swift.task* %2, %swift.executor* %3, %swift.executor* %1) +// CHECK-SAME: (i8* [[RESUME_FN:%0]], %swift.executor* %1, %swift.context* [[CTXT:%[^,]+]]) +// CHECK-arm64e: [[RESUME_FN_INT:%[^,]+]] = ptrtoint i8* [[RESUME_FN]] to i64 +// CHECK-arm64e: [[PTRAUTH_SIGN:%[^,]+]] = call i64 @llvm.ptrauth.sign.i64(i64 [[RESUME_FN_INT]], i32 0, i64 0) +// CHECK-arm64e: [[RESUME_FN:%[^,]+]] = inttoptr i64 [[PTRAUTH_SIGN]] to i8* +// CHECK: {{(must)?}}tail call swift{{(tail)?}}cc void @swift_task_switch(%swift.context* swiftasync [[CTXT]], i8* [[RESUME_FN]], %swift.executor* %1) // CHECK: ret void -// CHECK: define{{.*}} void @[[TAIL_CALL_FUNC]](i8* %0, %swift.task* %1, %swift.executor* %2, %swift.context* %3) -// CHECK: %4 = bitcast i8* %0 to void (%swift.task*, %swift.executor*, %swift.context*)* -// CHECK: {{(must)?}}tail call swift{{(tail)?}}cc void %4(%swift.task* %1, %swift.executor* %2, %swift.context* swiftasync %3) +// CHECK: define{{.*}} void @[[TAIL_CALL_FUNC]](i8* %0, %swift.context* %1) +// CHECK: %2 = bitcast i8* %0 to void (%swift.context*)* +// CHECK: {{(must)?}}tail call swift{{(tail)?}}cc void %2(%swift.context* swiftasync %1) // CHECK: ret void // CHECK: } diff --git a/test/IRGen/async/partial_apply.sil b/test/IRGen/async/partial_apply.sil index 383dac71a9ee2..9f374aa8c4350 100644 --- a/test/IRGen/async/partial_apply.sil +++ b/test/IRGen/async/partial_apply.sil @@ -1,6 +1,6 @@ // RUN: %empty-directory(%t) -// RUN: %target-swift-frontend -emit-module -enable-library-evolution -emit-module-path=%t/resilient_struct.swiftmodule -module-name=resilient_struct %S/../../Inputs/resilient_struct.swift -// RUN: %target-swift-frontend -I %t -emit-ir %s | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize +// RUN: %target-swift-frontend -g -emit-module -enable-library-evolution -emit-module-path=%t/resilient_struct.swiftmodule -module-name=resilient_struct %S/../../Inputs/resilient_struct.swift +// RUN: %target-swift-frontend -g -I %t -emit-ir %s | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize // REQUIRES: concurrency @@ -12,12 +12,21 @@ class SwiftClass {} sil_vtable SwiftClass {} sil @$s13partial_apply10SwiftClassCfD : $@async @convention(method) (SwiftClass) -> () -sil @partially_applyable_to_class : $@async @convention(thin) (@owned SwiftClass) -> () -sil @partially_applyable_to_two_classes : $@async @convention(thin) (@owned SwiftClass, @owned SwiftClass) -> () +sil @partially_applyable_to_class : $@async @convention(thin) (@owned SwiftClass) -> () { +entry(%c : $SwiftClass): + %0 = builtin "int_trap"() : $Never + unreachable +} +sil @partially_applyable_to_two_classes : $@async @convention(thin) (@owned SwiftClass, @owned SwiftClass) -> () { +entry(%c : $SwiftClass, %d : $SwiftClass): + %0 = builtin "int_trap"() : $Never + unreachable +} + sil @use_closure : $@async @convention(thin) (@noescape @async @callee_guaranteed () -> ()) -> () -// CHECK: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_class(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} { +// CHECK: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_class( sil @partial_apply_class : $@async @convention(thin) (SwiftClass) -> @async @callee_owned () -> () { entry(%c : $SwiftClass): %f = function_ref @partially_applyable_to_class : $@async @convention(thin) (@owned SwiftClass) -> () @@ -25,7 +34,7 @@ entry(%c : $SwiftClass): return %g : $@async @callee_owned () -> () } -// CHECK: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_class_on_stack(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} { +// CHECK: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_class_on_stack( sil @partial_apply_class_on_stack : $@async @convention(thin) (@owned SwiftClass) -> () { entry(%a : $SwiftClass): %f = function_ref @partially_applyable_to_class : $@async @convention(thin) (@owned SwiftClass) -> () @@ -38,7 +47,7 @@ entry(%a : $SwiftClass): return %t : $() } -// CHECK: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_two_classes_on_stack(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} { +// CHECK: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_two_classes_on_stack( sil @partial_apply_two_classes_on_stack : $@async @convention(thin) (@owned SwiftClass, @owned SwiftClass) -> () { entry(%a : $SwiftClass, %b: $SwiftClass): @@ -52,8 +61,11 @@ entry(%a : $SwiftClass, %b: $SwiftClass): %t = tuple() return %t : $() } -// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s22generic_captured_paramTA"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} { -sil public_external @generic_captured_param : $@async @convention(thin) (Int, @inout T) -> Int +// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s22generic_captured_paramTA"( +sil @generic_captured_param : $@async @convention(thin) (Int, @inout T) -> Int { +entry(%i : $Int, %t : $*T): +return %i : $Int +} sil @partial_apply_generic_capture : $@async @convention(thin) (Int) -> @async @callee_owned (Int) -> Int { entry(%x : $Int): @@ -65,9 +77,14 @@ entry(%x : $Int): return %p : $@async @callee_owned (Int) -> Int } -sil public_external @generic_captured_and_open_param : $@async @convention(thin) (@in T, @inout T) -> @out T +sil public @generic_captured_and_open_param : $@async @convention(thin) (@in T, @inout T) -> @out T { +entry(%o : $*T, %i : $*T, %io : $*T): + %0 = builtin "int_trap"() : $Never + unreachable +} + -// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_open_generic_capture(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} { +// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_open_generic_capture( sil @partial_apply_open_generic_capture : $@async @convention(thin) (@inout T) -> @async @callee_owned (@in T) -> @out T { entry(%a : $*T): %f = function_ref @generic_captured_and_open_param : $@async @convention(thin) (@in U, @inout U) -> @out U @@ -80,9 +97,13 @@ entry(%a : $*T): /* as the partial apply context. */ /*****************************************************************************/ -sil public_external @guaranteed_captured_class_param : $@async @convention(thin) (Int, @guaranteed SwiftClass) -> Int +sil public @guaranteed_captured_class_param : $@async @convention(thin) (Int, @guaranteed SwiftClass) -> Int { +entry(%i : $Int, %c : $SwiftClass): + %0 = builtin "int_trap"() : $Never + unreachable +} -// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_guaranteed_class_param(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} { +// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_guaranteed_class_param( sil @partial_apply_guaranteed_class_param : $@async @convention(thin) (@owned SwiftClass) -> @async @callee_owned (Int) -> Int { bb0(%x : $SwiftClass): @@ -91,10 +112,14 @@ bb0(%x : $SwiftClass): return %p : $@async @callee_owned (Int) -> Int } -sil public_external @indirect_guaranteed_captured_class_param : $@async @convention(thin) (Int, @in_guaranteed SwiftClass) -> Int +sil public @indirect_guaranteed_captured_class_param : $@async @convention(thin) (Int, @in_guaranteed SwiftClass) -> Int { +entry(%i : $Int, %c : $*SwiftClass): + %0 = builtin "int_trap"() : $Never + unreachable +} -// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_indirect_guaranteed_class_param(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} { -// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s40indirect_guaranteed_captured_class_paramTA"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[1-9]+}}) {{#[0-9]+}} { +// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_indirect_guaranteed_class_param( +// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s40indirect_guaranteed_captured_class_paramTA"( sil @partial_apply_indirect_guaranteed_class_param : $@async @convention(thin) (@in SwiftClass) -> @async @callee_owned (Int) -> Int { bb0(%x : $*SwiftClass): @@ -103,10 +128,14 @@ bb0(%x : $*SwiftClass): return %p : $@async @callee_owned (Int) -> Int } -sil public_external @indirect_consumed_captured_class_param : $@async @convention(thin) (Int, @in SwiftClass) -> Int +sil public @indirect_consumed_captured_class_param : $@async @convention(thin) (Int, @in SwiftClass) -> Int { +entry(%i : $Int, %c : $*SwiftClass): + %0 = builtin "int_trap"() : $Never + unreachable +} -// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_indirect_consumed_class_param(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[1-9]+}}) {{#[0-9]+}} { -// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s38indirect_consumed_captured_class_paramTA"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} { +// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_indirect_consumed_class_param( +// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s38indirect_consumed_captured_class_paramTA"( sil @partial_apply_indirect_consumed_class_param : $@async @convention(thin) (@in SwiftClass) -> @async @callee_owned (Int) -> Int { bb0(%x : $*SwiftClass): @@ -122,10 +151,15 @@ bb0(%x : $*SwiftClass): struct SwiftClassPair { var x: SwiftClass, y: SwiftClass } -sil public_external @guaranteed_captured_class_pair_param : $@async @convention(thin) (Int, @guaranteed SwiftClassPair) -> Int +sil public @guaranteed_captured_class_pair_param : $@async @convention(thin) (Int, @guaranteed SwiftClassPair) -> Int { +entry(%i : $Int, %c : $SwiftClassPair): + %0 = builtin "int_trap"() : $Never + unreachable +} + -// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_guaranteed_class_pair_param(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} { -// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s36guaranteed_captured_class_pair_paramTA"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} { +// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_guaranteed_class_pair_param( +// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s36guaranteed_captured_class_pair_paramTA"( sil @partial_apply_guaranteed_class_pair_param : $@async @convention(thin) (@owned SwiftClassPair) -> @async @callee_owned (Int) -> Int { bb0(%x : $SwiftClassPair): @@ -134,10 +168,14 @@ bb0(%x : $SwiftClassPair): return %p : $@async @callee_owned (Int) -> Int } -sil public_external @indirect_guaranteed_captured_class_pair_param : $@async @convention(thin) (Int, @in_guaranteed SwiftClassPair) -> Int +sil public @indirect_guaranteed_captured_class_pair_param : $@async @convention(thin) (Int, @in_guaranteed SwiftClassPair) -> Int { +entry(%i : $Int, %c : $*SwiftClassPair): + %0 = builtin "int_trap"() : $Never + unreachable +} -// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_indirect_guaranteed_class_pair_param(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} { -// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s45indirect_guaranteed_captured_class_pair_paramTA"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} { +// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_indirect_guaranteed_class_pair_param( +// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s45indirect_guaranteed_captured_class_pair_paramTA"( sil @partial_apply_indirect_guaranteed_class_pair_param : $@async @convention(thin) (@in SwiftClassPair) -> @async @callee_owned (Int) -> Int { bb0(%x : $*SwiftClassPair): @@ -146,10 +184,15 @@ bb0(%x : $*SwiftClassPair): return %p : $@async @callee_owned (Int) -> Int } -sil public_external @indirect_consumed_captured_class_pair_param : $@async @convention(thin) (Int, @in SwiftClassPair) -> Int +sil public @indirect_consumed_captured_class_pair_param : $@async @convention(thin) (Int, @in SwiftClassPair) -> Int { +entry(%i : $Int, %c : $*SwiftClassPair): + %0 = builtin "int_trap"() : $Never + unreachable +} + -// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_indirect_consumed_class_pair_param(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} { -// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s43indirect_consumed_captured_class_pair_paramTA"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} { +// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_indirect_consumed_class_pair_param( +// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s43indirect_consumed_captured_class_pair_paramTA"( sil @partial_apply_indirect_consumed_class_pair_param : $@async @convention(thin) (@in SwiftClassPair) -> @async @callee_owned (Int) -> Int { bb0(%x : $*SwiftClassPair): @@ -158,10 +201,14 @@ bb0(%x : $*SwiftClassPair): return %p : $@async @callee_owned (Int) -> Int } -sil public_external @captured_fixed_and_dependent_params : $@async @convention(thin) (@owned SwiftClass, @in A, Int) -> () +sil public @captured_fixed_and_dependent_params : $@async @convention(thin) (@owned SwiftClass, @in A, Int) -> () { +entry(%c : $SwiftClass, %a : $*A, %i : $Int): + %0 = builtin "int_trap"() : $Never + unreachable +} -// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_indirect_non_fixed_layout(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} { -// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s35captured_fixed_and_dependent_paramsTA"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} { +// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_indirect_non_fixed_layout +// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s35captured_fixed_and_dependent_paramsTA"( sil @partial_apply_indirect_non_fixed_layout : $@async @convention(thin) (@owned SwiftClass, @in T, Int) -> @async @callee_owned () -> () { bb0(%a : $SwiftClass, %b : $*T, %c : $Int): %f = function_ref @captured_fixed_and_dependent_params : $@async @convention(thin) (@owned SwiftClass, @in B, Int) -> () @@ -169,7 +216,11 @@ bb0(%a : $SwiftClass, %b : $*T, %c : $Int): return %p : $@async @callee_owned () -> () } -sil public_external @captured_dependent_out_param : $@async @convention(thin) (@in A) -> @out A +sil public @captured_dependent_out_param : $@async @convention(thin) (@in A) -> @out A { +entry(%o : $*A, %i : $*A): + %0 = builtin "int_trap"() : $Never + unreachable +} sil @partial_apply_with_out_param : $@async @convention(thin) (@in T) -> @async @callee_owned () -> @out T { bb0(%x : $*T): @@ -178,7 +229,7 @@ bb0(%x : $*T): return %p : $@async @callee_owned () -> @out T } -// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s28captured_dependent_out_paramTA"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} { +// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s28captured_dependent_out_paramTA"( sil @partial_apply_dynamic_with_out_param : $@async @convention(thin) (Int32, @owned @async @callee_owned (Int32) -> @out T) -> @async @callee_owned () -> @out T { bb0(%x : $Int32, %f : $@async @callee_owned (Int32) -> @out T): @@ -186,7 +237,7 @@ bb0(%x : $Int32, %f : $@async @callee_owned (Int32) -> @out T): return %p : $@async @callee_owned () -> @out T } -// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_dynamic_with_out_param(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} { +// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_dynamic_with_out_param( class Base { } @@ -205,10 +256,7 @@ bb0(%0 : $Base): sil public_external @receive_closure : $@async @convention(thin) (@owned @async @callee_owned () -> (@owned C)) -> () -// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @test_partial_apply(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} { - -// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s26parametric_casting_closureTA"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} { -// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s26parametric_casting_closureTA.{{[0-9]+}}"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} { +// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @test_partial_apply( sil @test_partial_apply : $@async @convention(thin) (@owned Base) -> () { bb0(%0 : $Base): @@ -221,26 +269,16 @@ bb0(%0 : $Base): return %5 : $() } -sil public_external @partial_empty_box : $@async @convention(thin) (@owned <Ï„_0_0> { var Ï„_0_0 } <()>, @inout_aliasable ()) -> () - -// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @empty_box(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} { -sil @empty_box : $@async @convention(thin) () -> () { -entry: - // CHECK: [[BOX:%.*]] = call {{.*}}swift_allocEmptyBox - // CHECK: store %swift.refcounted* [[BOX]] - // CHECK: store %swift.opaque* undef - %b = alloc_box $<Ï„_0_0> { var Ï„_0_0 } <()> - %ba = project_box %b : $<Ï„_0_0> { var Ï„_0_0 } <()>, 0 - %f = function_ref @partial_empty_box : $@async @convention(thin) (@owned <Ï„_0_0> { var Ï„_0_0 } <()>, @inout_aliasable ()) -> () - %g = partial_apply %f(%b, %ba) : $@async @convention(thin) (@owned <Ï„_0_0> { var Ï„_0_0 } <()>, @inout_aliasable ()) -> () - return undef : $() -} protocol P0 {} protocol P1 { associatedtype X : P0 } protocol P2 { associatedtype Y : P1 } -sil hidden_external @complex_generic_function : $@async @convention(thin) (Int) -> () +sil hidden @complex_generic_function : $@async @convention(thin) (Int) -> () { +entry(%i : $Int): + %0 = builtin "int_trap"() : $Never + unreachable +} sil @partial_apply_complex_generic_function : $@async @convention(thin) (Int) -> () { bb0(%0 : $Int): @@ -249,15 +287,16 @@ bb0(%0 : $Int): %result = tuple () return %result : $() } -// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_complex_generic_function(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} { -// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s24complex_generic_functionTA"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} { - +// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_complex_generic_function( struct ComplexBoundedType {} // SR-901: Ensure that a partial_apply which captures bound generic type // metadata doesn't crash when restoring the generic context. -sil hidden_external @generic_function : $@async @convention(thin) () -> () +sil hidden @generic_function : $@async @convention(thin) () -> () { + %0 = builtin "int_trap"() : $Never + unreachable +} sil @partial_apply_with_generic_type : $@async @convention(thin) () -> () { bb0: %fn = function_ref @generic_function : $@async @convention(thin) () -> () @@ -286,16 +325,18 @@ enum GenericEnum { case X(String) case Y(T, T, T, T, T) } -sil public_external @generic_indirect_return : $@async @convention(thin) (Int) -> @owned GenericEnum +sil public @generic_indirect_return : $@async @convention(thin) (Int) -> @owned GenericEnum { +entry(%i : $Int): + %0 = builtin "int_trap"() : $Never + unreachable +} -// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_generic_indirect_return(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} { -// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s23generic_indirect_returnTA"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} { +// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_generic_indirect_return( sil @partial_apply_generic_indirect_return : $@async @convention(thin) (Int) -> @async @callee_owned () -> @owned GenericEnum { bb0(%0 : $Int): %fn = function_ref @generic_indirect_return :$@async @convention(thin) (Int) -> @owned GenericEnum %pa = partial_apply %fn (%0) : $@async @convention(thin) (Int) -> @owned GenericEnum return %pa : $@async @callee_owned () -> @owned GenericEnum - } // Crash on partial apply of a generic enum. @@ -303,10 +344,13 @@ enum GenericEnum2 { case X(String) case Y(T) } -sil public_external @generic_indirect_return2 : $@async @convention(thin) (Int) -> @owned GenericEnum2 +sil public @generic_indirect_return2 : $@async @convention(thin) (Int) -> @owned GenericEnum2 { +entry(%i : $Int): + %0 = builtin "int_trap"() : $Never + unreachable +} -// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_generic_indirect_return2(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} { -// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s24generic_indirect_return2TA"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} { +// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_generic_indirect_return2( sil @partial_apply_generic_indirect_return2 : $@async @convention(thin) (Int) -> @async @callee_owned () -> @owned GenericEnum2 { bb0(%0 : $Int): %fn = function_ref @generic_indirect_return2 :$@async @convention(thin) (Int) -> @owned GenericEnum2 @@ -316,9 +360,13 @@ sil @partial_apply_generic_indirect_return2 : $@async @convention(thin) (Int) -> struct SwiftStruct {} -sil @fun : $@async @convention(thin) (@thin SwiftStruct.Type, @owned SwiftClass) -> () +sil @fun : $@async @convention(thin) (@thin SwiftStruct.Type, @owned SwiftClass) -> () { +entry(%t : $@thin SwiftStruct.Type, %c : $SwiftClass): + %0 = builtin "int_trap"() : $Never + unreachable +} -// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_thin_type(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} { +// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_thin_type( sil @partial_apply_thin_type : $@async @convention(thin) (@thin SwiftStruct.Type, @owned SwiftClass) -> @async @callee_owned () -> () { entry(%0: $@thin SwiftStruct.Type, %1: $SwiftClass): @@ -330,7 +378,7 @@ entry(%0: $@thin SwiftStruct.Type, %1: $SwiftClass): sil @afun : $@async @convention(thin) (Int) -> @error Error // Check that we don't assert on a thin noescape function. -// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @convert_thin_test(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} { +// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @convert_thin_test( sil @convert_thin_test : $@async @convention(thin) (Int) -> () { bb(%0 : $Int): %f = function_ref @afun : $@async @convention(thin) (Int) -> @error Error @@ -358,7 +406,11 @@ struct A2 { class A3 {} -sil @amethod : $@async @convention(method) (@in_guaranteed A2) -> (@owned A1, @error Error) +sil @amethod : $@async @convention(method) (@in_guaranteed A2) -> (@owned A1, @error Error) { +entry(%a : $*A2): + %0 = builtin "int_trap"() : $Never + unreachable +} sil @repo : $@async @convention(thin) (@in_guaranteed A2) -> @owned @async @callee_guaranteed () -> (@owned A1, @error Error) { bb0(%0 : $*A2): @@ -393,7 +445,7 @@ bb0(%0 : $*A2): sil_vtable A3 {} -// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_callee_guaranteed_indirect_guaranteed_class_pair_param(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} { +// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_callee_guaranteed_indirect_guaranteed_class_pair_param( sil @partial_apply_callee_guaranteed_indirect_guaranteed_class_pair_param : $@async @convention(thin) (@in SwiftClassPair) -> @owned @async @callee_guaranteed (Int) -> Int { bb0(%x : $*SwiftClassPair): @@ -404,8 +456,7 @@ bb0(%x : $*SwiftClassPair): sil public_external @use_closure2 : $@async @convention(thin) (@noescape @async @callee_guaranteed (Int) -> Int) -> () -// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_stack_callee_guaranteed_indirect_guaranteed_class_pair_param(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} { -// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s45indirect_guaranteed_captured_class_pair_paramTA.{{[0-9]+}}"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} { +// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_stack_callee_guaranteed_indirect_guaranteed_class_pair_param( sil @partial_apply_stack_callee_guaranteed_indirect_guaranteed_class_pair_param : $@async @convention(thin) (@in_guaranteed SwiftClassPair) -> () { bb0(%x : $*SwiftClassPair): @@ -418,10 +469,13 @@ bb0(%x : $*SwiftClassPair): return %t : $() } -// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_stack_callee_guaranteed_indirect_in_class_pair_param(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} { -// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s37indirect_in_captured_class_pair_paramTA"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} { +// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_stack_callee_guaranteed_indirect_in_class_pair_param( -sil public_external @indirect_in_captured_class_pair_param : $@async @convention(thin) (Int, @in SwiftClassPair) -> Int +sil public @indirect_in_captured_class_pair_param : $@async @convention(thin) (Int, @in SwiftClassPair) -> Int { +entry(%i : $Int, %p : $*SwiftClassPair): + %0 = builtin "int_trap"() : $Never + unreachable +} sil @partial_apply_stack_callee_guaranteed_indirect_in_class_pair_param : $@async @convention(thin) (@in SwiftClassPair) -> () { bb0(%x : $*SwiftClassPair): @@ -436,10 +490,13 @@ bb0(%x : $*SwiftClassPair): } -// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_stack_callee_guaranteed_indirect_in_constant_class_pair_param(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} { -// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s46indirect_in_constant_captured_class_pair_paramTA"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} { +// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_stack_callee_guaranteed_indirect_in_constant_class_pair_param( -sil public_external @indirect_in_constant_captured_class_pair_param : $@async @convention(thin) (Int, @in_constant SwiftClassPair) -> Int +sil public @indirect_in_constant_captured_class_pair_param : $@async @convention(thin) (Int, @in_constant SwiftClassPair) -> Int { +entry(%i : $Int, %ic : $*SwiftClassPair): + %0 = builtin "int_trap"() : $Never + unreachable +} sil @partial_apply_stack_callee_guaranteed_indirect_in_constant_class_pair_param : $@async @convention(thin) (@in SwiftClassPair) -> () { bb0(%x : $*SwiftClassPair): @@ -453,10 +510,14 @@ bb0(%x : $*SwiftClassPair): return %t : $() } -sil public_external @closure : $@async @convention(thin) (@in_guaranteed ResilientInt, @guaranteed SwiftClass) -> () +sil public @closure : $@async @convention(thin) (@in_guaranteed ResilientInt, @guaranteed SwiftClass) -> () { +entry(%i : $*ResilientInt, %c : $SwiftClass): + %0 = builtin "int_trap"() : $Never + unreachable +} // Make sure that we use the heap header size (16) for the initial offset. -// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @test_initial_offset(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} { +// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @test_initial_offset( sil @test_initial_offset : $@async @convention(thin) (@in_guaranteed ResilientInt, @guaranteed SwiftClass) -> () { bb0(%x : $*ResilientInt, %y : $SwiftClass): @@ -476,9 +537,13 @@ struct SomeType : Proto2 { var x : Int } -sil @foo : $@async @convention(thin) <Ï„_0_0, Ï„_0_1 where Ï„_0_0 : Proto1, Ï„_0_1 : Proto2> (@in_guaranteed Ï„_0_0, @in_guaranteed Ï„_0_1) -> () +sil @foo : $@async @convention(thin) <Ï„_0_0, Ï„_0_1 where Ï„_0_0 : Proto1, Ï„_0_1 : Proto2> (@in_guaranteed Ï„_0_0, @in_guaranteed Ï„_0_1) -> () { +entry(%z : $*Ï„_0_0, %o : $*Ï„_0_1): + %0 = builtin "int_trap"() : $Never + unreachable +} -// CHECK-64-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @empty_followed_by_non_fixed(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} { +// CHECK-64-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @empty_followed_by_non_fixed( sil @empty_followed_by_non_fixed : $@async @convention(thin) (EmptyType, @in_guaranteed SomeType) -> () { entry(%0 : $EmptyType, %1: $*SomeType): @@ -501,9 +566,13 @@ entry(%0 : $EmptyType, %1: $*SomeType): struct FixedType { var f: Int32 } -// CHECK-64-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @fixed_followed_by_empty_followed_by_non_fixed(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} { +// CHECK-64-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @fixed_followed_by_empty_followed_by_non_fixed -sil @foo2 : $@async @convention(thin) <Ï„_0_0, Ï„_0_1, Ï„_0_2> (@in_guaranteed Ï„_0_0, @in_guaranteed Ï„_0_1, @in_guaranteed Ï„_0_2) -> () +sil @foo2 : $@async @convention(thin) <Ï„_0_0, Ï„_0_1, Ï„_0_2> (@in_guaranteed Ï„_0_0, @in_guaranteed Ï„_0_1, @in_guaranteed Ï„_0_2) -> () { +entry(%z : $*Ï„_0_0, %o : $*Ï„_0_1, %t : $*Ï„_0_2): + %0 = builtin "int_trap"() : $Never + unreachable +} sil @fixed_followed_by_empty_followed_by_non_fixed : $@async @convention(thin) (EmptyType, @in_guaranteed SomeType, FixedType) -> () { entry(%0 : $EmptyType, %1: $*SomeType, %3: $FixedType): %5 = alloc_stack $EmptyType @@ -524,3 +593,22 @@ entry(%0 : $EmptyType, %1: $*SomeType, %3: $FixedType): %40 = tuple() return %40 : $() } + +// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc { i8*, %swift.refcounted* } @create_pa_f2( +sil @create_pa_f2 : $@convention(thin) (@callee_guaranteed @async @convention(thick) (Int64, Int32) -> Int64, Int32) -> @owned @async @callee_guaranteed (Int64) -> Int64 { +bb0(%thick : $@callee_guaranteed @async @convention(thick) (Int64, Int32) -> Int64 , %captured : $Int32): + %pa_f = partial_apply [callee_guaranteed] %thick(%captured) : $@callee_guaranteed @async @convention(thick) (Int64, Int32) -> Int64 + %pa_f2 = partial_apply [callee_guaranteed] %thick(%captured) : $@callee_guaranteed @async @convention(thick) (Int64, Int32) -> Int64 + return %pa_f : $@async @callee_guaranteed (Int64) -> Int64 +} + +// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s26parametric_casting_closureTA"( +// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s26parametric_casting_closureTA.{{[0-9]+}}"( +// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s24complex_generic_functionTA"( +// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s23generic_indirect_returnTA"( +// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s24generic_indirect_return2TA"( +// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s45indirect_guaranteed_captured_class_pair_paramTA.{{[0-9]+}}"( +// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s37indirect_in_captured_class_pair_paramTA"( +// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s46indirect_in_constant_captured_class_pair_paramTA"( +// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s12create_pa_f2Tw_"( +// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s12create_pa_f2Tw0_"( diff --git a/test/IRGen/async/partial_apply_forwarder.sil b/test/IRGen/async/partial_apply_forwarder.sil index 3a07fee8c03cc..d2f1079ca57ee 100644 --- a/test/IRGen/async/partial_apply_forwarder.sil +++ b/test/IRGen/async/partial_apply_forwarder.sil @@ -6,6 +6,7 @@ sil_stage canonical import Builtin +import Swift public protocol P {} public class C : P {} @@ -28,8 +29,6 @@ bb0(%0 : $*S): return %2 : $@async @callee_owned (@in O) -> () } -// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s23unspecialized_uncurriedTA"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} - sil hidden @specialized_curried : $@async @convention(thin) (@owned E) -> @owned @async @callee_owned () -> @owned D { bb0(%0 : $E): %1 = function_ref @unspecialized_uncurried : $@async @convention(method) <Ï„_0_0 where Ï„_0_0 : P> (@guaranteed E) -> @owned D<Ï„_0_0> @@ -37,11 +36,18 @@ bb0(%0 : $E): return %2 : $@async @callee_owned () -> @owned D } -sil hidden_external @unspecialized_uncurried : $@async @convention(method) <Ï„_0_0 where Ï„_0_0 : P> (@guaranteed E) -> @owned D<Ï„_0_0> +sil hidden @unspecialized_uncurried : $@async @convention(method) <Ï„_0_0 where Ï„_0_0 : P> (@guaranteed E) -> @owned D<Ï„_0_0> { +entry(%e : $E): + %0 = builtin "int_trap"() : $Never + unreachable +} -// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s7takingPTA"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} -sil hidden_external @takingP : $@async @convention(method) <Ï„_0_0 where Ï„_0_0 : P> (@in_guaranteed Ï„_0_0) -> () +sil hidden_external @takingP : $@async @convention(method) <Ï„_0_0 where Ï„_0_0 : P> (@in_guaranteed Ï„_0_0) -> () { +entry(%p : $*Ï„_0_0): + %0 = builtin "int_trap"() : $Never + unreachable +} sil hidden @reabstract_context : $@async @convention(thin) (@owned C) -> () { bb0(%0 : $C): @@ -67,12 +73,23 @@ public class WeakBox {} public struct EmptyType {} -sil hidden_external @takingQ : $@async @convention(thin) <Ï„_0_0 where Ï„_0_0 : Q> (@owned WeakBox<Ï„_0_0>) -> () -sil hidden_external @takingQAndEmpty : $@async @convention(thin) <Ï„_0_0 where Ï„_0_0 : Q> (@owned WeakBox<Ï„_0_0>, EmptyType) -> () -sil hidden_external @takingEmptyAndQ : $@async @convention(thin) <Ï„_0_0 where Ï„_0_0 : Q> (EmptyType, @owned WeakBox<Ï„_0_0>) -> () +sil hidden @takingQ : $@async @convention(thin) <Ï„_0_0 where Ï„_0_0 : Q> (@owned WeakBox<Ï„_0_0>) -> () { +entry(%b : $WeakBox<Ï„_0_0>): + %0 = builtin "int_trap"() : $Never + unreachable +} +sil hidden @takingQAndEmpty : $@async @convention(thin) <Ï„_0_0 where Ï„_0_0 : Q> (@owned WeakBox<Ï„_0_0>, EmptyType) -> () { +entry(%b : $WeakBox<Ï„_0_0>, %e : $EmptyType): + %0 = builtin "int_trap"() : $Never + unreachable +} +sil hidden @takingEmptyAndQ : $@async @convention(thin) <Ï„_0_0 where Ï„_0_0 : Q> (EmptyType, @owned WeakBox<Ï„_0_0>) -> () { +entry(%e : $EmptyType, %b : $WeakBox<Ï„_0_0>): + %0 = builtin "int_trap"() : $Never + unreachable +} -// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @bind_polymorphic_param_from_context(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} -// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s7takingQTA"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} +// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @bind_polymorphic_param_from_context( sil public @bind_polymorphic_param_from_context : $@async @convention(thin) <Ï„_0_1>(@in Ï„_0_1) -> @owned @async @callee_owned () -> () { bb0(%0 : $*Ï„_0_1): @@ -82,7 +99,7 @@ bb0(%0 : $*Ï„_0_1): return %9 : $@async @callee_owned () -> () } -// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @bind_polymorphic_param_from_context_2(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} +// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @bind_polymorphic_param_from_context_2( sil public @bind_polymorphic_param_from_context_2 : $@async @convention(thin) <Ï„_0_1>(@in Ï„_0_1, EmptyType) -> @owned @async @callee_owned () -> () { bb0(%0 : $*Ï„_0_1, %2: $EmptyType): %1 = alloc_ref $WeakBox> @@ -91,7 +108,7 @@ bb0(%0 : $*Ï„_0_1, %2: $EmptyType): return %9 : $@async @callee_owned () -> () } -// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @bind_polymorphic_param_from_context_3(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} +// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @bind_polymorphic_param_from_context_3( sil public @bind_polymorphic_param_from_context_3 : $@async @convention(thin) <Ï„_0_1>(@in Ï„_0_1, EmptyType) -> @owned @async @callee_owned () -> () { bb0(%0 : $*Ï„_0_1, %2: $EmptyType): %1 = alloc_ref $WeakBox> @@ -100,8 +117,7 @@ bb0(%0 : $*Ï„_0_1, %2: $EmptyType): return %9 : $@async @callee_owned () -> () } -// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @bind_polymorphic_param_from_forwarder_parameter(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} -// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s7takingQTA.{{[0-9]+}}"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} +// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @bind_polymorphic_param_from_forwarder_parameter( sil public @bind_polymorphic_param_from_forwarder_parameter : $@async @convention(thin) <Ï„_0_1>(@in Ï„_0_1) -> () { bb0(%0 : $*Ï„_0_1): @@ -116,10 +132,13 @@ struct S { var x : Builtin.Int64 } -sil hidden_external @takingQAndS : $@async @convention(thin) <Ï„_0_0 where Ï„_0_0 : Q> (S, @owned WeakBox<Ï„_0_0>) -> () +sil hidden @takingQAndS : $@async @convention(thin) <Ï„_0_0 where Ï„_0_0 : Q> (S, @owned WeakBox<Ï„_0_0>) -> () { +entry(%s : $S, %b : $WeakBox<Ï„_0_0>): + %0 = builtin "int_trap"() : $Never + unreachable +} -// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @bind_polymorphic_param_from_context_with_layout(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} -// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s11takingQAndSTA"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} +// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @bind_polymorphic_param_from_context_with_layout( sil public @bind_polymorphic_param_from_context_with_layout : $@async @convention(thin) <Ï„_0_1>(@in Ï„_0_1, S) -> @owned @async @callee_owned () -> () { bb0(%0 : $*Ï„_0_1, %1: $S): %2 = alloc_ref $WeakBox> @@ -150,8 +169,7 @@ bb0: return %1 : $@async @callee_guaranteed (Empty) -> (@owned Empty, @owned @async @callee_guaranteed (Empty) -> @owned Empty) } -// CHECK-LABEL: define hidden swift{{(tail)?}}cc void @specializes_closure_returning_closure(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} -// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s15returns_closureTA"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} +// CHECK-LABEL: define hidden swift{{(tail)?}}cc void @specializes_closure_returning_closure( protocol MyEquatable { static func isEqual (lhs: Self, rhs: Self) -> Builtin.Int1 } @@ -179,8 +197,16 @@ extension Outer : MyEquatable where Value : MyEquatable { public struct Outermost { } -sil @$closure : $@async @convention(method) (Outer, Outer, @thin Outer.Type) -> Builtin.Int1 -sil @$closure2 : $@async @convention(method) (Outermost, Outermost, @thin Outermost.Type) -> Builtin.Int1 +sil @$closure : $@async @convention(method) (Outer, Outer, @thin Outer.Type) -> Builtin.Int1 { +entry(%o1 : $Outer, %o2 : $Outer, %ot : $@thin Outer.Type): + %0 = builtin "int_trap"() : $Never + unreachable +} +sil @$closure2 : $@async @convention(method) (Outermost, Outermost, @thin Outermost.Type) -> Builtin.Int1 { +entry(%o1 : $Outermost, %o2 : $Outermost, %t : $@thin Outermost.Type): + %0 = builtin "int_trap"() : $Never + unreachable +} sil @$dont_crash_test_capture_specialized_conditional_conformance : $@async @convention(thin) (Outer>) -> () { bb0(%0 : $Outer>): @@ -229,3 +255,10 @@ sil_vtable D {} sil_vtable E {} sil_vtable Empty {} sil_witness_table C: P module main {} + +// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s23unspecialized_uncurriedTA"( +// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s7takingPTA"( +// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s7takingQTA"( +// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s7takingQTA.{{[0-9]+}}"( +// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s11takingQAndSTA"( +// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s15returns_closureTA"( diff --git a/test/IRGen/async/partial_apply_lowering.sil b/test/IRGen/async/partial_apply_lowering.sil new file mode 100644 index 0000000000000..05aa06eba33c7 --- /dev/null +++ b/test/IRGen/async/partial_apply_lowering.sil @@ -0,0 +1,34 @@ +// RUN: %target-sil-opt -sil-inline-generics -enable-sil-verify-all -inline -partial-apply-lowering %s | %FileCheck %s --check-prefix=CHECK-SIL + +import Builtin +import Swift +import SwiftShims + + +public protocol Observable { + associatedtype Result + func subscribe(o: T) async -> () +} +public protocol Observer { + associatedtype Result +} + +// CHECK-SIL-LABEL: sil hidden @witness_method : $@convention(thin) @async (@in S, @in_guaranteed T) -> @owned @async @callee_guaranteed (@in O) -> () { +// CHECK-SIL: bb0([[OBSERVABLE:%[^,]+]] : $*S, [[GENERIC:%[^,]+]] : $*T): +// CHECK-SIL: [[WITNESS_METHOD:%[^,]+]] = witness_method $S, #Observable.subscribe : (Self) -> (T) async -> () : $@convention(witness_method: Observable) @async <Ï„_0_0 where Ï„_0_0 : Observable><Ï„_1_0 where Ï„_1_0 : Observer, Ï„_0_0.Result == Ï„_1_0.Result> (@in Ï„_1_0, @in_guaranteed Ï„_0_0) -> () +// CHECK-SIL: [[THUNK:%[^,]+]] = function_ref @$s14witness_methodTw_ : $@convention(thin) @async <Ï„_0_0 where Ï„_0_0 : Observable><Ï„_1_0 where Ï„_1_0 : Observer, Ï„_0_0.Result == Ï„_1_0.Result><Ï„_2_0> (@in Ï„_1_0, @in_guaranteed Ï„_0_0, @convention(witness_method: Observable) @async <Ï„_0_0 where Ï„_0_0 : Observable><Ï„_1_0 where Ï„_1_0 : Observer, Ï„_0_0.Result == Ï„_1_0.Result> (@in Ï„_1_0, @in_guaranteed Ï„_0_0) -> ()) -> () +// CHECK-SIL: [[THICK_FUNC:%[^,]+]] = partial_apply [callee_guaranteed] [[THUNK]]([[OBSERVABLE]], [[WITNESS_METHOD]]) : $@convention(thin) @async <Ï„_0_0 where Ï„_0_0 : Observable><Ï„_1_0 where Ï„_1_0 : Observer, Ï„_0_0.Result == Ï„_1_0.Result><Ï„_2_0> (@in Ï„_1_0, @in_guaranteed Ï„_0_0, @convention(witness_method: Observable) @async <Ï„_0_0 where Ï„_0_0 : Observable><Ï„_1_0 where Ï„_1_0 : Observer, Ï„_0_0.Result == Ï„_1_0.Result> (@in Ï„_1_0, @in_guaranteed Ï„_0_0) -> ()) -> () +// CHECK-SIL: return [[THICK_FUNC]] : $@async @callee_guaranteed (@in O) -> () +// CHECK-SIL-LABEL: } // end sil function 'witness_method' + +// CHECK-SIL-LABEL: sil private [thunk] [ossa] @$s14witness_methodTw_ : $@convention(thin) @async (@in O, @in_guaranteed S, @convention(witness_method: Observable) @async (@in O, @in_guaranteed S) -> ()) -> () { +// CHECK-SIL: bb0([[OBSERVER:%[^,]+]] : $*O, [[OBSERVABLE:%[^,]+]] : $*S, [[WITNESS_METHOD:%[^,]+]] : $@convention(witness_method: Observable) @async <Ï„_0_0 where Ï„_0_0 : Observable><Ï„_1_0 where Ï„_1_0 : Observer, Ï„_0_0.Result == Ï„_1_0.Result> (@in Ï„_1_0, @in_guaranteed Ï„_0_0) -> ()): +// CHECK-SIL: [[RESULT:%[^,]+]] = apply [[WITNESS_METHOD]]([[OBSERVER]], [[OBSERVABLE]]) : $@convention(witness_method: Observable) @async <Ï„_0_0 where Ï„_0_0 : Observable><Ï„_1_0 where Ï„_1_0 : Observer, Ï„_0_0.Result == Ï„_1_0.Result> (@in Ï„_1_0, @in_guaranteed Ï„_0_0) -> () +// CHECK-SIL: return [[RESULT]] : $() +// CHECK-SIL-LABEL: } // end sil function '$s14witness_methodTw_' +sil hidden @witness_method : $@async @convention(thin) (@in S, @in_guaranteed T) -> @owned @async @callee_guaranteed (@in O) -> () { +bb0(%0 : $*S, %t: $*T): + %1 = witness_method $S, #Observable.subscribe : $@async @convention(witness_method: Observable) <Ï„_0_0 where Ï„_0_0 : Observable><Ï„_1_0 where Ï„_1_0 : Observer, Ï„_0_0.Result == Ï„_1_0.Result> (@in Ï„_1_0, @in_guaranteed Ï„_0_0) -> () + %2 = partial_apply [callee_guaranteed] %1(%0) : $@async @convention(witness_method: Observable) <Ï„_0_0 where Ï„_0_0 : Observable><Ï„_1_0 where Ï„_1_0 : Observer, Ï„_0_0.Result == Ï„_1_0.Result> (@in Ï„_1_0, @in_guaranteed Ï„_0_0) -> () + return %2 : $@async @callee_guaranteed (@in O) -> () +} diff --git a/test/IRGen/async/protocol_resilience.swift b/test/IRGen/async/protocol_resilience.swift index cfb8a8ee9e268..e811d93d693b1 100644 --- a/test/IRGen/async/protocol_resilience.swift +++ b/test/IRGen/async/protocol_resilience.swift @@ -26,14 +26,14 @@ public protocol MyAwaitable { // CHECK-LABEL: @"$s19protocol_resilience19ConformsToAwaitableVyxG010resilient_A00E0AAMc" = hidden constant // CHECK-SAME: %swift.async_func_pointer* @"$s19protocol_resilience19ConformsToAwaitableVyxG010resilient_A00E0AaeFP4wait6ResultQzyYFTWTu" -// CHECK-LABEL: define {{(dllexport )?}}{{(protected )?}}swift{{(tail)?}}cc void @"$s19protocol_resilience14callsAwaitabley6ResultQzxY010resilient_A00D0RzlF"(%swift.task* %0, %swift.executor* %1, %swift.context* swiftasync %2) +// CHECK-LABEL: define {{(dllexport )?}}{{(protected )?}}swift{{(tail)?}}cc void @"$s19protocol_resilience14callsAwaitabley6ResultQzxY010resilient_A00D0RzlF"(%swift.opaque* noalias nocapture %0, %swift.context* swiftasync %1, %swift.opaque* noalias nocapture %2, %swift.type* %T, i8** %T.Awaitable) // CHECK: %swift.async_func_pointer* @"$s18resilient_protocol9AwaitableP4wait6ResultQzyYFTjTu" // CHECK: ret void public func callsAwaitable(_ t: T) async -> T.Result { return await t.wait() } -// CHECK-LABEL: define {{(dllexport )?}}{{(protected )?}}swift{{(tail)?}}cc void @"$s19protocol_resilience11MyAwaitableP4wait6ResultQzyYFTj"(%swift.task* %0, %swift.executor* %1, %swift.context* swiftasync %2) +// CHECK-LABEL: define {{(dllexport )?}}{{(protected )?}}swift{{(tail)?}}cc void @"$s19protocol_resilience11MyAwaitableP4wait6ResultQzyYFTj"(%swift.opaque* noalias nocapture %0, %swift.context* swiftasync %1, %swift.opaque* noalias nocapture swiftself %2, %swift.type* %3, i8** %4) struct ConformsToAwaitable : Awaitable { var value: T diff --git a/test/IRGen/async/run-call-class-witnessmethod-void-to-void.swift b/test/IRGen/async/run-call-class-witnessmethod-void-to-void.swift index b50fcb1455c67..7a6b311f22411 100644 --- a/test/IRGen/async/run-call-class-witnessmethod-void-to-void.swift +++ b/test/IRGen/async/run-call-class-witnessmethod-void-to-void.swift @@ -31,7 +31,7 @@ protocol P { // CHECK-LL: @"$s4main1XCAA1PA2aDP1fyyYFTWTu" = internal global %swift.async_func_pointer extension P { - // CHECK-LL: define hidden swift{{(tail)?}}cc void @"$s4main1PPAAE1fyyYF"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} + // CHECK-LL: define hidden swift{{(tail)?}}cc void @"$s4main1PPAAE1fyyYF"( func f() async { print("entering f") printGeneric(Self.self) @@ -40,10 +40,10 @@ extension P { } } -// CHECK-LL: define internal swift{{(tail)?}}cc void @"$s4main1XCAA1PA2aDP1fyyYFTW"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define internal swift{{(tail)?}}cc void @"$s4main1XCAA1PA2aDP1fyyYFTW"( extension X : P {} -// CHECK-LL: define hidden swift{{(tail)?}}cc void @"$s4main6call_fyyxYAA1PRzlF"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define hidden swift{{(tail)?}}cc void @"$s4main6call_fyyxYAA1PRzlF"( func call_f(_ t: T) async { print("entering call_f") await t.f() diff --git a/test/IRGen/async/run-call-classinstance-int64-to-void.sil b/test/IRGen/async/run-call-classinstance-int64-to-void.sil index 09050c564defe..033feefeb227b 100644 --- a/test/IRGen/async/run-call-classinstance-int64-to-void.sil +++ b/test/IRGen/async/run-call-classinstance-int64-to-void.sil @@ -30,7 +30,7 @@ class S { } // CHECK-LL: @classinstanceSInt64ToVoidTu = -// CHECK-LL: define hidden swift{{(tail)?}}cc void @classinstanceSInt64ToVoid(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]+}} +// CHECK-LL: define hidden swift{{(tail)?}}cc void @classinstanceSInt64ToVoid( sil hidden @classinstanceSInt64ToVoid : $@async @convention(method) (Int64, @guaranteed S) -> () { bb0(%int : $Int64, %instance : $S): %take_s = function_ref @take_S : $@async @convention(thin) (@guaranteed S) -> () @@ -104,14 +104,21 @@ sil @test_case : $@convention(thin) @async () -> () { // Defined in _Concurrency sil @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () +sil @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error { +bb0(%0 :$@async @callee_guaranteed () -> ()): + %void = apply %0() : $@async @callee_guaranteed () -> () + return %void : $() +} + // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): %test_case_nothrow = function_ref @test_case : $@convention(thin) @async () -> () - %test_case = convert_function %test_case_nothrow : $@convention(thin) @async () -> () to $@convention(thin) @async () -> @error Error - %thick_test_case = thin_to_thick_function %test_case : $@convention(thin) @async () -> @error Error to $@callee_guaranteed @async () -> @error Error + %thick_test_case = thin_to_thick_function %test_case_nothrow : $@convention(thin) @async () -> () to $@callee_guaranteed @async () -> () + %thunk = function_ref @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error + %throwing = partial_apply [callee_guaranteed] %thunk(%thick_test_case) : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error %runAsyncMain = function_ref @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () - %result = apply %runAsyncMain(%thick_test_case) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () + %result = apply %runAsyncMain(%throwing) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () %out_literal = integer_literal $Builtin.Int32, 0 %out = struct $Int32 (%out_literal : $Builtin.Int32) return %out : $Int32 diff --git a/test/IRGen/async/run-call-classinstance-void-to-void.sil b/test/IRGen/async/run-call-classinstance-void-to-void.sil index 43d836cae775a..7fa1275ad1711 100644 --- a/test/IRGen/async/run-call-classinstance-void-to-void.sil +++ b/test/IRGen/async/run-call-classinstance-void-to-void.sil @@ -30,7 +30,7 @@ class S { } // CHECK-LL: @classinstanceSVoidToVoidTu = -// CHECK-LL: define hidden swift{{(tail)?}}cc void @classinstanceSVoidToVoid(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define hidden swift{{(tail)?}}cc void @classinstanceSVoidToVoid( sil hidden @classinstanceSVoidToVoid : $@async @convention(method) (@guaranteed S) -> () { bb0(%instance : $S): %take_s = function_ref @take_S : $@async @convention(thin) (@guaranteed S) -> () @@ -102,14 +102,21 @@ sil @test_case : $@convention(thin) @async () -> () { // Defined in _Concurrency sil @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () +sil @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error { +bb0(%0 :$@async @callee_guaranteed () -> ()): + %void = apply %0() : $@async @callee_guaranteed () -> () + return %void : $() +} + // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): %test_case_nothrow = function_ref @test_case : $@convention(thin) @async () -> () - %test_case = convert_function %test_case_nothrow : $@convention(thin) @async () -> () to $@convention(thin) @async () -> @error Error - %thick_test_case = thin_to_thick_function %test_case : $@convention(thin) @async () -> @error Error to $@callee_guaranteed @async () -> @error Error + %thick_test_case = thin_to_thick_function %test_case_nothrow : $@convention(thin) @async () -> () to $@callee_guaranteed @async () -> () + %thunk = function_ref @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error + %throwing = partial_apply [callee_guaranteed] %thunk(%thick_test_case) : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error %runAsyncMain = function_ref @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () - %result = apply %runAsyncMain(%thick_test_case) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () + %result = apply %runAsyncMain(%throwing) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () %out_literal = integer_literal $Builtin.Int32, 0 %out = struct $Int32 (%out_literal : $Builtin.Int32) return %out : $Int32 diff --git a/test/IRGen/async/run-call-dynamic-void_to_void.swift b/test/IRGen/async/run-call-dynamic-void_to_void.swift index 1a9c90a076258..2c60efb5bb188 100644 --- a/test/IRGen/async/run-call-dynamic-void_to_void.swift +++ b/test/IRGen/async/run-call-dynamic-void_to_void.swift @@ -16,7 +16,7 @@ import _Concurrency // CHECK-LL: @"$s4main3runyyYFTu" = hidden global %swift.async_func_pointer -// CHECK-LL: define hidden swift{{(tail)?}}cc void @"$s4main3runyyYF"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define hidden swift{{(tail)?}}cc void @"$s4main3runyyYF"(%swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} dynamic func run() async { print("running") } diff --git a/test/IRGen/async/run-call-existential-to-void.sil b/test/IRGen/async/run-call-existential-to-void.sil index ba0b9eb2eda2b..075ede460c888 100644 --- a/test/IRGen/async/run-call-existential-to-void.sil +++ b/test/IRGen/async/run-call-existential-to-void.sil @@ -2,7 +2,7 @@ // RUN: %target-build-swift-dylib(%t/%target-library-name(PrintShims)) %S/../../Inputs/print-shims.swift -module-name PrintShims -emit-module -emit-module-path %t/PrintShims.swiftmodule // RUN: %target-codesign %t/%target-library-name(PrintShims) // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL -// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) +// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) // RUN: %target-codesign %t/main // RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s @@ -38,7 +38,7 @@ bb0(%int : $Int64, %S_type : $@thin S.Type): } // CHECK-LL: @existentialToVoidTu = -// CHECK-LL: define hidden swift{{(tail)?}}cc void @existentialToVoid(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define hidden swift{{(tail)?}}cc void @existentialToVoid( sil hidden @existentialToVoid : $@async @convention(thin) (@in_guaranteed P) -> () { bb0(%existential : $*P): %existential_addr = open_existential_addr immutable_access %existential : $*P to $*@opened("B2796A9C-FEBE-11EA-84BB-D0817AD71B77") P @@ -80,14 +80,21 @@ sil @test_case : $@convention(thin) @async () -> () { // Defined in _Concurrency sil @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () +sil @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error { +bb0(%0 :$@async @callee_guaranteed () -> ()): + %void = apply %0() : $@async @callee_guaranteed () -> () + return %void : $() +} + // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): %test_case_nothrow = function_ref @test_case : $@convention(thin) @async () -> () - %test_case = convert_function %test_case_nothrow : $@convention(thin) @async () -> () to $@convention(thin) @async () -> @error Error - %thick_test_case = thin_to_thick_function %test_case : $@convention(thin) @async () -> @error Error to $@callee_guaranteed @async () -> @error Error + %thick_test_case = thin_to_thick_function %test_case_nothrow : $@convention(thin) @async () -> () to $@callee_guaranteed @async () -> () + %thunk = function_ref @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error + %throwing = partial_apply [callee_guaranteed] %thunk(%thick_test_case) : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error %runAsyncMain = function_ref @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () - %result = apply %runAsyncMain(%thick_test_case) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () + %result = apply %runAsyncMain(%throwing) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () %out_literal = integer_literal $Builtin.Int32, 0 %out = struct $Int32 (%out_literal : $Builtin.Int32) return %out : $Int32 diff --git a/test/IRGen/async/run-call-generic-to-generic.sil b/test/IRGen/async/run-call-generic-to-generic.sil index c7250bf137955..1dd31505de199 100644 --- a/test/IRGen/async/run-call-generic-to-generic.sil +++ b/test/IRGen/async/run-call-generic-to-generic.sil @@ -2,7 +2,7 @@ // RUN: %target-build-swift-dylib(%t/%target-library-name(PrintShims)) %S/../../Inputs/print-shims.swift -module-name PrintShims -emit-module -emit-module-path %t/PrintShims.swiftmodule // RUN: %target-codesign %t/%target-library-name(PrintShims) // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL -// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) +// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) // RUN: %target-codesign %t/main // RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s @@ -20,7 +20,7 @@ import _Concurrency sil public_external @printInt64 : $@convention(thin) (Int64) -> () // CHECK-LL: @genericToGenericTu = -// CHECK-LL: define hidden swift{{(tail)?}}cc void @genericToGeneric(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define hidden swift{{(tail)?}}cc void @genericToGeneric( sil hidden @genericToGeneric : $@async @convention(thin) (@in_guaranteed T) -> @out T { bb0(%out : $*T, %in : $*T): copy_addr %in to [initialization] %out : $*T @@ -52,14 +52,21 @@ sil @test_case : $@convention(thin) @async () -> () { // Defined in _Concurrency sil @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () +sil @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error { +bb0(%0 :$@async @callee_guaranteed () -> ()): + %void = apply %0() : $@async @callee_guaranteed () -> () + return %void : $() +} + // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): %test_case_nothrow = function_ref @test_case : $@convention(thin) @async () -> () - %test_case = convert_function %test_case_nothrow : $@convention(thin) @async () -> () to $@convention(thin) @async () -> @error Error - %thick_test_case = thin_to_thick_function %test_case : $@convention(thin) @async () -> @error Error to $@callee_guaranteed @async () -> @error Error + %thick_test_case = thin_to_thick_function %test_case_nothrow : $@convention(thin) @async () -> () to $@callee_guaranteed @async () -> () + %thunk = function_ref @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error + %throwing = partial_apply [callee_guaranteed] %thunk(%thick_test_case) : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error %runAsyncMain = function_ref @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () - %result = apply %runAsyncMain(%thick_test_case) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () + %result = apply %runAsyncMain(%throwing) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () %out_literal = integer_literal $Builtin.Int32, 0 %out = struct $Int32 (%out_literal : $Builtin.Int32) return %out : $Int32 diff --git a/test/IRGen/async/run-call-generic-to-void.swift b/test/IRGen/async/run-call-generic-to-void.swift index 517062833dcf9..ccdfca4802e70 100644 --- a/test/IRGen/async/run-call-generic-to-void.swift +++ b/test/IRGen/async/run-call-generic-to-void.swift @@ -12,7 +12,7 @@ import _Concurrency // CHECK-LL: @genericToVoidTu = -// CHECK-LL: define hidden swift{{(tail)?}}cc void @genericToVoid(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define hidden swift{{(tail)?}}cc void @genericToVoid( @_silgen_name("genericToVoid") func genericToVoid(_ t: T) async { print(t) // CHECK: 922337203685477580 diff --git a/test/IRGen/async/run-call-genericEquatable-x2-to-bool.sil b/test/IRGen/async/run-call-genericEquatable-x2-to-bool.sil index d27e9701461ca..a59b1f1a22b53 100644 --- a/test/IRGen/async/run-call-genericEquatable-x2-to-bool.sil +++ b/test/IRGen/async/run-call-genericEquatable-x2-to-bool.sil @@ -20,7 +20,7 @@ import _Concurrency sil public_external @printBool : $@convention(thin) (Bool) -> () // CHECK-LL: @genericEquatableAndGenericEquatableToBoolTu = -// CHECK-LL: define hidden swift{{(tail)?}}cc void @genericEquatableAndGenericEquatableToBool(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define hidden swift{{(tail)?}}cc void @genericEquatableAndGenericEquatableToBool( sil hidden @genericEquatableAndGenericEquatableToBool : $@async @convention(thin) (@in_guaranteed T, @in_guaranteed T) -> Bool { bb0(%0 : $*T, %1 : $*T): %4 = metatype $@thick T.Type @@ -59,15 +59,21 @@ sil @test_case : $@convention(thin) @async () -> () { // Defined in _Concurrency sil @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () +sil @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error { +bb0(%0 :$@async @callee_guaranteed () -> ()): + %void = apply %0() : $@async @callee_guaranteed () -> () + return %void : $() +} // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): %test_case_nothrow = function_ref @test_case : $@convention(thin) @async () -> () - %test_case = convert_function %test_case_nothrow : $@convention(thin) @async () -> () to $@convention(thin) @async () -> @error Error - %thick_test_case = thin_to_thick_function %test_case : $@convention(thin) @async () -> @error Error to $@callee_guaranteed @async () -> @error Error + %thick_test_case = thin_to_thick_function %test_case_nothrow : $@convention(thin) @async () -> () to $@callee_guaranteed @async () -> () + %thunk = function_ref @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error + %throwing = partial_apply [callee_guaranteed] %thunk(%thick_test_case) : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error %runAsyncMain = function_ref @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () - %result = apply %runAsyncMain(%thick_test_case) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () + %result = apply %runAsyncMain(%throwing) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () %out_literal = integer_literal $Builtin.Int32, 0 %out = struct $Int32 (%out_literal : $Builtin.Int32) return %out : $Int32 diff --git a/test/IRGen/async/run-call-int64-and-int64-to-void.sil b/test/IRGen/async/run-call-int64-and-int64-to-void.sil index e4bdbf2bca2f8..ea7f4dccd0cb6 100644 --- a/test/IRGen/async/run-call-int64-and-int64-to-void.sil +++ b/test/IRGen/async/run-call-int64-and-int64-to-void.sil @@ -2,7 +2,7 @@ // RUN: %target-build-swift-dylib(%t/%target-library-name(PrintShims)) %S/../../Inputs/print-shims.swift -module-name PrintShims -emit-module -emit-module-path %t/PrintShims.swiftmodule // RUN: %target-codesign %t/%target-library-name(PrintShims) // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL -// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) +// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) // RUN: %target-codesign %t/main // RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s @@ -20,7 +20,7 @@ import _Concurrency sil public_external @printInt64 : $@convention(thin) (Int64) -> () // CHECK-LL: @int64AndInt64ToVoidTu = -// CHECK-LL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @int64AndInt64ToVoid(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @int64AndInt64ToVoid( sil @int64AndInt64ToVoid : $@async @convention(thin) (Int64, Int64) -> () { entry(%int1: $Int64, %int2: $Int64): %print = function_ref @printInt64 : $@convention(thin) (Int64) -> () @@ -45,14 +45,21 @@ sil @test_case : $@convention(thin) @async () -> () { // Defined in _Concurrency sil @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () +sil @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error { +bb0(%0 :$@async @callee_guaranteed () -> ()): + %void = apply %0() : $@async @callee_guaranteed () -> () + return %void : $() +} + // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): %test_case_nothrow = function_ref @test_case : $@convention(thin) @async () -> () - %test_case = convert_function %test_case_nothrow : $@convention(thin) @async () -> () to $@convention(thin) @async () -> @error Error - %thick_test_case = thin_to_thick_function %test_case : $@convention(thin) @async () -> @error Error to $@callee_guaranteed @async () -> @error Error + %thick_test_case = thin_to_thick_function %test_case_nothrow : $@convention(thin) @async () -> () to $@callee_guaranteed @async () -> () + %thunk = function_ref @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error + %throwing = partial_apply [callee_guaranteed] %thunk(%thick_test_case) : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error %runAsyncMain = function_ref @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () - %result = apply %runAsyncMain(%thick_test_case) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () + %result = apply %runAsyncMain(%throwing) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () %out_literal = integer_literal $Builtin.Int32, 0 %out = struct $Int32 (%out_literal : $Builtin.Int32) return %out : $Int32 diff --git a/test/IRGen/async/run-call-int64-to-void.sil b/test/IRGen/async/run-call-int64-to-void.sil index 9029369266686..6bb522a1a3007 100644 --- a/test/IRGen/async/run-call-int64-to-void.sil +++ b/test/IRGen/async/run-call-int64-to-void.sil @@ -2,7 +2,7 @@ // RUN: %target-build-swift-dylib(%t/%target-library-name(PrintShims)) %S/../../Inputs/print-shims.swift -module-name PrintShims -emit-module -emit-module-path %t/PrintShims.swiftmodule // RUN: %target-codesign %t/%target-library-name(PrintShims) // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL -// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) +// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) // RUN: %target-codesign %t/main // RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s @@ -20,7 +20,7 @@ import _Concurrency sil public_external @printInt64 : $@convention(thin) (Int64) -> () // CHECK-LL: @int64ToVoidTu = -// CHECK-LL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @int64ToVoid(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @int64ToVoid( sil @int64ToVoid : $@async @convention(thin) (Int64) -> () { entry(%int: $Int64): %print = function_ref @printInt64 : $@convention(thin) (Int64) -> () @@ -42,14 +42,21 @@ sil @test_case : $@convention(thin) @async () -> () { // Defined in _Concurrency sil @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () +sil @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error { +bb0(%0 :$@async @callee_guaranteed () -> ()): + %void = apply %0() : $@async @callee_guaranteed () -> () + return %void : $() +} + // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): %test_case_nothrow = function_ref @test_case : $@convention(thin) @async () -> () - %test_case = convert_function %test_case_nothrow : $@convention(thin) @async () -> () to $@convention(thin) @async () -> @error Error - %thick_test_case = thin_to_thick_function %test_case : $@convention(thin) @async () -> @error Error to $@callee_guaranteed @async () -> @error Error + %thick_test_case = thin_to_thick_function %test_case_nothrow : $@convention(thin) @async () -> () to $@callee_guaranteed @async () -> () + %thunk = function_ref @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error + %throwing = partial_apply [callee_guaranteed] %thunk(%thick_test_case) : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error %runAsyncMain = function_ref @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () - %result = apply %runAsyncMain(%thick_test_case) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () + %result = apply %runAsyncMain(%throwing) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () %out_literal = integer_literal $Builtin.Int32, 0 %out = struct $Int32 (%out_literal : $Builtin.Int32) return %out : $Int32 diff --git a/test/IRGen/async/run-call-protocolextension_instance-void-to-int64.sil b/test/IRGen/async/run-call-protocolextension_instance-void-to-int64.sil index 24eea629e9730..4376a3ceaf365 100644 --- a/test/IRGen/async/run-call-protocolextension_instance-void-to-int64.sil +++ b/test/IRGen/async/run-call-protocolextension_instance-void-to-int64.sil @@ -2,7 +2,7 @@ // RUN: %target-build-swift-dylib(%t/%target-library-name(PrintShims)) %S/../../Inputs/print-shims.swift -module-name PrintShims -emit-module -emit-module-path %t/PrintShims.swiftmodule // RUN: %target-codesign %t/%target-library-name(PrintShims) // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL -// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) +// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) // RUN: %target-codesign %t/main // RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s @@ -34,7 +34,7 @@ struct I : P { } // CHECK-LL: @callPrintMeTu = -// CHECK-LL: define hidden swift{{(tail)?}}cc void @callPrintMe(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define hidden swift{{(tail)?}}cc void @callPrintMe( sil hidden @callPrintMe : $@async @convention(method) (@in_guaranteed Self) -> Int64 { bb0(%self : $*Self): %P_printMe = witness_method $Self, #P.printMe : (Self) -> () -> Int64 : $@convention(witness_method: P) <Ï„_0_0 where Ï„_0_0 : P> (@in_guaranteed Ï„_0_0) -> Int64 @@ -81,14 +81,21 @@ sil @test_case : $@convention(thin) @async () -> () { // Defined in _Concurrency sil @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () +sil @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error { +bb0(%0 :$@async @callee_guaranteed () -> ()): + %void = apply %0() : $@async @callee_guaranteed () -> () + return %void : $() +} + // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): %test_case_nothrow = function_ref @test_case : $@convention(thin) @async () -> () - %test_case = convert_function %test_case_nothrow : $@convention(thin) @async () -> () to $@convention(thin) @async () -> @error Error - %thick_test_case = thin_to_thick_function %test_case : $@convention(thin) @async () -> @error Error to $@callee_guaranteed @async () -> @error Error + %thick_test_case = thin_to_thick_function %test_case_nothrow : $@convention(thin) @async () -> () to $@callee_guaranteed @async () -> () + %thunk = function_ref @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error + %throwing = partial_apply [callee_guaranteed] %thunk(%thick_test_case) : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error %runAsyncMain = function_ref @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () - %result = apply %runAsyncMain(%thick_test_case) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () + %result = apply %runAsyncMain(%throwing) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () %out_literal = integer_literal $Builtin.Int32, 0 %out = struct $Int32 (%out_literal : $Builtin.Int32) return %out : $Int32 diff --git a/test/IRGen/async/run-call-protocolwitness_instance-void-to-int64.sil b/test/IRGen/async/run-call-protocolwitness_instance-void-to-int64.sil index 53e3399c95c37..5edb12faa4e66 100644 --- a/test/IRGen/async/run-call-protocolwitness_instance-void-to-int64.sil +++ b/test/IRGen/async/run-call-protocolwitness_instance-void-to-int64.sil @@ -30,7 +30,7 @@ struct I : P { } // CHECK-LL: @I_printMeTu = -// CHECK-LL-LABEL: define hidden swift{{(tail)?}}cc void @I_printMe(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL-LABEL: define hidden swift{{(tail)?}}cc void @I_printMe( sil hidden @I_printMe : $@async @convention(method) (I) -> Int64 { bb0(%self : $I): %self_addr = alloc_stack $I @@ -42,7 +42,7 @@ bb0(%self : $I): return %result : $Int64 } -// CHECK-LL-LABEL: define internal swift{{(tail)?}}cc void @I_P_printMe(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL-LABEL: define internal swift{{(tail)?}}cc void @I_P_printMe( sil private [transparent] [thunk] @I_P_printMe : $@async @convention(witness_method: P) (@in_guaranteed I) -> Int64 { bb0(%self_addr : $*I): %self = load %self_addr : $*I @@ -72,19 +72,25 @@ sil @test_case : $@convention(thin) @async () -> () { // Defined in _Concurrency sil @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () +sil @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error { +bb0(%0 :$@async @callee_guaranteed () -> ()): + %void = apply %0() : $@async @callee_guaranteed () -> () + return %void : $() +} + // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): %test_case_nothrow = function_ref @test_case : $@convention(thin) @async () -> () - %test_case = convert_function %test_case_nothrow : $@convention(thin) @async () -> () to $@convention(thin) @async () -> @error Error - %thick_test_case = thin_to_thick_function %test_case : $@convention(thin) @async () -> @error Error to $@callee_guaranteed @async () -> @error Error + %thick_test_case = thin_to_thick_function %test_case_nothrow : $@convention(thin) @async () -> () to $@callee_guaranteed @async () -> () + %thunk = function_ref @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error + %throwing = partial_apply [callee_guaranteed] %thunk(%thick_test_case) : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error %runAsyncMain = function_ref @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () - %result = apply %runAsyncMain(%thick_test_case) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () + %result = apply %runAsyncMain(%throwing) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () %out_literal = integer_literal $Builtin.Int32, 0 %out = struct $Int32 (%out_literal : $Builtin.Int32) return %out : $Int32 } - sil_witness_table hidden I: P module main { method #P.printMe: (Self) -> () async -> Int64 : @I_P_printMe } diff --git a/test/IRGen/async/run-call-resilient-classinstance-void-to-void.sil b/test/IRGen/async/run-call-resilient-classinstance-void-to-void.sil index e0e9ccd9a6399..671d1df31baa6 100644 --- a/test/IRGen/async/run-call-resilient-classinstance-void-to-void.sil +++ b/test/IRGen/async/run-call-resilient-classinstance-void-to-void.sil @@ -22,7 +22,7 @@ import ResilientClass sil public_external [exact_self_class] @$s14ResilientClass5ClazzCACycfC : $@convention(method) (@thick Clazz.Type) -> @owned Clazz -// CHECK-LL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @test_case(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @test_case(%swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} sil @test_case : $@convention(thin) @async () -> () { %s_type = metatype $@thick Clazz.Type %allocating_init = function_ref @$s14ResilientClass5ClazzCACycfC : $@convention(method) (@thick Clazz.Type) -> @owned Clazz @@ -39,14 +39,21 @@ sil @test_case : $@convention(thin) @async () -> () { // Defined in _Concurrency sil @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () +sil @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error { +bb0(%0 :$@async @callee_guaranteed () -> ()): + %void = apply %0() : $@async @callee_guaranteed () -> () + return %void : $() +} + // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): %test_case_nothrow = function_ref @test_case : $@convention(thin) @async () -> () - %test_case = convert_function %test_case_nothrow : $@convention(thin) @async () -> () to $@convention(thin) @async () -> @error Error - %thick_test_case = thin_to_thick_function %test_case : $@convention(thin) @async () -> @error Error to $@callee_guaranteed @async () -> @error Error + %thick_test_case = thin_to_thick_function %test_case_nothrow : $@convention(thin) @async () -> () to $@callee_guaranteed @async () -> () + %thunk = function_ref @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error + %throwing = partial_apply [callee_guaranteed] %thunk(%thick_test_case) : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error %runAsyncMain = function_ref @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () - %result = apply %runAsyncMain(%thick_test_case) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () + %result = apply %runAsyncMain(%throwing) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () %out_literal = integer_literal $Builtin.Int32, 0 %out = struct $Int32 (%out_literal : $Builtin.Int32) return %out : $Int32 diff --git a/test/IRGen/async/run-call-resilient-protocolinstance-void-to-void.swift b/test/IRGen/async/run-call-resilient-protocolinstance-void-to-void.swift index ae8f411b7c8e2..fc04adb1e99eb 100644 --- a/test/IRGen/async/run-call-resilient-protocolinstance-void-to-void.swift +++ b/test/IRGen/async/run-call-resilient-protocolinstance-void-to-void.swift @@ -20,7 +20,7 @@ func call(_ t: T) async { await t.protocolinstanceVoidToVoid() } -// CHECK-LL: define hidden swift{{(tail)?}}cc void @"$s4main4callyyxY17ResilientProtocol8ProtokolRzlF"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define hidden swift{{(tail)?}}cc void @"$s4main4callyyxY17ResilientProtocol8ProtokolRzlF"( func test_case() async { let impl = Impl() await call(impl) // CHECK: Impl() diff --git a/test/IRGen/async/run-call-struct-instance_generic-mutating-generic_1-to-generic_1.swift b/test/IRGen/async/run-call-struct-instance_generic-mutating-generic_1-to-generic_1.swift index cc84401f592c6..7ca3a5601e1ca 100644 --- a/test/IRGen/async/run-call-struct-instance_generic-mutating-generic_1-to-generic_1.swift +++ b/test/IRGen/async/run-call-struct-instance_generic-mutating-generic_1-to-generic_1.swift @@ -13,7 +13,7 @@ import _Concurrency struct G { // CHECK-LL: @"$s4main1GV19theMutatingFunctionyqd__qd__YlFTu" = hidden global %swift.async_func_pointer - // CHECK-LL: define hidden swift{{(tail)?}}cc void @"$s4main1GV19theMutatingFunctionyqd__qd__YlF"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} + // CHECK-LL: define hidden swift{{(tail)?}}cc void @"$s4main1GV19theMutatingFunctionyqd__qd__YlF"( mutating func theMutatingFunction(_ u: U) async -> U { return u } diff --git a/test/IRGen/async/run-call-struct_five_bools-to-void.sil b/test/IRGen/async/run-call-struct_five_bools-to-void.sil index 03e734ce39113..b3a87b256a864 100644 --- a/test/IRGen/async/run-call-struct_five_bools-to-void.sil +++ b/test/IRGen/async/run-call-struct_five_bools-to-void.sil @@ -40,7 +40,7 @@ entry(%pack : $Pack): return %printGeneric_result1 : $() } -// CHECK-LL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @test_case(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @test_case(%swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} sil @test_case : $@async @convention(thin) () -> () { %a_literal = integer_literal $Builtin.Int1, -1 @@ -64,14 +64,21 @@ sil @test_case : $@async @convention(thin) () -> () { // Defined in _Concurrency sil @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () +sil @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error { +bb0(%0 :$@async @callee_guaranteed () -> ()): + %void = apply %0() : $@async @callee_guaranteed () -> () + return %void : $() +} + // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): %test_case_nothrow = function_ref @test_case : $@convention(thin) @async () -> () - %test_case = convert_function %test_case_nothrow : $@convention(thin) @async () -> () to $@convention(thin) @async () -> @error Error - %thick_test_case = thin_to_thick_function %test_case : $@convention(thin) @async () -> @error Error to $@callee_guaranteed @async () -> @error Error + %thick_test_case = thin_to_thick_function %test_case_nothrow : $@convention(thin) @async () -> () to $@callee_guaranteed @async () -> () + %thunk = function_ref @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error + %throwing = partial_apply [callee_guaranteed] %thunk(%thick_test_case) : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error %runAsyncMain = function_ref @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () - %result = apply %runAsyncMain(%thick_test_case) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () + %result = apply %runAsyncMain(%throwing) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () %out_literal = integer_literal $Builtin.Int32, 0 %out = struct $Int32 (%out_literal : $Builtin.Int32) return %out : $Int32 diff --git a/test/IRGen/async/run-call-structinstance-int64-to-void.sil b/test/IRGen/async/run-call-structinstance-int64-to-void.sil index f727f1b7130c2..58eb252208dd8 100644 --- a/test/IRGen/async/run-call-structinstance-int64-to-void.sil +++ b/test/IRGen/async/run-call-structinstance-int64-to-void.sil @@ -26,7 +26,7 @@ struct S { } // CHECK-LL: @structinstanceSInt64ToVoidTu = -// CHECK-LL: define hidden swift{{(tail)?}}cc void @structinstanceSInt64ToVoid(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define hidden swift{{(tail)?}}cc void @structinstanceSInt64ToVoid( sil hidden @structinstanceSInt64ToVoid : $@async @convention(method) (Int64, S) -> () { bb0(%int : $Int64, %self : $S): %takeSAndInt64 = function_ref @takeSAndInt64 : $@async @convention(thin) (S, Int64) -> () @@ -65,14 +65,21 @@ sil @test_case : $@convention(thin) @async () -> () { // Defined in _Concurrency sil @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () +sil @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error { +bb0(%0 :$@async @callee_guaranteed () -> ()): + %void = apply %0() : $@async @callee_guaranteed () -> () + return %void : $() +} + // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): %test_case_nothrow = function_ref @test_case : $@convention(thin) @async () -> () - %test_case = convert_function %test_case_nothrow : $@convention(thin) @async () -> () to $@convention(thin) @async () -> @error Error - %thick_test_case = thin_to_thick_function %test_case : $@convention(thin) @async () -> @error Error to $@callee_guaranteed @async () -> @error Error + %thick_test_case = thin_to_thick_function %test_case_nothrow : $@convention(thin) @async () -> () to $@callee_guaranteed @async () -> () + %thunk = function_ref @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error + %throwing = partial_apply [callee_guaranteed] %thunk(%thick_test_case) : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error %runAsyncMain = function_ref @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () - %result = apply %runAsyncMain(%thick_test_case) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () + %result = apply %runAsyncMain(%throwing) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () %out_literal = integer_literal $Builtin.Int32, 0 %out = struct $Int32 (%out_literal : $Builtin.Int32) return %out : $Int32 diff --git a/test/IRGen/async/run-call-void-throws-to-int-throwing.sil b/test/IRGen/async/run-call-void-throws-to-int-throwing.sil index 0969dcf4a3daa..48f7827e91000 100644 --- a/test/IRGen/async/run-call-void-throws-to-int-throwing.sil +++ b/test/IRGen/async/run-call-void-throws-to-int-throwing.sil @@ -2,7 +2,7 @@ // RUN: %target-build-swift-dylib(%t/%target-library-name(PrintShims)) %S/../../Inputs/print-shims.swift -module-name PrintShims -emit-module -emit-module-path %t/PrintShims.swiftmodule // RUN: %target-codesign %t/%target-library-name(PrintShims) // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL -// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) +// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) // RUN: %target-codesign %t/main // RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s @@ -100,7 +100,7 @@ bb5: } // CHECK-LL: @voidThrowsToIntTu = -// CHECK-LL: define hidden swift{{(tail)?}}cc void @voidThrowsToInt(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define hidden swift{{(tail)?}}cc void @voidThrowsToInt(%swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} sil hidden @voidThrowsToInt : $@async @convention(thin) () -> (Int, @error Error) { bb0: %e_type = metatype $@thin E.Type @@ -126,14 +126,21 @@ sil @test_case : $@convention(thin) @async () -> () { // Defined in _Concurrency sil @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () +sil @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error { +bb0(%0 :$@async @callee_guaranteed () -> ()): + %void = apply %0() : $@async @callee_guaranteed () -> () + return %void : $() +} + // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): %test_case_nothrow = function_ref @test_case : $@convention(thin) @async () -> () - %test_case = convert_function %test_case_nothrow : $@convention(thin) @async () -> () to $@convention(thin) @async () -> @error Error - %thick_test_case = thin_to_thick_function %test_case : $@convention(thin) @async () -> @error Error to $@callee_guaranteed @async () -> @error Error + %thick_test_case = thin_to_thick_function %test_case_nothrow : $@convention(thin) @async () -> () to $@callee_guaranteed @async () -> () + %thunk = function_ref @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error + %throwing = partial_apply [callee_guaranteed] %thunk(%thick_test_case) : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error %runAsyncMain = function_ref @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () - %result = apply %runAsyncMain(%thick_test_case) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () + %result = apply %runAsyncMain(%throwing) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () %out_literal = integer_literal $Builtin.Int32, 0 %out = struct $Int32 (%out_literal : $Builtin.Int32) return %out : $Int32 diff --git a/test/IRGen/async/run-call-void-throws-to-int-throwing_call-async-nothrow_call-sync-throw.sil b/test/IRGen/async/run-call-void-throws-to-int-throwing_call-async-nothrow_call-sync-throw.sil index 56ea8918b2b83..02108298e7532 100644 --- a/test/IRGen/async/run-call-void-throws-to-int-throwing_call-async-nothrow_call-sync-throw.sil +++ b/test/IRGen/async/run-call-void-throws-to-int-throwing_call-async-nothrow_call-sync-throw.sil @@ -2,7 +2,7 @@ // RUN: %target-build-swift-dylib(%t/%target-library-name(PrintShims)) %S/../../Inputs/print-shims.swift -module-name PrintShims -emit-module -emit-module-path %t/PrintShims.swiftmodule // RUN: %target-codesign %t/%target-library-name(PrintShims) // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL -// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) +// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) // RUN: %target-codesign %t/main // RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s @@ -99,7 +99,7 @@ bb5: } // CHECK-LL: @voidThrowsToIntTu = -// CHECK-LL: define hidden swift{{(tail)?}}cc void @voidThrowsToInt(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define hidden swift{{(tail)?}}cc void @voidThrowsToInt(%swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} sil hidden @voidThrowsToInt : $@async @convention(thin) () -> (Int64, @error Error) { entry: %asyncVoidThrowsToInt = function_ref @asyncVoidThrowsToInt : $@async @convention(thin) () -> (Int64, @error Error) @@ -150,14 +150,21 @@ sil @test_case : $@convention(thin) @async () -> () { // Defined in _Concurrency sil @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () +sil @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error { +bb0(%0 :$@async @callee_guaranteed () -> ()): + %void = apply %0() : $@async @callee_guaranteed () -> () + return %void : $() +} + // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): %test_case_nothrow = function_ref @test_case : $@convention(thin) @async () -> () - %test_case = convert_function %test_case_nothrow : $@convention(thin) @async () -> () to $@convention(thin) @async () -> @error Error - %thick_test_case = thin_to_thick_function %test_case : $@convention(thin) @async () -> @error Error to $@callee_guaranteed @async () -> @error Error + %thick_test_case = thin_to_thick_function %test_case_nothrow : $@convention(thin) @async () -> () to $@callee_guaranteed @async () -> () + %thunk = function_ref @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error + %throwing = partial_apply [callee_guaranteed] %thunk(%thick_test_case) : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error %runAsyncMain = function_ref @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () - %result = apply %runAsyncMain(%thick_test_case) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () + %result = apply %runAsyncMain(%throwing) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () %out_literal = integer_literal $Builtin.Int32, 0 %out = struct $Int32 (%out_literal : $Builtin.Int32) return %out : $Int32 diff --git a/test/IRGen/async/run-call-void-throws-to-int-throwing_call-async-throw.sil b/test/IRGen/async/run-call-void-throws-to-int-throwing_call-async-throw.sil index ffe8d6ccc4b5d..27a67a001a713 100644 --- a/test/IRGen/async/run-call-void-throws-to-int-throwing_call-async-throw.sil +++ b/test/IRGen/async/run-call-void-throws-to-int-throwing_call-async-throw.sil @@ -2,7 +2,7 @@ // RUN: %target-build-swift-dylib(%t/%target-library-name(PrintShims)) %S/../../Inputs/print-shims.swift -module-name PrintShims -emit-module -emit-module-path %t/PrintShims.swiftmodule // RUN: %target-codesign %t/%target-library-name(PrintShims) // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL -// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) +// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) // RUN: %target-codesign %t/main // RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s @@ -100,7 +100,7 @@ bb5: } // CHECK-LL: @voidThrowsToIntTu = -// CHECK-LL: define hidden swift{{(tail)?}}cc void @voidThrowsToInt(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define hidden swift{{(tail)?}}cc void @voidThrowsToInt(%swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} sil hidden @voidThrowsToInt : $@async @convention(thin) () -> (Int, @error Error) { bb0: %asyncVoidThrowsToInt = function_ref @asyncVoidThrowsToInt : $@async @convention(thin) () -> (Int, @error Error) @@ -137,14 +137,21 @@ sil @test_case : $@convention(thin) @async () -> () { // Defined in _Concurrency sil @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () +sil @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error { +bb0(%0 :$@async @callee_guaranteed () -> ()): + %void = apply %0() : $@async @callee_guaranteed () -> () + return %void : $() +} + // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): %test_case_nothrow = function_ref @test_case : $@convention(thin) @async () -> () - %test_case = convert_function %test_case_nothrow : $@convention(thin) @async () -> () to $@convention(thin) @async () -> @error Error - %thick_test_case = thin_to_thick_function %test_case : $@convention(thin) @async () -> @error Error to $@callee_guaranteed @async () -> @error Error + %thick_test_case = thin_to_thick_function %test_case_nothrow : $@convention(thin) @async () -> () to $@callee_guaranteed @async () -> () + %thunk = function_ref @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error + %throwing = partial_apply [callee_guaranteed] %thunk(%thick_test_case) : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error %runAsyncMain = function_ref @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () - %result = apply %runAsyncMain(%thick_test_case) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () + %result = apply %runAsyncMain(%throwing) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () %out_literal = integer_literal $Builtin.Int32, 0 %out = struct $Int32 (%out_literal : $Builtin.Int32) return %out : $Int32 diff --git a/test/IRGen/async/run-call-void-throws-to-int-throwing_call-sync-nothrow_call-async-throw.sil b/test/IRGen/async/run-call-void-throws-to-int-throwing_call-sync-nothrow_call-async-throw.sil index c9c2aace3f485..e8e19073c67ca 100644 --- a/test/IRGen/async/run-call-void-throws-to-int-throwing_call-sync-nothrow_call-async-throw.sil +++ b/test/IRGen/async/run-call-void-throws-to-int-throwing_call-sync-nothrow_call-async-throw.sil @@ -2,7 +2,7 @@ // RUN: %target-build-swift-dylib(%t/%target-library-name(PrintShims)) %S/../../Inputs/print-shims.swift -module-name PrintShims -emit-module -emit-module-path %t/PrintShims.swiftmodule // RUN: %target-codesign %t/%target-library-name(PrintShims) // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL -// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) +// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) // RUN: %target-codesign %t/main // RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s @@ -100,7 +100,7 @@ bb5: } // CHECK-LL: @voidThrowsToIntTu = -// CHECK-LL: define hidden swift{{(tail)?}}cc void @voidThrowsToInt(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define hidden swift{{(tail)?}}cc void @voidThrowsToInt(%swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} sil hidden @voidThrowsToInt : $@async @convention(thin) () -> (Int64, @error Error) { entry: %syncVoidThrowsToInt = function_ref @syncVoidThrowsToInt : $@async @convention(thin) () -> (Int64, @error Error) @@ -151,14 +151,21 @@ sil @test_case : $@convention(thin) @async () -> () { // Defined in _Concurrency sil @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () +sil @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error { +bb0(%0 :$@async @callee_guaranteed () -> ()): + %void = apply %0() : $@async @callee_guaranteed () -> () + return %void : $() +} + // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): %test_case_nothrow = function_ref @test_case : $@convention(thin) @async () -> () - %test_case = convert_function %test_case_nothrow : $@convention(thin) @async () -> () to $@convention(thin) @async () -> @error Error - %thick_test_case = thin_to_thick_function %test_case : $@convention(thin) @async () -> @error Error to $@callee_guaranteed @async () -> @error Error + %thick_test_case = thin_to_thick_function %test_case_nothrow : $@convention(thin) @async () -> () to $@callee_guaranteed @async () -> () + %thunk = function_ref @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error + %throwing = partial_apply [callee_guaranteed] %thunk(%thick_test_case) : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error %runAsyncMain = function_ref @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () - %result = apply %runAsyncMain(%thick_test_case) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () + %result = apply %runAsyncMain(%throwing) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () %out_literal = integer_literal $Builtin.Int32, 0 %out = struct $Int32 (%out_literal : $Builtin.Int32) return %out : $Int32 diff --git a/test/IRGen/async/run-call-void-throws-to-int-throwing_call-sync-throw.sil b/test/IRGen/async/run-call-void-throws-to-int-throwing_call-sync-throw.sil index f63723ed03661..47e9fa0f9b58b 100644 --- a/test/IRGen/async/run-call-void-throws-to-int-throwing_call-sync-throw.sil +++ b/test/IRGen/async/run-call-void-throws-to-int-throwing_call-sync-throw.sil @@ -101,7 +101,7 @@ bb5: } // CHECK-LL: @voidThrowsToIntTu = -// CHECK-LL: define hidden swift{{(tail)?}}cc void @voidThrowsToInt(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define hidden swift{{(tail)?}}cc void @voidThrowsToInt(%swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} sil hidden @voidThrowsToInt : $@async @convention(thin) () -> (Int, @error Error) { bb0: %syncVoidThrowsToInt = function_ref @syncVoidThrowsToInt : $@async @convention(thin) () -> (Int, @error Error) @@ -137,14 +137,21 @@ sil @test_case : $@convention(thin) @async () -> () { // Defined in _Concurrency sil @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () +sil @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error { +bb0(%0 :$@async @callee_guaranteed () -> ()): + %void = apply %0() : $@async @callee_guaranteed () -> () + return %void : $() +} + // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): %test_case_nothrow = function_ref @test_case : $@convention(thin) @async () -> () - %test_case = convert_function %test_case_nothrow : $@convention(thin) @async () -> () to $@convention(thin) @async () -> @error Error - %thick_test_case = thin_to_thick_function %test_case : $@convention(thin) @async () -> @error Error to $@callee_guaranteed @async () -> @error Error + %thick_test_case = thin_to_thick_function %test_case_nothrow : $@convention(thin) @async () -> () to $@callee_guaranteed @async () -> () + %thunk = function_ref @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error + %throwing = partial_apply [callee_guaranteed] %thunk(%thick_test_case) : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error %runAsyncMain = function_ref @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () - %result = apply %runAsyncMain(%thick_test_case) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () + %result = apply %runAsyncMain(%throwing) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () %out_literal = integer_literal $Builtin.Int32, 0 %out = struct $Int32 (%out_literal : $Builtin.Int32) return %out : $Int32 diff --git a/test/IRGen/async/run-call-void-to-existential.sil b/test/IRGen/async/run-call-void-to-existential.sil index f9fc09b957f20..c5c69a79e1bba 100644 --- a/test/IRGen/async/run-call-void-to-existential.sil +++ b/test/IRGen/async/run-call-void-to-existential.sil @@ -2,7 +2,7 @@ // RUN: %target-build-swift-dylib(%t/%target-library-name(PrintShims)) %S/../../Inputs/print-shims.swift -module-name PrintShims -emit-module -emit-module-path %t/PrintShims.swiftmodule // RUN: %target-codesign %t/%target-library-name(PrintShims) // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL -// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) +// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) // RUN: %target-codesign %t/main // RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s @@ -37,7 +37,7 @@ bb0(%int : $Int64, %S_type : $@thin S.Type): } // CHECK-LL: @voidToExistentialTu = -// CHECK-LL: define hidden swift{{(tail)?}}cc void @voidToExistential(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define hidden swift{{(tail)?}}cc void @voidToExistential( sil hidden @voidToExistential : $@async @convention(thin) () -> @out P { bb0(%out : $*P): %S_type = metatype $@thin S.Type @@ -84,14 +84,21 @@ sil @test_case : $@convention(thin) @async () -> () { // Defined in _Concurrency sil @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () +sil @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error { +bb0(%0 :$@async @callee_guaranteed () -> ()): + %void = apply %0() : $@async @callee_guaranteed () -> () + return %void : $() +} + // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): %test_case_nothrow = function_ref @test_case : $@convention(thin) @async () -> () - %test_case = convert_function %test_case_nothrow : $@convention(thin) @async () -> () to $@convention(thin) @async () -> @error Error - %thick_test_case = thin_to_thick_function %test_case : $@convention(thin) @async () -> @error Error to $@callee_guaranteed @async () -> @error Error + %thick_test_case = thin_to_thick_function %test_case_nothrow : $@convention(thin) @async () -> () to $@callee_guaranteed @async () -> () + %thunk = function_ref @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error + %throwing = partial_apply [callee_guaranteed] %thunk(%thick_test_case) : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error %runAsyncMain = function_ref @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () - %result = apply %runAsyncMain(%thick_test_case) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () + %result = apply %runAsyncMain(%throwing) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () %out_literal = integer_literal $Builtin.Int32, 0 %out = struct $Int32 (%out_literal : $Builtin.Int32) return %out : $Int32 diff --git a/test/IRGen/async/run-call-void-to-int64-and-int64.sil b/test/IRGen/async/run-call-void-to-int64-and-int64.sil index 09f2defcb9e1c..062c80fdadaed 100644 --- a/test/IRGen/async/run-call-void-to-int64-and-int64.sil +++ b/test/IRGen/async/run-call-void-to-int64-and-int64.sil @@ -2,7 +2,7 @@ // RUN: %target-build-swift-dylib(%t/%target-library-name(PrintShims)) %S/../../Inputs/print-shims.swift -module-name PrintShims -emit-module -emit-module-path %t/PrintShims.swiftmodule // RUN: %target-codesign %t/%target-library-name(PrintShims) // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL -// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) +// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) // RUN: %target-codesign %t/main // RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s @@ -20,7 +20,7 @@ import _Concurrency sil public_external @printInt64 : $@convention(thin) (Int64) -> () // CHECK-LL: @voidToInt64AndInt64Tu = -// CHECK-LL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @voidToInt64AndInt64(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @voidToInt64AndInt64( sil @voidToInt64AndInt64 : $@async @convention(thin) () -> (Int64, Int64) { %int_literal1 = integer_literal $Builtin.Int64, 42 %int1 = struct $Int64 (%int_literal1 : $Builtin.Int64) @@ -47,14 +47,21 @@ sil @test_case : $@convention(thin) @async () -> () { // Defined in _Concurrency sil @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () +sil @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error { +bb0(%0 :$@async @callee_guaranteed () -> ()): + %void = apply %0() : $@async @callee_guaranteed () -> () + return %void : $() +} + // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): %test_case_nothrow = function_ref @test_case : $@convention(thin) @async () -> () - %test_case = convert_function %test_case_nothrow : $@convention(thin) @async () -> () to $@convention(thin) @async () -> @error Error - %thick_test_case = thin_to_thick_function %test_case : $@convention(thin) @async () -> @error Error to $@callee_guaranteed @async () -> @error Error + %thick_test_case = thin_to_thick_function %test_case_nothrow : $@convention(thin) @async () -> () to $@callee_guaranteed @async () -> () + %thunk = function_ref @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error + %throwing = partial_apply [callee_guaranteed] %thunk(%thick_test_case) : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error %runAsyncMain = function_ref @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () - %result = apply %runAsyncMain(%thick_test_case) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () + %result = apply %runAsyncMain(%throwing) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () %out_literal = integer_literal $Builtin.Int32, 0 %out = struct $Int32 (%out_literal : $Builtin.Int32) return %out : $Int32 diff --git a/test/IRGen/async/run-call-void-to-int64.swift b/test/IRGen/async/run-call-void-to-int64.swift index 76ebe7267b312..721cd72cffd6c 100644 --- a/test/IRGen/async/run-call-void-to-int64.swift +++ b/test/IRGen/async/run-call-void-to-int64.swift @@ -13,7 +13,7 @@ import Swift import _Concurrency // CHECK-LL: @voidToInt64Tu = -// CHECK-LL: define hidden swift{{(tail)?}}cc void @voidToInt64(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define hidden swift{{(tail)?}}cc void @voidToInt64(%swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} @_silgen_name("voidToInt64") func voidToInt64() async -> Int64 { return 42 } diff --git a/test/IRGen/async/run-call-void-to-struct_large.sil b/test/IRGen/async/run-call-void-to-struct_large.sil index 302ecb5889353..0f355ea54c1d7 100644 --- a/test/IRGen/async/run-call-void-to-struct_large.sil +++ b/test/IRGen/async/run-call-void-to-struct_large.sil @@ -2,7 +2,7 @@ // RUN: %target-build-swift-dylib(%t/%target-library-name(PrintShims)) %S/../../Inputs/print-shims.swift -module-name PrintShims -emit-module -emit-module-path %t/PrintShims.swiftmodule // RUN: %target-codesign %t/%target-library-name(PrintShims) // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL -// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) +// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) // RUN: %target-codesign %t/main // RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s @@ -102,7 +102,7 @@ bb0(%0 : $@thin Big.Type): } // CHECK-LL: @getBigTu = -// CHECK-LL: define hidden swift{{(tail)?}}cc void @getBig(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define hidden swift{{(tail)?}}cc void @getBig sil hidden @getBig : $@async @convention(thin) () -> Big { bb0: %0 = metatype $@thin Big.Type @@ -135,14 +135,21 @@ sil @test_case : $@convention(thin) @async () -> () { // Defined in _Concurrency sil @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () +sil @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error { +bb0(%0 :$@async @callee_guaranteed () -> ()): + %void = apply %0() : $@async @callee_guaranteed () -> () + return %void : $() +} + // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): %test_case_nothrow = function_ref @test_case : $@convention(thin) @async () -> () - %test_case = convert_function %test_case_nothrow : $@convention(thin) @async () -> () to $@convention(thin) @async () -> @error Error - %thick_test_case = thin_to_thick_function %test_case : $@convention(thin) @async () -> @error Error to $@callee_guaranteed @async () -> @error Error + %thick_test_case = thin_to_thick_function %test_case_nothrow : $@convention(thin) @async () -> () to $@callee_guaranteed @async () -> () + %thunk = function_ref @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error + %throwing = partial_apply [callee_guaranteed] %thunk(%thick_test_case) : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error %runAsyncMain = function_ref @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () - %result = apply %runAsyncMain(%thick_test_case) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () + %result = apply %runAsyncMain(%throwing) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () %out_literal = integer_literal $Builtin.Int32, 0 %out = struct $Int32 (%out_literal : $Builtin.Int32) return %out : $Int32 diff --git a/test/IRGen/async/run-call_generic-protocolwitness_instance-generic-to-int64-and-generic.sil b/test/IRGen/async/run-call_generic-protocolwitness_instance-generic-to-int64-and-generic.sil index 4a674c2a8b134..f0610e8f3d380 100644 --- a/test/IRGen/async/run-call_generic-protocolwitness_instance-generic-to-int64-and-generic.sil +++ b/test/IRGen/async/run-call_generic-protocolwitness_instance-generic-to-int64-and-generic.sil @@ -46,7 +46,7 @@ bb0(%out_addr : $*T, %in_addr : $*T, %self : $I): } // CHECK-LL: @I_P_printMeTu = -// CHECK-LL: define internal swift{{(tail)?}}cc void @I_P_printMe(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define internal swift{{(tail)?}}cc void @I_P_printMe( sil private [transparent] [thunk] @I_P_printMe : $@convention(witness_method: P) @async <Ï„_0_0> (@in_guaranteed Ï„_0_0, @in_guaranteed I) -> (Int64, @out Ï„_0_0) { bb0(%out_addr : $*Ï„_0_0, %in_addr : $*Ï„_0_0, %self_addr : $*I): %self = load %self_addr : $*I @@ -94,19 +94,25 @@ sil @test_case : $@convention(thin) @async () -> () { // Defined in _Concurrency sil @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () +sil @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error { +bb0(%0 :$@async @callee_guaranteed () -> ()): + %void = apply %0() : $@async @callee_guaranteed () -> () + return %void : $() +} + // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): %test_case_nothrow = function_ref @test_case : $@convention(thin) @async () -> () - %test_case = convert_function %test_case_nothrow : $@convention(thin) @async () -> () to $@convention(thin) @async () -> @error Error - %thick_test_case = thin_to_thick_function %test_case : $@convention(thin) @async () -> @error Error to $@callee_guaranteed @async () -> @error Error + %thick_test_case = thin_to_thick_function %test_case_nothrow : $@convention(thin) @async () -> () to $@callee_guaranteed @async () -> () + %thunk = function_ref @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error + %throwing = partial_apply [callee_guaranteed] %thunk(%thick_test_case) : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error %runAsyncMain = function_ref @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () - %result = apply %runAsyncMain(%thick_test_case) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () + %result = apply %runAsyncMain(%throwing) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () %out_literal = integer_literal $Builtin.Int32, 0 %out = struct $Int32 (%out_literal : $Builtin.Int32) return %out : $Int32 } - sil_witness_table hidden I: P module main { method #P.printMe: (Self) -> (T) async -> (Int64, T) : @I_P_printMe } diff --git a/test/IRGen/async/run-call_generic-protocolwitness_instance-void-to-int64.sil b/test/IRGen/async/run-call_generic-protocolwitness_instance-void-to-int64.sil index 61017cd8867c6..4de435ee79655 100644 --- a/test/IRGen/async/run-call_generic-protocolwitness_instance-void-to-int64.sil +++ b/test/IRGen/async/run-call_generic-protocolwitness_instance-void-to-int64.sil @@ -2,7 +2,7 @@ // RUN: %target-build-swift-dylib(%t/%target-library-name(PrintShims)) %S/../../Inputs/print-shims.swift -module-name PrintShims -emit-module -emit-module-path %t/PrintShims.swiftmodule // RUN: %target-codesign %t/%target-library-name(PrintShims) // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL -// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) +// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) // RUN: %target-codesign %t/main // RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s @@ -32,7 +32,7 @@ struct I : P { // CHECK-LL: @I_printMeTu = // CHECK-LL: @I_P_printMeTu = -// CHECK-LL-LABEL: define hidden swift{{(tail)?}}cc void @I_printMe(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL-LABEL: define hidden swift{{(tail)?}}cc void @I_printMe( sil hidden @I_printMe : $@async @convention(method) (I) -> Int64 { bb0(%self : $I): %self_addr = alloc_stack $I @@ -44,7 +44,7 @@ bb0(%self : $I): return %result : $Int64 } -// CHECK-LL-LABEL: define internal swift{{(tail)?}}cc void @I_P_printMe(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL-LABEL: define internal swift{{(tail)?}}cc void @I_P_printMe( sil private [transparent] [thunk] @I_P_printMe : $@async @convention(witness_method: P) (@in_guaranteed I) -> Int64 { bb0(%self_addr : $*I): %self = load %self_addr : $*I @@ -81,20 +81,25 @@ sil @test_case : $@convention(thin) @async () -> () { // Defined in _Concurrency sil @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () +sil @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error { +bb0(%0 :$@async @callee_guaranteed () -> ()): + %void = apply %0() : $@async @callee_guaranteed () -> () + return %void : $() +} + // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): %test_case_nothrow = function_ref @test_case : $@convention(thin) @async () -> () - %test_case = convert_function %test_case_nothrow : $@convention(thin) @async () -> () to $@convention(thin) @async () -> @error Error - %thick_test_case = thin_to_thick_function %test_case : $@convention(thin) @async () -> @error Error to $@callee_guaranteed @async () -> @error Error + %thick_test_case = thin_to_thick_function %test_case_nothrow : $@convention(thin) @async () -> () to $@callee_guaranteed @async () -> () + %thunk = function_ref @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error + %throwing = partial_apply [callee_guaranteed] %thunk(%thick_test_case) : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error %runAsyncMain = function_ref @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () - %result = apply %runAsyncMain(%thick_test_case) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () + %result = apply %runAsyncMain(%throwing) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () %out_literal = integer_literal $Builtin.Int32, 0 %out = struct $Int32 (%out_literal : $Builtin.Int32) return %out : $Int32 } - - sil_witness_table hidden I: P module main { method #P.printMe: (Self) -> () async -> Int64 : @I_P_printMe } diff --git a/test/IRGen/async/run-convertfunction-int64-to-void.sil b/test/IRGen/async/run-convertfunction-int64-to-void.sil index 80bf89177e8f5..fff27702dd7fe 100644 --- a/test/IRGen/async/run-convertfunction-int64-to-void.sil +++ b/test/IRGen/async/run-convertfunction-int64-to-void.sil @@ -2,7 +2,7 @@ // RUN: %target-build-swift-dylib(%t/%target-library-name(PrintShims)) %S/../../Inputs/print-shims.swift -module-name PrintShims -emit-module -emit-module-path %t/PrintShims.swiftmodule // RUN: %target-codesign %t/%target-library-name(PrintShims) // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL -// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) +// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) // RUN: %target-codesign %t/main // RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s @@ -18,18 +18,25 @@ import _Concurrency sil public_external @printInt64 : $@convention(thin) (Int64) -> () -// CHECK-LL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @int64ToVoid(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @int64ToVoid( sil @int64ToVoid : $@async @convention(thin) (Int64) -> () { entry(%int : $Int64): %printInt64 = function_ref @printInt64 : $@convention(thin) (Int64) -> () %result = apply %printInt64(%int) : $@convention(thin) (Int64) -> () // CHECK: 9999 return %result : $() } +sil @no_throw_to_throw_think_1 : $@convention(thin) @async (Int64, @guaranteed @async @callee_guaranteed (Int64) -> ()) -> @error Error { +bb0(%0: $Int64, %1 :$@async @callee_guaranteed (Int64) -> ()): + %void = apply %1(%0) : $@async @callee_guaranteed (Int64) -> () + return %void : $() +} + sil @test_case : $@convention(thin) @async () -> () { %int64ToVoid = function_ref @int64ToVoid : $@async @convention(thin) (Int64) -> () %int64ToVoidThick = thin_to_thick_function %int64ToVoid : $@convention(thin) @async (Int64) -> () to $@async @callee_guaranteed (Int64) -> () - %int64ThrowsToVoid = convert_function %int64ToVoidThick : $@async @callee_guaranteed (Int64) -> () to $@async @callee_guaranteed (Int64) -> @error Error + %thunk = function_ref @no_throw_to_throw_think_1 : $@convention(thin) @async (Int64, @guaranteed @async @callee_guaranteed (Int64) -> ()) -> @error Error + %int64ThrowsToVoid = partial_apply [callee_guaranteed] %thunk(%int64ToVoidThick) : $@convention(thin) @async (Int64, @guaranteed @async @callee_guaranteed (Int64) -> ()) -> @error Error %int_literal = integer_literal $Builtin.Int64, 9999 %int = struct $Int64 (%int_literal : $Builtin.Int64) try_apply %int64ThrowsToVoid(%int) : $@async @callee_guaranteed (Int64) -> @error Error, normal success, error failure @@ -46,14 +53,21 @@ failure(%error : $Error): // Defined in _Concurrency sil @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () +sil @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error { +bb0(%0 :$@async @callee_guaranteed () -> ()): + %void = apply %0() : $@async @callee_guaranteed () -> () + return %void : $() +} + // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): %test_case_nothrow = function_ref @test_case : $@convention(thin) @async () -> () - %test_case = convert_function %test_case_nothrow : $@convention(thin) @async () -> () to $@convention(thin) @async () -> @error Error - %thick_test_case = thin_to_thick_function %test_case : $@convention(thin) @async () -> @error Error to $@callee_guaranteed @async () -> @error Error + %thick_test_case = thin_to_thick_function %test_case_nothrow : $@convention(thin) @async () -> () to $@callee_guaranteed @async () -> () + %thunk = function_ref @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error + %throwing = partial_apply [callee_guaranteed] %thunk(%thick_test_case) : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error %runAsyncMain = function_ref @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () - %result = apply %runAsyncMain(%thick_test_case) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () + %result = apply %runAsyncMain(%throwing) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () %out_literal = integer_literal $Builtin.Int32, 0 %out = struct $Int32 (%out_literal : $Builtin.Int32) return %out : $Int32 diff --git a/test/IRGen/async/run-partialapply-capture-class-to-void.sil b/test/IRGen/async/run-partialapply-capture-class-to-void.sil index bb4fba3380850..205749ea40fc2 100644 --- a/test/IRGen/async/run-partialapply-capture-class-to-void.sil +++ b/test/IRGen/async/run-partialapply-capture-class-to-void.sil @@ -58,7 +58,7 @@ sil_vtable S { } // CHECK-LL: @classinstanceSToVoidTu = -// CHECK-LL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @classinstanceSToVoid(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @classinstanceSToVoid( sil @classinstanceSToVoid : $@async @convention(thin) (@owned S) -> () { entry(%c : $S): %class_addr = alloc_stack $S @@ -95,14 +95,21 @@ sil @test_case : $@convention(thin) @async () -> () { // Defined in _Concurrency sil @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () +sil @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error { +bb0(%0 :$@async @callee_guaranteed () -> ()): + %void = apply %0() : $@async @callee_guaranteed () -> () + return %void : $() +} + // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): %test_case_nothrow = function_ref @test_case : $@convention(thin) @async () -> () - %test_case = convert_function %test_case_nothrow : $@convention(thin) @async () -> () to $@convention(thin) @async () -> @error Error - %thick_test_case = thin_to_thick_function %test_case : $@convention(thin) @async () -> @error Error to $@callee_guaranteed @async () -> @error Error + %thick_test_case = thin_to_thick_function %test_case_nothrow : $@convention(thin) @async () -> () to $@callee_guaranteed @async () -> () + %thunk = function_ref @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error + %throwing = partial_apply [callee_guaranteed] %thunk(%thick_test_case) : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error %runAsyncMain = function_ref @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () - %result = apply %runAsyncMain(%thick_test_case) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () + %result = apply %runAsyncMain(%throwing) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () %out_literal = integer_literal $Builtin.Int32, 0 %out = struct $Int32 (%out_literal : $Builtin.Int32) return %out : $Int32 diff --git a/test/IRGen/async/run-partialapply-capture-classinstance-to-void.sil b/test/IRGen/async/run-partialapply-capture-classinstance-to-void.sil index 93d8beddc40ce..b9df72932e95e 100644 --- a/test/IRGen/async/run-partialapply-capture-classinstance-to-void.sil +++ b/test/IRGen/async/run-partialapply-capture-classinstance-to-void.sil @@ -58,7 +58,7 @@ sil_vtable S { } // CHECK-LL: @classinstanceSToVoidTu = -// CHECK-LL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @classinstanceSToVoid(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @classinstanceSToVoid( sil @classinstanceSToVoid : $@async @convention(method) (@owned S) -> () { entry(%c : $S): %class_addr = alloc_stack $S @@ -89,14 +89,21 @@ sil @test_case : $@convention(thin) @async () -> () { // Defined in _Concurrency sil @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () +sil @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error { +bb0(%0 :$@async @callee_guaranteed () -> ()): + %void = apply %0() : $@async @callee_guaranteed () -> () + return %void : $() +} + // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): %test_case_nothrow = function_ref @test_case : $@convention(thin) @async () -> () - %test_case = convert_function %test_case_nothrow : $@convention(thin) @async () -> () to $@convention(thin) @async () -> @error Error - %thick_test_case = thin_to_thick_function %test_case : $@convention(thin) @async () -> @error Error to $@callee_guaranteed @async () -> @error Error + %thick_test_case = thin_to_thick_function %test_case_nothrow : $@convention(thin) @async () -> () to $@callee_guaranteed @async () -> () + %thunk = function_ref @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error + %throwing = partial_apply [callee_guaranteed] %thunk(%thick_test_case) : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error %runAsyncMain = function_ref @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () - %result = apply %runAsyncMain(%thick_test_case) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () + %result = apply %runAsyncMain(%throwing) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () %out_literal = integer_literal $Builtin.Int32, 0 %out = struct $Int32 (%out_literal : $Builtin.Int32) return %out : $Int32 diff --git a/test/IRGen/async/run-partialapply-capture-classinstance_generic-and-int-to-string.sil b/test/IRGen/async/run-partialapply-capture-classinstance_generic-and-int-to-string.sil new file mode 100644 index 0000000000000..98f2c392d410c --- /dev/null +++ b/test/IRGen/async/run-partialapply-capture-classinstance_generic-and-int-to-string.sil @@ -0,0 +1,300 @@ +// RUN: %empty-directory(%t) +// RUN: %target-build-swift-dylib(%t/%target-library-name(PrintShims)) %S/../../Inputs/print-shims.swift -module-name PrintShims -emit-module -emit-module-path %t/PrintShims.swiftmodule +// RUN: %target-codesign %t/%target-library-name(PrintShims) +// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL +// RUN: %target-sil-opt -sil-inline-generics -enable-sil-verify-all -inline -partial-apply-lowering %s | %FileCheck %s --check-prefix=CHECK-SIL +// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) +// RUN: %target-codesign %t/main +// RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s + +// REQUIRES: executable_test +// REQUIRES: swift_test_mode_optimize_none +// REQUIRES: concurrency +// UNSUPPORTED: use_os_stdlib + +import Builtin +import Swift +import _Concurrency + +// CHECK-LL: @Super_runTu = +// CHECK-LL: @Sub_runTu = +// CHECK-LL: @"$s20partial_apply_methodTw_Tu" = + +protocol Q { + func testU() -> String +} + +sil public_external @printGeneric : $@convention(thin) (@in_guaranteed T) -> () + +class Super { + init(_ t: String) + @_hasStorage private final let t: String { get } + func run(on u: U, at i: Int64) async -> String where U : Q + deinit +} + +@_inheritsConvenienceInitializers class Sub : Super { + @_hasStorage @_hasInitialValue var t2: String? { get set } + override func run(on u: U, at i: Int64) async -> String where U : Q + override init(_ t: String) + deinit +} + +struct QImpl : Q { + func testU() -> String + init() +} + +sil hidden [exact_self_class] @Super_allocating_init : $@convention(method) (@owned String, @thick Super.Type) -> @owned Super { +bb0(%value : $String, %super_type : $@thick Super.Type): + %uninitialized = alloc_ref $Super + %Super_init = function_ref @Super_init : $@convention(method) (@owned String, @owned Super) -> @owned Super + %result = apply %Super_init(%value, %uninitialized) : $@convention(method) (@owned String, @owned Super) -> @owned Super + return %result : $Super +} + +sil hidden @Super_init : $@convention(method) (@owned String, @owned Super) -> @owned Super { +bb0(%value : $String, %instance : $Super): + retain_value %value : $String + %field_addr = ref_element_addr %instance : $Super, #Super.t + store %value to %field_addr : $*String + release_value %value : $String + return %instance : $Super +} + +// CHECK-LL: define hidden swift{{(tail)?}}cc void @Super_run( +sil hidden @Super_run : $@convention(method) @async (@in_guaranteed U, Int64, @guaranteed Super) -> @owned String { +bb0(%generic_addr : $*U, %int_arg : $Int64, %int : $Super): + %printGeneric = function_ref @printGeneric : $@convention(thin) <Ï„_0_0> (@in_guaranteed Ï„_0_0) -> () + // CHECK: QImpl() + %printGeneric_result = apply %printGeneric(%generic_addr) : $@convention(thin) <Ï„_0_0> (@in_guaranteed Ï„_0_0) -> () + %testU = witness_method $U, #Q.testU : (Self) -> () -> String : $@convention(witness_method: Q) <Ï„_0_0 where Ï„_0_0 : Q> (@in_guaranteed Ï„_0_0) -> @owned String + %testU_result = apply %testU(%generic_addr) : $@convention(witness_method: Q) <Ï„_0_0 where Ï„_0_0 : Q> (@in_guaranteed Ï„_0_0) -> @owned String + %testU_result_addr = alloc_stack $String + store %testU_result to %testU_result_addr : $*String + // CHECK: QImpl.testU + %printGeneric_result2 = apply %printGeneric(%testU_result_addr) : $@convention(thin) <Ï„_0_0> (@in_guaranteed Ï„_0_0) -> () + destroy_addr %testU_result_addr : $*String + dealloc_stack %testU_result_addr : $*String + %int_arg_addr = alloc_stack $Int64 + store %int_arg to %int_arg_addr : $*Int64 + // CHECK: 42 + %printGeneric_result3 = apply %printGeneric(%int_arg_addr) : $@convention(thin) <Ï„_0_0> (@in_guaranteed Ï„_0_0) -> () + dealloc_stack %int_arg_addr : $*Int64 + %field_addr = ref_element_addr %int : $Super, #Super.t + %field = load %field_addr : $*String + retain_value %field : $String + return %field : $String +} + +sil hidden @Super_deinit : $@convention(method) (@guaranteed Super) -> @owned Builtin.NativeObject { +bb0(%instance : $Super): + %field_addr = ref_element_addr %instance : $Super, #Super.t + %field = begin_access [deinit] [static] %field_addr : $*String + destroy_addr %field : $*String + end_access %field : $*String + %uninitialized = unchecked_ref_cast %instance : $Super to $Builtin.NativeObject + return %uninitialized : $Builtin.NativeObject +} + +sil hidden @Super_deallocating_deinit : $@convention(method) (@owned Super) -> () { +bb0(%instance : $Super): + %Super_deinit = function_ref @Super_deinit : $@convention(method) (@guaranteed Super) -> @owned Builtin.NativeObject + %uninitialized = apply %Super_deinit(%instance) : $@convention(method) (@guaranteed Super) -> @owned Builtin.NativeObject + %uninitailized_super = unchecked_ref_cast %uninitialized : $Builtin.NativeObject to $Super + dealloc_ref %uninitailized_super : $Super + %out = tuple () + return %out : $() +} + +// CHECK-LL: define hidden swift{{(tail)?}}cc void @Sub_run( +sil hidden @Sub_run : $@convention(method) @async (@in_guaranteed U, Int64, @guaranteed Sub) -> @owned String { +bb0(%U_addr : $*U, %int : $Int64, %sub : $Sub): + strong_retain %sub : $Sub + %super = upcast %sub : $Sub to $Super + %Super_run = function_ref @Super_run : $@convention(method) @async <Ï„_0_0 where Ï„_0_0 : Q> (@in_guaranteed Ï„_0_0, Int64, @guaranteed Super) -> @owned String + %result = apply %Super_run(%U_addr, %int, %super) : $@convention(method) @async <Ï„_0_0 where Ï„_0_0 : Q> (@in_guaranteed Ï„_0_0, Int64, @guaranteed Super) -> @owned String + strong_release %super : $Super + return %result : $String +} + +sil hidden [exact_self_class] @Sub_allocating_init : $@convention(method) (@owned String, @thick Sub.Type) -> @owned Sub { +bb0(%value : $String, %type : $@thick Sub.Type): + %uninitialized = alloc_ref $Sub + %Sub_init = function_ref @Sub_init : $@convention(method) (@owned String, @owned Sub) -> @owned Sub + %result = apply %Sub_init(%value, %uninitialized) : $@convention(method) (@owned String, @owned Sub) -> @owned Sub + return %result : $Sub +} + +sil hidden @Sub_init : $@convention(method) (@owned String, @owned Sub) -> @owned Sub { +bb0(%value : $String, %uninitialized : $Sub): + %field_addr = ref_element_addr %uninitialized : $Sub, #Sub.t2 + %none = enum $Optional, #Optional.none!enumelt + store %none to %field_addr : $*Optional + %uninitialized_super = upcast %uninitialized : $Sub to $Super + retain_value %value : $String + %Super_init = function_ref @Super_init : $@convention(method) (@owned String, @owned Super) -> @owned Super + %result_super = apply %Super_init(%value, %uninitialized_super) : $@convention(method) (@owned String, @owned Super) -> @owned Super + %result = unchecked_ref_cast %result_super : $Super to $Sub + strong_retain %result : $Sub + release_value %value : $String + return %result : $Sub +} + +sil hidden @Sub_deinit : $@convention(method) (@guaranteed Sub) -> @owned Builtin.NativeObject { +bb0(%initialized : $Sub): + %initialized_super = upcast %initialized : $Sub to $Super + %Super_deinit = function_ref @Super_deinit : $@convention(method) (@guaranteed Super) -> @owned Builtin.NativeObject + %uninitialized = apply %Super_deinit(%initialized_super) : $@convention(method) (@guaranteed Super) -> @owned Builtin.NativeObject + %uninitialized_super = unchecked_ref_cast %uninitialized : $Builtin.NativeObject to $Sub + %field_addr = ref_element_addr %uninitialized_super : $Sub, #Sub.t2 + %field = begin_access [deinit] [static] %field_addr : $*Optional + destroy_addr %field : $*Optional + end_access %field : $*Optional + return %uninitialized : $Builtin.NativeObject +} + +sil hidden @Sub_deallocating_deinit : $@convention(method) (@owned Sub) -> () { +bb0(%initialized : $Sub): + %Sub_deinit = function_ref @Sub_deinit : $@convention(method) (@guaranteed Sub) -> @owned Builtin.NativeObject + %uninitialized = apply %Sub_deinit(%initialized) : $@convention(method) (@guaranteed Sub) -> @owned Builtin.NativeObject + %uninitialized_sub = unchecked_ref_cast %uninitialized : $Builtin.NativeObject to $Sub + dealloc_ref %uninitialized_sub : $Sub + %out = tuple () + return %out : $() +} + +// CHECK-SIL-LABEL: sil hidden @partial_apply_method +// CHECK-SIL-SAME: : $@convention(thin) ( +// CHECK-SIL-SAME: @guaranteed Super, +// CHECK-SIL-SAME: @convention(method) @async (@in_guaranteed U, Int64, @guaranteed Super) -> @owned String +// CHECK-SIL-SAME: ) -> +// CHECK-SIL-SAME: @async @callee_guaranteed (@in_guaranteed U, Int64) -> @owned String { +// CHECK-SIL: bb0( +// CHECK-SIL-SAME: [[INSTANCE:%[^,]+]] : $Super, +// CHECK-SIL-SAME: [[DYNAMIC_METHOD:%[^,]+]] : $@convention(method) @async <Ï„_0_0 where Ï„_0_0 : Q> (@in_guaranteed Ï„_0_0, Int64, @guaranteed Super) -> @owned String +// CHECK-SIL-SAME: ): +// CHECK-SIL: [[THUNK:%[^,]+]] = function_ref @$s20partial_apply_methodTw_ : $@convention(thin) @async <Ï„_0_0 where Ï„_0_0 : Q> (@in_guaranteed Ï„_0_0, Int64, @guaranteed Super, @convention(method) @async <Ï„_0_0 where Ï„_0_0 : Q> (@in_guaranteed Ï„_0_0, Int64, @guaranteed Super) -> @owned String) -> @owned String +// CHECK-SIL: [[RESULT:%[^,]+]] = partial_apply [callee_guaranteed] [[THUNK]]([[INSTANCE]], [[DYNAMIC_METHOD]]) : $@convention(thin) @async <Ï„_0_0 where Ï„_0_0 : Q> (@in_guaranteed Ï„_0_0, Int64, @guaranteed Super, @convention(method) @async <Ï„_0_0 where Ï„_0_0 : Q> (@in_guaranteed Ï„_0_0, Int64, @guaranteed Super) -> @owned String) -> @owned String +// CHECK-SIL: return [[RESULT]] : $@async @callee_guaranteed (@in_guaranteed U, Int64) -> @owned String +// CHECK-SIL-LABEL: } // end sil function 'partial_apply_method' + +// CHECK-SIL-LABEL: sil private [thunk] [ossa] @$s20partial_apply_methodTw_ : $@convention(thin) @async ( +// CHECK-SIL-SAME: @in_guaranteed U, +// CHECK-SIL-SAME: Int64, +// CHECK-SIL-SAME: @guaranteed Super, +// CHECK-SIL-SAME: @convention(method) @async (@in_guaranteed U, Int64, @guaranteed Super) -> @owned String) -> @owned String +// CHECK-SIL-SAME: { +// CHECK-SIL: bb0( +// CHECK-SIL-SAME: [[GENERIC_ADDR:%[^,]+]] : $*U, +// CHECK-SIL-SAME: [[INT:%[^,]+]] : $Int64, +// CHECK-SIL-SAME: [[INSTANCE:%[^,]+]] : @guaranteed $Super, +// CHECK-SIL-SAME: [[METHOD:%[^,]+]] : $@convention(method) @async <Ï„_0_0 where Ï„_0_0 : Q> (@in_guaranteed Ï„_0_0, Int64, @guaranteed Super) -> @owned String +// CHECK-SIL-SAME: ): +// CHECK-SIL: [[RESULT:%[^,]+]] = apply [[METHOD]]( +// CHECK-SIL-SAME: [[GENERIC_ADDR]], +// CHECK-SIL-SAME: [[INT]], +// CHECK-SIL-SAME: [[INSTANCE]] +// CHECK-SIL-SAME: ) : $@convention(method) @async <Ï„_0_0 where Ï„_0_0 : Q> (@in_guaranteed Ï„_0_0, Int64, @guaranteed Super) -> @owned String +// CHECK-SIL: return [[RESULT]] : $String +// CHECK-SIL-LABEL: } // end sil function '$s20partial_apply_methodTw_' + +// CHECK-LL: define internal swift{{(tail)?}}cc void @"$s20partial_apply_methodTw_TA"( +sil hidden @partial_apply_method : $@convention(thin) (@guaranteed Super, @convention(method) @async <Ï„_0_0 where Ï„_0_0 : Q> (@in_guaranteed Ï„_0_0, Int64, @guaranteed Super) -> @owned String) -> @callee_guaranteed @async (@in_guaranteed U, Int64) -> @owned String { +entry(%int : $Super, %fn : $@convention(method) @async <Ï„_0_0 where Ï„_0_0 : Q> (@in_guaranteed Ï„_0_0, Int64, @guaranteed Super) -> @owned String): + %pa = partial_apply [callee_guaranteed] %fn(%int) : $@convention(method) @async <Ï„_0_0 where Ï„_0_0 : Q> (@in_guaranteed Ï„_0_0, Int64, @guaranteed Super) -> @owned String + return %pa : $@callee_guaranteed @async (@in_guaranteed U, Int64) -> @owned String +} + +sil hidden @doit : $@convention(thin) @async (Int64, @in_guaranteed U, @guaranteed Super) -> @owned String { +bb0(%int : $Int64, %generic_addr : $*U, %instance : $Super): + %run_method = class_method %instance : $Super, #Super.run : (Super) -> (U, Int64) async -> String, $@convention(method) @async <Ï„_0_0 where Ï„_0_0 : Q> (@in_guaranteed Ï„_0_0, Int64, @guaranteed Super) -> @owned String + %partial_apply_method = function_ref @partial_apply_method : $@convention(thin) (@guaranteed Super, @convention(method) @async <Ï„_0_0 where Ï„_0_0 : Q> (@in_guaranteed Ï„_0_0, Int64, @guaranteed Super) -> @owned String) -> @callee_guaranteed @async (@in_guaranteed U, Int64) -> @owned String + %partially_applied_method = apply %partial_apply_method(%instance, %run_method) : $@convention(thin) (@guaranteed Super, @convention(method) @async <Ï„_0_0 where Ï„_0_0 : Q> (@in_guaranteed Ï„_0_0, Int64, @guaranteed Super) -> @owned String) -> @callee_guaranteed @async (@in_guaranteed U, Int64) -> @owned String + %result = apply %partially_applied_method(%generic_addr, %int) : $@callee_guaranteed @async (@in_guaranteed U, Int64) -> @owned String + return %result : $String +} + +sil hidden @QImpl_testU : $@convention(method) (QImpl) -> @owned String { +bb0(%instance : $QImpl): + %string_literal = string_literal utf8 "QImpl.testU" + %utf8CodeUnitCount = integer_literal $Builtin.Word, 11 + %isASCII = integer_literal $Builtin.Int1, -1 + %string_type = metatype $@thin String.Type + %String_init = function_ref @$sSS21_builtinStringLiteral17utf8CodeUnitCount7isASCIISSBp_BwBi1_tcfC : $@convention(method) (Builtin.RawPointer, Builtin.Word, Builtin.Int1, @thin String.Type) -> @owned String + %result = apply %String_init(%string_literal, %utf8CodeUnitCount, %isASCII, %string_type) : $@convention(method) (Builtin.RawPointer, Builtin.Word, Builtin.Int1, @thin String.Type) -> @owned String + return %result : $String +} + +sil [serialized] [always_inline] [readonly] [_semantics "string.makeUTF8"] @$sSS21_builtinStringLiteral17utf8CodeUnitCount7isASCIISSBp_BwBi1_tcfC : $@convention(method) (Builtin.RawPointer, Builtin.Word, Builtin.Int1, @thin String.Type) -> @owned String + +sil private [transparent] [thunk] @QImpl_testU_conformance_thunk : $@convention(witness_method: Q) (@in_guaranteed QImpl) -> @owned String { +bb0(%qimpl_addr : $*QImpl): + %qimpl = load %qimpl_addr : $*QImpl + %QImpl_testU = function_ref @QImpl_testU : $@convention(method) (QImpl) -> @owned String + %result = apply %QImpl_testU(%qimpl) : $@convention(method) (QImpl) -> @owned String + return %result : $String +} + +sil @test_case : $@convention(thin) @async () -> () { + %sub_type = metatype $@thick Sub.Type + %string_literal = string_literal utf8 "42" + %utf8CodeUnitCount = integer_literal $Builtin.Word, 2 + %isASCII = integer_literal $Builtin.Int1, -1 + %string_type = metatype $@thin String.Type + %string_init = function_ref @$sSS21_builtinStringLiteral17utf8CodeUnitCount7isASCIISSBp_BwBi1_tcfC : $@convention(method) (Builtin.RawPointer, Builtin.Word, Builtin.Int1, @thin String.Type) -> @owned String + %string = apply %string_init(%string_literal, %utf8CodeUnitCount, %isASCII, %string_type) : $@convention(method) (Builtin.RawPointer, Builtin.Word, Builtin.Int1, @thin String.Type) -> @owned String + %Sub_allocating_init = function_ref @Sub_allocating_init : $@convention(method) (@owned String, @thick Sub.Type) -> @owned Sub + %instance_sub = apply %Sub_allocating_init(%string, %sub_type) : $@convention(method) (@owned String, @thick Sub.Type) -> @owned Sub + %int_literal = integer_literal $Builtin.Int64, 42 + %int = struct $Int64 (%int_literal : $Builtin.Int64) + %qimpl = struct $QImpl () + %qimpl_addr = alloc_stack $QImpl + store %qimpl to %qimpl_addr : $*QImpl + %instance_super = upcast %instance_sub : $Sub to $Super + %doit = function_ref @doit : $@convention(thin) @async <Ï„_0_0 where Ï„_0_0 : Q> (Int64, @in_guaranteed Ï„_0_0, @guaranteed Super) -> @owned String + %doit_result = apply %doit(%int, %qimpl_addr, %instance_super) : $@convention(thin) @async <Ï„_0_0 where Ï„_0_0 : Q> (Int64, @in_guaranteed Ï„_0_0, @guaranteed Super) -> @owned String + dealloc_stack %qimpl_addr : $*QImpl + strong_release %instance_sub : $Sub + + %void = tuple() + return %void : $() +} + +// Defined in _Concurrency +sil @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () + +sil @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error { +bb0(%0 :$@async @callee_guaranteed () -> ()): + %void = apply %0() : $@async @callee_guaranteed () -> () + return %void : $() +} + +// main +sil @main : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { +bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): + %test_case_nothrow = function_ref @test_case : $@convention(thin) @async () -> () + %thick_test_case = thin_to_thick_function %test_case_nothrow : $@convention(thin) @async () -> () to $@callee_guaranteed @async () -> () + %thunk = function_ref @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error + %throwing = partial_apply [callee_guaranteed] %thunk(%thick_test_case) : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error + %runAsyncMain = function_ref @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () + %result = apply %runAsyncMain(%throwing) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () + %out_literal = integer_literal $Builtin.Int32, 0 + %out = struct $Int32 (%out_literal : $Builtin.Int32) + return %out : $Int32 +} +sil_vtable Super { + #Super.init!allocator: (Super.Type) -> (String) -> Super : @Super_allocating_init + #Super.run: (Super) -> (U, Int64) async -> String : @Super_run + #Super.deinit!deallocator: @Super_deallocating_deinit +} + +sil_vtable Sub { + #Super.init!allocator: (Super.Type) -> (String) -> Super : @Sub_allocating_init [override] + #Super.run: (Super) -> (U, Int64) async -> String : @Sub_run [override] + #Sub.deinit!deallocator: @Sub_deallocating_deinit +} + +sil_witness_table hidden QImpl: Q module main { + method #Q.testU: (Self) -> () -> String : @QImpl_testU_conformance_thunk +} diff --git a/test/IRGen/async/run-partialapply-capture-generic_conformer-and-generic-to-void.sil b/test/IRGen/async/run-partialapply-capture-generic_conformer-and-generic-to-void.sil index cae1036a1e4ac..c169679464b91 100644 --- a/test/IRGen/async/run-partialapply-capture-generic_conformer-and-generic-to-void.sil +++ b/test/IRGen/async/run-partialapply-capture-generic_conformer-and-generic-to-void.sil @@ -2,7 +2,8 @@ // RUN: %target-build-swift-dylib(%t/%target-library-name(PrintShims)) %S/../../Inputs/print-shims.swift -module-name PrintShims -emit-module -emit-module-path %t/PrintShims.swiftmodule // RUN: %target-codesign %t/%target-library-name(PrintShims) // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL -// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) +// RUN: %target-sil-opt -sil-inline-generics -enable-sil-verify-all -inline -partial-apply-lowering %s | %FileCheck %s --check-prefix=CHECK-SIL +// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) // RUN: %target-codesign %t/main // RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s @@ -13,7 +14,6 @@ import Builtin import Swift -import PrintShims import _Concurrency sil public_external @printGeneric : $@convention(thin) (@in_guaranteed T) -> () @@ -29,7 +29,7 @@ class ObservableImpl : Observable { } sil_vtable ObservableImpl { } -// CHECK-LL: define hidden swift{{(tail)?}}cc void @subscribe_ObservableImpl_Observable(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define hidden swift{{(tail)?}}cc void @subscribe_ObservableImpl_Observable( sil hidden @subscribe_ObservableImpl_Observable : $@convention(witness_method: Observable) @async <Ï„_0_0 where Ï„_0_0 : Observer> (@in_guaranteed Ï„_0_0, @in_guaranteed ObservableImpl) -> () { bb0(%observer : $*Ï„_0_0, %self : $*ObservableImpl): %printGeneric = function_ref @printGeneric : $@convention(thin) (@in_guaranteed T) -> () @@ -55,12 +55,78 @@ sil_witness_table ObserverImpl : Observer module main { associated_type Result : () } -// CHECK-LL: define internal swift{{(tail)?}}cc void @"$sTA"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} -sil hidden @witness_method : $@async @convention(thin) (@in S) -> @owned @async @callee_owned (@in O) -> () { +// CHECK-SIL-LABEL: sil hidden @witness_method +// CHECK-SIL-SAME: : $@convention(thin) @async +// CHECK-SIL-SAME: +// CHECK-SIL-SAME: +// CHECK-SIL-SAME: (@in S) -> @owned @async @callee_guaranteed (@in O) -> () { +// CHECK-SIL: bb0([[S_INSTANCE:%[^,]+]] : $*S): +// CHECK-SIL: [[WITNESS_METHOD:%[^,]+]] = witness_method $S, #Observable.subscribe +// CHECK-SIL-SAME: : (Self) -> (T) async -> () +// CHECK-SIL-SAME: : $@convention(witness_method: Observable) @async +// CHECK-SIL-SAME: <Ï„_0_0 where Ï„_0_0 : Observable> +// CHECK-SIL-SAME: <Ï„_1_0 where Ï„_1_0 : Observer, Ï„_0_0.Result == Ï„_1_0.Result> +// CHECK-SIL-SAME: (@in Ï„_1_0, @in_guaranteed Ï„_0_0) -> () +// CHECK-SIL: [[THUNK:%[^,]+]] = function_ref @$s14witness_methodTw_ +// CHECK-SIL-SAME: : $@convention(thin) @async +// CHECK-SIL-SAME: <Ï„_0_0 where Ï„_0_0 : Observable> +// CHECK-SIL-SAME: <Ï„_1_0 where Ï„_1_0 : Observer, Ï„_0_0.Result == Ï„_1_0.Result> +// CHECK-SIL-SAME: ( +// CHECK-SIL-SAME: @in Ï„_1_0, +// CHECK-SIL-SAME: @in_guaranteed Ï„_0_0, +// CHECK-SIL-SAME: @convention(witness_method: Observable) @async +// CHECK-SIL-SAME: <Ï„_0_0 where Ï„_0_0 : Observable> +// CHECK-SIL-SAME: <Ï„_1_0 where Ï„_1_0 : Observer, Ï„_0_0.Result == Ï„_1_0.Result> +// CHECK-SIL-SAME: (@in Ï„_1_0, @in_guaranteed Ï„_0_0) -> () +// CHECK-SIL-SAME: ) -> () +// CHECK-SIL: [[RESULT:%[^,]+]] = partial_apply [callee_guaranteed] [[THUNK]]([[S_INSTANCE]], [[WITNESS_METHOD]]) +// CHECK-SIL-SAME: : $@convention(thin) @async +// CHECK-SIL-SAME: <Ï„_0_0 where Ï„_0_0 : Observable> +// CHECK-SIL-SAME: <Ï„_1_0 where Ï„_1_0 : Observer, Ï„_0_0.Result == Ï„_1_0.Result> +// CHECK-SIL-SAME: ( +// CHECK-SIL-SAME: @in Ï„_1_0, +// CHECK-SIL-SAME: @in_guaranteed Ï„_0_0, +// CHECK-SIL-SAME: @convention(witness_method: Observable) @async +// CHECK-SIL-SAME: <Ï„_0_0 where Ï„_0_0 : Observable> +// CHECK-SIL-SAME: <Ï„_1_0 where Ï„_1_0 : Observer, Ï„_0_0.Result == Ï„_1_0.Result> +// CHECK-SIL-SAME: (@in Ï„_1_0, @in_guaranteed Ï„_0_0) -> () +// CHECK-SIL-SAME: ) -> () +// CHECK-SIL: return [[RESULT]] : $@async @callee_guaranteed (@in O) -> () +// CHECK-SIL-LABEL: } // end sil function 'witness_method' + +// CHECK-SIL-LABEL: sil private [thunk] [ossa] @$s14witness_methodTw_ +// CHECK-SIL-SAME: : $@convention(thin) @async +// CHECK-SIL-SAME: +// CHECK-SIL-SAME: +// CHECK-SIL-SAME: ( +// CHECK-SIL-SAME: @in O, +// CHECK-SIL-SAME: @in_guaranteed S, +// CHECK-SIL-SAME: @convention(witness_method: Observable) @async +// CHECK-SIL-SAME: +// CHECK-SIL-SAME: +// CHECK-SIL-SAME: (@in O, @in_guaranteed S) -> () +// CHECK-SIL-SAME: ) -> () { +// CHECK-SIL: bb0( +// CHECK-SIL-SAME: [[O_INSTANCE:%[^,]+]] : $*O, +// CHECK-SIL-SAME: [[S_INSTANCE:%[^,]+]] : $*S, +// CHECK-SIL-SAME: [[WITNESS_METHOD:%[^,]+]] : $ +// CHECK-SIL-SAME: @convention(witness_method: Observable) @async +// CHECK-SIL-SAME: <Ï„_0_0 where Ï„_0_0 : Observable><Ï„_1_0 where Ï„_1_0 : Observer, Ï„_0_0.Result == Ï„_1_0.Result> +// CHECK-SIL-SAME: (@in Ï„_1_0, @in_guaranteed Ï„_0_0) -> () +// CHECK-SIL-SAME: ): +// CHECK-SIL: [[RESULT:%[^,]+]] = apply [[WITNESS_METHOD]]( +// CHECK-SIL-SAME: [[O_INSTANCE]], +// CHECK-SIL-SAME: [[S_INSTANCE]] +// CHECK-SIL-SAME: ) : $@convention(witness_method: Observable) @async <Ï„_0_0 where Ï„_0_0 : Observable><Ï„_1_0 where Ï„_1_0 : Observer, Ï„_0_0.Result == Ï„_1_0.Result> (@in Ï„_1_0, @in_guaranteed Ï„_0_0) -> () +// CHECK-SIL: return [[RESULT]] : $() +// CHECK-SIL-LABEL: } // end sil function '$s14witness_methodTw_' + +// CHECK-LL: define internal swift{{(tail)?}}cc void @"$s14witness_methodTw_TA"( +sil hidden @witness_method : $@async @convention(thin) (@in S) -> @owned @async @callee_guaranteed (@in O) -> () { bb0(%0 : $*S): %1 = witness_method $S, #Observable.subscribe : $@async @convention(witness_method: Observable) <Ï„_0_0 where Ï„_0_0 : Observable><Ï„_1_0 where Ï„_1_0 : Observer, Ï„_0_0.Result == Ï„_1_0.Result> (@in Ï„_1_0, @in_guaranteed Ï„_0_0) -> () - %2 = partial_apply %1(%0) : $@async @convention(witness_method: Observable) <Ï„_0_0 where Ï„_0_0 : Observable><Ï„_1_0 where Ï„_1_0 : Observer, Ï„_0_0.Result == Ï„_1_0.Result> (@in Ï„_1_0, @in_guaranteed Ï„_0_0) -> () - return %2 : $@async @callee_owned (@in O) -> () + %2 = partial_apply [callee_guaranteed] %1(%0) : $@async @convention(witness_method: Observable) <Ï„_0_0 where Ï„_0_0 : Observable><Ï„_1_0 where Ï„_1_0 : Observer, Ï„_0_0.Result == Ï„_1_0.Result> (@in Ï„_1_0, @in_guaranteed Ï„_0_0) -> () + return %2 : $@async @callee_guaranteed (@in O) -> () } @@ -69,13 +135,13 @@ sil @test_case : $@convention(thin) @async () -> () { strong_retain %observableImpl : $ObservableImpl %observableImpl_addr = alloc_stack $ObservableImpl store %observableImpl to %observableImpl_addr : $*ObservableImpl - %witness_method = function_ref @witness_method : $@async @convention(thin) (@in S) -> @owned @async @callee_owned (@in O) -> () - %partiallyApplied = apply %witness_method(%observableImpl_addr) : $@async @convention(thin) (@in S) -> @owned @async @callee_owned (@in O) -> () + %witness_method = function_ref @witness_method : $@async @convention(thin) (@in S) -> @owned @async @callee_guaranteed (@in O) -> () + %partiallyApplied = apply %witness_method(%observableImpl_addr) : $@async @convention(thin) (@in S) -> @owned @async @callee_guaranteed (@in O) -> () %observerImpl = alloc_ref $ObserverImpl %observerImpl_addr = alloc_stack $ObserverImpl store %observerImpl to %observerImpl_addr : $*ObserverImpl - %result = apply %partiallyApplied(%observerImpl_addr) : $@async @callee_owned (@in ObserverImpl) -> () + %result = apply %partiallyApplied(%observerImpl_addr) : $@async @callee_guaranteed (@in ObserverImpl) -> () dealloc_stack %observerImpl_addr : $*ObserverImpl dealloc_stack %observableImpl_addr : $*ObservableImpl @@ -87,14 +153,21 @@ sil @test_case : $@convention(thin) @async () -> () { // Defined in _Concurrency sil @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () +sil @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error { +bb0(%0 :$@async @callee_guaranteed () -> ()): + %void = apply %0() : $@async @callee_guaranteed () -> () + return %void : $() +} + // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): %test_case_nothrow = function_ref @test_case : $@convention(thin) @async () -> () - %test_case = convert_function %test_case_nothrow : $@convention(thin) @async () -> () to $@convention(thin) @async () -> @error Error - %thick_test_case = thin_to_thick_function %test_case : $@convention(thin) @async () -> @error Error to $@callee_guaranteed @async () -> @error Error + %thick_test_case = thin_to_thick_function %test_case_nothrow : $@convention(thin) @async () -> () to $@callee_guaranteed @async () -> () + %thunk = function_ref @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error + %throwing = partial_apply [callee_guaranteed] %thunk(%thick_test_case) : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error %runAsyncMain = function_ref @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () - %result = apply %runAsyncMain(%thick_test_case) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () + %result = apply %runAsyncMain(%throwing) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () %out_literal = integer_literal $Builtin.Int32, 0 %out = struct $Int32 (%out_literal : $Builtin.Int32) return %out : $Int32 diff --git a/test/IRGen/async/run-partialapply-capture-inout-generic-and-in-generic-to-generic.sil b/test/IRGen/async/run-partialapply-capture-inout-generic-and-in-generic-to-generic.sil index 7563906d7a23a..075871eeae93d 100644 --- a/test/IRGen/async/run-partialapply-capture-inout-generic-and-in-generic-to-generic.sil +++ b/test/IRGen/async/run-partialapply-capture-inout-generic-and-in-generic-to-generic.sil @@ -20,8 +20,8 @@ sil public_external @printGeneric : $@convention(thin) (@in_guaranteed T) -> sil public_external @printInt64 : $@convention(thin) (Int64) -> () // CHECK-LL: @inGenericAndInoutGenericToGenericTu = -// CHECK-LL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @inGenericAndInoutGenericToGeneric(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} -// CHECK-LL: define internal swift{{(tail)?}}cc void @"$s017inGenericAndInoutb2ToB0TA"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @inGenericAndInoutGenericToGeneric( +// CHECK-LL: define internal swift{{(tail)?}}cc void @"$s017inGenericAndInoutb2ToB0TA"( sil @inGenericAndInoutGenericToGeneric : $@async @convention(thin) (@in T, @inout T) -> @out T { entry(%out : $*T, %in : $*T, %inout : $*T): %printGeneric = function_ref @printGeneric : $@convention(thin) (@in_guaranteed T) -> () @@ -71,14 +71,21 @@ sil @test_case : $@convention(thin) @async () -> () { // Defined in _Concurrency sil @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () +sil @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error { +bb0(%0 :$@async @callee_guaranteed () -> ()): + %void = apply %0() : $@async @callee_guaranteed () -> () + return %void : $() +} + // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): %test_case_nothrow = function_ref @test_case : $@convention(thin) @async () -> () - %test_case = convert_function %test_case_nothrow : $@convention(thin) @async () -> () to $@convention(thin) @async () -> @error Error - %thick_test_case = thin_to_thick_function %test_case : $@convention(thin) @async () -> @error Error to $@callee_guaranteed @async () -> @error Error + %thick_test_case = thin_to_thick_function %test_case_nothrow : $@convention(thin) @async () -> () to $@callee_guaranteed @async () -> () + %thunk = function_ref @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error + %throwing = partial_apply [callee_guaranteed] %thunk(%thick_test_case) : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error %runAsyncMain = function_ref @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () - %result = apply %runAsyncMain(%thick_test_case) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () + %result = apply %runAsyncMain(%throwing) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () %out_literal = integer_literal $Builtin.Int32, 0 %out = struct $Int32 (%out_literal : $Builtin.Int32) return %out : $Int32 diff --git a/test/IRGen/async/run-partialapply-capture-int64-int64-throws-to-int64.sil b/test/IRGen/async/run-partialapply-capture-int64-int64-throws-to-int64.sil index 09b22c7a5735f..25d97bb5f9911 100644 --- a/test/IRGen/async/run-partialapply-capture-int64-int64-throws-to-int64.sil +++ b/test/IRGen/async/run-partialapply-capture-int64-int64-throws-to-int64.sil @@ -46,8 +46,8 @@ exit: } // CHECK-LL: @closureTu = -// CHECK-LL: define internal swift{{(tail)?}}cc void @closure(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} -// CHECK-LL: define internal swift{{(tail)?}}cc void @"$s7closureTA"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define internal swift{{(tail)?}}cc void @closure( +// CHECK-LL: define internal swift{{(tail)?}}cc void @"$s7closureTA"( sil hidden @createPartialApply : $@async @convention(thin) (Int64) -> @owned @async @callee_guaranteed (Int64) -> (Int64, @error Error) { bb0(%captured : $Int64): %closure = function_ref @closure : $@async @convention(thin) (Int64, Int64) -> (Int64, @error Error) @@ -82,14 +82,21 @@ sil @test_case : $@convention(thin) @async () -> () { // Defined in _Concurrency sil @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () +sil @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error { +bb0(%0 :$@async @callee_guaranteed () -> ()): + %void = apply %0() : $@async @callee_guaranteed () -> () + return %void : $() +} + // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): %test_case_nothrow = function_ref @test_case : $@convention(thin) @async () -> () - %test_case = convert_function %test_case_nothrow : $@convention(thin) @async () -> () to $@convention(thin) @async () -> @error Error - %thick_test_case = thin_to_thick_function %test_case : $@convention(thin) @async () -> @error Error to $@callee_guaranteed @async () -> @error Error + %thick_test_case = thin_to_thick_function %test_case_nothrow : $@convention(thin) @async () -> () to $@callee_guaranteed @async () -> () + %thunk = function_ref @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error + %throwing = partial_apply [callee_guaranteed] %thunk(%thick_test_case) : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error %runAsyncMain = function_ref @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () - %result = apply %runAsyncMain(%thick_test_case) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () + %result = apply %runAsyncMain(%throwing) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () %out_literal = integer_literal $Builtin.Int32, 0 %out = struct $Int32 (%out_literal : $Builtin.Int32) return %out : $Int32 diff --git a/test/IRGen/async/run-partialapply-capture-int64-int64-to-int64.sil b/test/IRGen/async/run-partialapply-capture-int64-int64-to-int64.sil index d9ccb410272aa..6be47c3915a9c 100644 --- a/test/IRGen/async/run-partialapply-capture-int64-int64-to-int64.sil +++ b/test/IRGen/async/run-partialapply-capture-int64-int64-to-int64.sil @@ -37,8 +37,8 @@ bb0: } // CHECK-LL: @closureTu = -// CHECK-LL: define internal swift{{(tail)?}}cc void @closure(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} -// CHECK-LL: define internal swift{{(tail)?}}cc void @"$s7closureTA"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define internal swift{{(tail)?}}cc void @closure( +// CHECK-LL: define internal swift{{(tail)?}}cc void @"$s7closureTA"( sil hidden @createPartialApply : $@async @convention(thin) (Int64) -> @owned @async @callee_guaranteed (Int64) -> Int64 { bb0(%captured : $Int64): %closure = function_ref @closure : $@async @convention(thin) (Int64, Int64) -> Int64 @@ -73,14 +73,21 @@ sil @test_case : $@convention(thin) @async () -> () { // Defined in _Concurrency sil @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () +sil @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error { +bb0(%0 :$@async @callee_guaranteed () -> ()): + %void = apply %0() : $@async @callee_guaranteed () -> () + return %void : $() +} + // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): %test_case_nothrow = function_ref @test_case : $@convention(thin) @async () -> () - %test_case = convert_function %test_case_nothrow : $@convention(thin) @async () -> () to $@convention(thin) @async () -> @error Error - %thick_test_case = thin_to_thick_function %test_case : $@convention(thin) @async () -> @error Error to $@callee_guaranteed @async () -> @error Error + %thick_test_case = thin_to_thick_function %test_case_nothrow : $@convention(thin) @async () -> () to $@callee_guaranteed @async () -> () + %thunk = function_ref @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error + %throwing = partial_apply [callee_guaranteed] %thunk(%thick_test_case) : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error %runAsyncMain = function_ref @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () - %result = apply %runAsyncMain(%thick_test_case) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () + %result = apply %runAsyncMain(%throwing) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () %out_literal = integer_literal $Builtin.Int32, 0 %out = struct $Int32 (%out_literal : $Builtin.Int32) return %out : $Int32 diff --git a/test/IRGen/async/run-partialapply-capture-int64-to-generic.sil b/test/IRGen/async/run-partialapply-capture-int64-to-generic.sil index 18f1458b14382..0cc4192378d13 100644 --- a/test/IRGen/async/run-partialapply-capture-int64-to-generic.sil +++ b/test/IRGen/async/run-partialapply-capture-int64-to-generic.sil @@ -25,8 +25,8 @@ bb0(%x : $Int32, %f : $@async @callee_owned (Int32) -> @out T): return %p : $@async @callee_owned () -> @out T } -// CHECK-LL: define internal swift{{(tail)?}}cc void @"$sTA"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} -// CHECK-LL: define internal swift{{(tail)?}}cc void @"$s6calleeTA"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define internal swift{{(tail)?}}cc void @"$s36partial_apply_dynamic_with_out_paramTw_TA"( +// CHECK-LL: define internal swift{{(tail)?}}cc void @"$s6calleeTA"( sil @callee : $@async @convention(thin) (Int32, @in_guaranteed T) -> @out T { entry(%out_t : $*T, %x : $Int32, %in_t : $*T): %printGeneric = function_ref @printGeneric : $@convention(thin) (@in_guaranteed T) -> () @@ -65,14 +65,21 @@ sil @test_case : $@convention(thin) @async () -> () { // Defined in _Concurrency sil @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () +sil @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error { +bb0(%0 :$@async @callee_guaranteed () -> ()): + %void = apply %0() : $@async @callee_guaranteed () -> () + return %void : $() +} + // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): %test_case_nothrow = function_ref @test_case : $@convention(thin) @async () -> () - %test_case = convert_function %test_case_nothrow : $@convention(thin) @async () -> () to $@convention(thin) @async () -> @error Error - %thick_test_case = thin_to_thick_function %test_case : $@convention(thin) @async () -> @error Error to $@callee_guaranteed @async () -> @error Error + %thick_test_case = thin_to_thick_function %test_case_nothrow : $@convention(thin) @async () -> () to $@callee_guaranteed @async () -> () + %thunk = function_ref @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error + %throwing = partial_apply [callee_guaranteed] %thunk(%thick_test_case) : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error %runAsyncMain = function_ref @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () - %result = apply %runAsyncMain(%thick_test_case) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () + %result = apply %runAsyncMain(%throwing) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () %out_literal = integer_literal $Builtin.Int32, 0 %out = struct $Int32 (%out_literal : $Builtin.Int32) return %out : $Int32 diff --git a/test/IRGen/async/run-partialapply-capture-struct_classinstance_classinstance-and-int64-to-int64.sil b/test/IRGen/async/run-partialapply-capture-struct_classinstance_classinstance-and-int64-to-int64.sil index 095071fb15af7..f44862bd89841 100644 --- a/test/IRGen/async/run-partialapply-capture-struct_classinstance_classinstance-and-int64-to-int64.sil +++ b/test/IRGen/async/run-partialapply-capture-struct_classinstance_classinstance-and-int64-to-int64.sil @@ -62,8 +62,8 @@ sil_vtable C { struct S { var x: C, y: C } // CHECK-LL: @structClassInstanceClassInstanceAndInt64ToInt64Tu = -// CHECK-LL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @structClassInstanceClassInstanceAndInt64ToInt64(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} -// CHECK-LL: define internal swift{{(tail)?}}cc void @"$s019structClassInstancebc10AndInt64ToE0TA"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @structClassInstanceClassInstanceAndInt64ToInt64( +// CHECK-LL: define internal swift{{(tail)?}}cc void @"$s019structClassInstancebc10AndInt64ToE0TA"( sil @structClassInstanceClassInstanceAndInt64ToInt64 : $@async @convention(thin) (Int64, @guaranteed S) -> Int64 { entry(%in : $Int64, %s : $S): %s_addr = alloc_stack $S @@ -108,14 +108,21 @@ sil @test_case : $@convention(thin) @async () -> () { // Defined in _Concurrency sil @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () +sil @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error { +bb0(%0 :$@async @callee_guaranteed () -> ()): + %void = apply %0() : $@async @callee_guaranteed () -> () + return %void : $() +} + // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): %test_case_nothrow = function_ref @test_case : $@convention(thin) @async () -> () - %test_case = convert_function %test_case_nothrow : $@convention(thin) @async () -> () to $@convention(thin) @async () -> @error Error - %thick_test_case = thin_to_thick_function %test_case : $@convention(thin) @async () -> @error Error to $@callee_guaranteed @async () -> @error Error + %thick_test_case = thin_to_thick_function %test_case_nothrow : $@convention(thin) @async () -> () to $@callee_guaranteed @async () -> () + %thunk = function_ref @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error + %throwing = partial_apply [callee_guaranteed] %thunk(%thick_test_case) : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error %runAsyncMain = function_ref @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () - %result = apply %runAsyncMain(%thick_test_case) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () + %result = apply %runAsyncMain(%throwing) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () %out_literal = integer_literal $Builtin.Int32, 0 %out = struct $Int32 (%out_literal : $Builtin.Int32) return %out : $Int32 diff --git a/test/IRGen/async/run-partialapply-capture-structgeneric_classinstance_to_struct_and_error.sil b/test/IRGen/async/run-partialapply-capture-structgeneric_classinstance_to_struct_and_error.sil index a1affcacc80c4..15b0f6b3ac73c 100644 --- a/test/IRGen/async/run-partialapply-capture-structgeneric_classinstance_to_struct_and_error.sil +++ b/test/IRGen/async/run-partialapply-capture-structgeneric_classinstance_to_struct_and_error.sil @@ -42,18 +42,18 @@ entry(%value : $A2): // CHECK-LL: @amethodTu = // CHECK-LL: @repoTu = -// CHECK-LL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @amethod(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @amethod( sil @amethod : $@async @convention(method) (@in_guaranteed A2) -> (@owned A1, @error Error) { entry(%a2_at_a3_addr : $*A2): %a2_at_a3 = load %a2_at_a3_addr : $*A2 - %printA2AtA3 = function_ref @printA2AtA3 : $@convention(thin) (A2) -> () - %partiallyApplied = partial_apply [callee_guaranteed] %printA2AtA3(%a2_at_a3) : $@convention(thin) (A2) -> () + %printA2AtA3 = function_ref @printA2AtA3 : $@convention(thin) (A2) -> () + %partiallyApplied = partial_apply [callee_guaranteed] %printA2AtA3(%a2_at_a3) : $@convention(thin) (A2) -> () %result = struct $A1 ( %partiallyApplied : $@callee_guaranteed () -> () ) return %result : $A1 } -// CHECK-LL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @repo(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} -// CHECK-LL: define internal swift{{(tail)?}}cc void @"$s7amethodTA"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @repo( +// CHECK-LL: define internal swift{{(tail)?}}cc void @"$s7amethodTA"( sil @repo : $@async @convention(thin) (@in_guaranteed A2) -> @owned @async @callee_guaranteed () -> (@owned A1, @error Error) { bb0(%0 : $*A2): %1 = load %0 : $*A2 @@ -102,14 +102,21 @@ bb_finish: // Defined in _Concurrency sil @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () +sil @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error { +bb0(%0 :$@async @callee_guaranteed () -> ()): + %void = apply %0() : $@async @callee_guaranteed () -> () + return %void : $() +} + // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): %test_case_nothrow = function_ref @test_case : $@convention(thin) @async () -> () - %test_case = convert_function %test_case_nothrow : $@convention(thin) @async () -> () to $@convention(thin) @async () -> @error Error - %thick_test_case = thin_to_thick_function %test_case : $@convention(thin) @async () -> @error Error to $@callee_guaranteed @async () -> @error Error + %thick_test_case = thin_to_thick_function %test_case_nothrow : $@convention(thin) @async () -> () to $@callee_guaranteed @async () -> () + %thunk = function_ref @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error + %throwing = partial_apply [callee_guaranteed] %thunk(%thick_test_case) : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error %runAsyncMain = function_ref @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () - %result = apply %runAsyncMain(%thick_test_case) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () + %result = apply %runAsyncMain(%throwing) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () %out_literal = integer_literal $Builtin.Int32, 0 %out = struct $Int32 (%out_literal : $Builtin.Int32) return %out : $Int32 diff --git a/test/IRGen/async/run-partialapply-capture-structgeneric_polymorphic_constrained-to-void.sil b/test/IRGen/async/run-partialapply-capture-structgeneric_polymorphic_constrained-to-void.sil index 95f6cf8ff768f..75b6da68c7731 100644 --- a/test/IRGen/async/run-partialapply-capture-structgeneric_polymorphic_constrained-to-void.sil +++ b/test/IRGen/async/run-partialapply-capture-structgeneric_polymorphic_constrained-to-void.sil @@ -2,7 +2,7 @@ // RUN: %target-build-swift-dylib(%t/%target-library-name(PrintShims)) %S/../../Inputs/print-shims.swift -module-name PrintShims -emit-module -emit-module-path %t/PrintShims.swiftmodule // RUN: %target-codesign %t/%target-library-name(PrintShims) // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL -// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) +// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) // RUN: %target-codesign %t/main // RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s @@ -32,7 +32,7 @@ sil_witness_table BaseProducer : Q module main { public class WeakBox {} sil_vtable WeakBox {} -// CHECK-LL: define internal swift{{(tail)?}}cc void @"$s7takingQTA"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define internal swift{{(tail)?}}cc void @"$s7takingQTA"( sil hidden @takingQ : $@async @convention(thin) <Ï„_0_0 where Ï„_0_0 : Q> (@owned WeakBox<Ï„_0_0>) -> () { entry(%box : $WeakBox<Ï„_0_0>): %box_addr = alloc_stack $WeakBox<Ï„_0_0> @@ -70,14 +70,21 @@ sil @test_case : $@convention(thin) @async () -> () { // Defined in _Concurrency sil @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () +sil @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error { +bb0(%0 :$@async @callee_guaranteed () -> ()): + %void = apply %0() : $@async @callee_guaranteed () -> () + return %void : $() +} + // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): %test_case_nothrow = function_ref @test_case : $@convention(thin) @async () -> () - %test_case = convert_function %test_case_nothrow : $@convention(thin) @async () -> () to $@convention(thin) @async () -> @error Error - %thick_test_case = thin_to_thick_function %test_case : $@convention(thin) @async () -> @error Error to $@callee_guaranteed @async () -> @error Error + %thick_test_case = thin_to_thick_function %test_case_nothrow : $@convention(thin) @async () -> () to $@callee_guaranteed @async () -> () + %thunk = function_ref @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error + %throwing = partial_apply [callee_guaranteed] %thunk(%thick_test_case) : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error %runAsyncMain = function_ref @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () - %result = apply %runAsyncMain(%thick_test_case) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () + %result = apply %runAsyncMain(%throwing) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () %out_literal = integer_literal $Builtin.Int32, 0 %out = struct $Int32 (%out_literal : $Builtin.Int32) return %out : $Int32 diff --git a/test/IRGen/async/run-partialapply-capture-type_structgeneric_polymorphic_constrained-to-void.sil b/test/IRGen/async/run-partialapply-capture-type_structgeneric_polymorphic_constrained-to-void.sil index 405f7c8980ba7..fbca12d6ee6cb 100644 --- a/test/IRGen/async/run-partialapply-capture-type_structgeneric_polymorphic_constrained-to-void.sil +++ b/test/IRGen/async/run-partialapply-capture-type_structgeneric_polymorphic_constrained-to-void.sil @@ -2,7 +2,7 @@ // RUN: %target-build-swift-dylib(%t/%target-library-name(PrintShims)) %S/../../Inputs/print-shims.swift -module-name PrintShims -emit-module -emit-module-path %t/PrintShims.swiftmodule // RUN: %target-codesign %t/%target-library-name(PrintShims) // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL -// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) +// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -g -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) // RUN: %target-codesign %t/main // RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s @@ -33,7 +33,7 @@ public class WeakBox {} sil_vtable WeakBox {} // CHECK-LL: @takingQTu = -// CHECK-LL: define hidden swift{{(tail)?}}cc void @takingQ(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define hidden swift{{(tail)?}}cc void @takingQ( sil hidden @takingQ : $@async @convention(thin) <Ï„_0_0 where Ï„_0_0 : Q> (@owned WeakBox<Ï„_0_0>) -> () { entry(%box : $WeakBox<Ï„_0_0>): %box_addr = alloc_stack $WeakBox<Ï„_0_0> @@ -45,7 +45,7 @@ entry(%box : $WeakBox<Ï„_0_0>): } -// CHECK-LL: define internal swift{{(tail)?}}cc void @"$s7takingQTA"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define internal swift{{(tail)?}}cc void @"$s7takingQTA"( sil public @bind_polymorphic_param_from_forwarder_parameter : $@async @convention(thin) <Ï„_0_1>(@in Ï„_0_1) -> @callee_owned @async (@owned WeakBox>) -> () { bb0(%0 : $*Ï„_0_1): %1 = alloc_ref $WeakBox> @@ -75,14 +75,21 @@ sil @test_case : $@convention(thin) @async () -> () { // Defined in _Concurrency sil @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () +sil @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error { +bb0(%0 :$@async @callee_guaranteed () -> ()): + %void = apply %0() : $@async @callee_guaranteed () -> () + return %void : $() +} + // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): %test_case_nothrow = function_ref @test_case : $@convention(thin) @async () -> () - %test_case = convert_function %test_case_nothrow : $@convention(thin) @async () -> () to $@convention(thin) @async () -> @error Error - %thick_test_case = thin_to_thick_function %test_case : $@convention(thin) @async () -> @error Error to $@callee_guaranteed @async () -> @error Error + %thick_test_case = thin_to_thick_function %test_case_nothrow : $@convention(thin) @async () -> () to $@callee_guaranteed @async () -> () + %thunk = function_ref @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error + %throwing = partial_apply [callee_guaranteed] %thunk(%thick_test_case) : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error %runAsyncMain = function_ref @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () - %result = apply %runAsyncMain(%thick_test_case) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () + %result = apply %runAsyncMain(%throwing) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () %out_literal = integer_literal $Builtin.Int32, 0 %out = struct $Int32 (%out_literal : $Builtin.Int32) return %out : $Int32 diff --git a/test/IRGen/async/run-partialapply-capture-type_thin-and-classinstance-to-void.sil b/test/IRGen/async/run-partialapply-capture-type_thin-and-classinstance-to-void.sil index 4fa2fa388c0cc..a4c33f85a3b77 100644 --- a/test/IRGen/async/run-partialapply-capture-type_thin-and-classinstance-to-void.sil +++ b/test/IRGen/async/run-partialapply-capture-type_thin-and-classinstance-to-void.sil @@ -60,8 +60,8 @@ sil_vtable C { struct S {} -// CHECK-LL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @structtypeSAndClassinstanceCToVoid(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} -// CHECK-LL: define internal swift{{(tail)?}}cc void @"$s34structtypeSAndClassinstanceCToVoidTA"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @structtypeSAndClassinstanceCToVoid +// CHECK-LL: define internal swift{{(tail)?}}cc void @"$s34structtypeSAndClassinstanceCToVoidTA"( sil @structtypeSAndClassinstanceCToVoid : $@async @convention(thin) (@thin S.Type, @owned C) -> () { entry(%S_type: $@thin S.Type, %C_instance: $C): %S_type_addr = alloc_stack $@thick S.Type @@ -104,14 +104,21 @@ sil @test_case : $@convention(thin) @async () -> () { // Defined in _Concurrency sil @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () +sil @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error { +bb0(%0 :$@async @callee_guaranteed () -> ()): + %void = apply %0() : $@async @callee_guaranteed () -> () + return %void : $() +} + // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): %test_case_nothrow = function_ref @test_case : $@convention(thin) @async () -> () - %test_case = convert_function %test_case_nothrow : $@convention(thin) @async () -> () to $@convention(thin) @async () -> @error Error - %thick_test_case = thin_to_thick_function %test_case : $@convention(thin) @async () -> @error Error to $@callee_guaranteed @async () -> @error Error + %thick_test_case = thin_to_thick_function %test_case_nothrow : $@convention(thin) @async () -> () to $@callee_guaranteed @async () -> () + %thunk = function_ref @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error + %throwing = partial_apply [callee_guaranteed] %thunk(%thick_test_case) : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error %runAsyncMain = function_ref @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () - %result = apply %runAsyncMain(%thick_test_case) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () + %result = apply %runAsyncMain(%throwing) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () %out_literal = integer_literal $Builtin.Int32, 0 %out = struct $Int32 (%out_literal : $Builtin.Int32) return %out : $Int32 diff --git a/test/IRGen/async/run-structinstance_generic-void-to-void-constrained.swift b/test/IRGen/async/run-structinstance_generic-void-to-void-constrained.swift index dc1c1cdc794fc..f9727152f6145 100644 --- a/test/IRGen/async/run-structinstance_generic-void-to-void-constrained.swift +++ b/test/IRGen/async/run-structinstance_generic-void-to-void-constrained.swift @@ -16,7 +16,7 @@ extension String: Fooable {} extension Optional where Wrapped: Fooable { // CHECK-LL: @"$sSq4mainAA7FooableRzlE22theConstrainedFunctionyyYFTu" = hidden global %swift.async_func_pointer - // CHECK-LL: define hidden swift{{(tail)?}}cc void @"$sSq4mainAA7FooableRzlE22theConstrainedFunctionyyYF"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} + // CHECK-LL: define hidden swift{{(tail)?}}cc void @"$sSq4mainAA7FooableRzlE22theConstrainedFunctionyyYF"( func theConstrainedFunction() async { // CHECK: running Optional.theConstrainedFunction print("running \(Self.self).theConstrainedFunction") diff --git a/test/IRGen/async/run-thintothick-int64-to-void.sil b/test/IRGen/async/run-thintothick-int64-to-void.sil index 5af9e8647fa77..2be25ecbf04a7 100644 --- a/test/IRGen/async/run-thintothick-int64-to-void.sil +++ b/test/IRGen/async/run-thintothick-int64-to-void.sil @@ -18,7 +18,7 @@ import _Concurrency sil public_external @printInt64 : $@convention(thin) (Int64) -> () -// CHECK-LL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @afun2(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @afun2(%swift.context* swiftasync {{%[0-9]+}} sil @afun2 : $@async @convention(thin) (Int64) -> () { entry(%int : $Int64): %print = function_ref @printInt64 : $@convention(thin) (Int64) -> () @@ -26,7 +26,7 @@ entry(%int : $Int64): return %result : $() } -// CHECK-LL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @test_apply_of_thin_to_thick(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} +// CHECK-LL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @test_apply_of_thin_to_thick( sil @test_apply_of_thin_to_thick : $@async @convention(thin) () -> () { entry: %f = function_ref @afun2 : $@async @convention(thin) (Int64) -> () @@ -49,14 +49,21 @@ sil @test_case : $@convention(thin) @async () -> () { // Defined in _Concurrency sil @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () +sil @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error { +bb0(%0 :$@async @callee_guaranteed () -> ()): + %void = apply %0() : $@async @callee_guaranteed () -> () + return %void : $() +} + // main sil @main : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): %test_case_nothrow = function_ref @test_case : $@convention(thin) @async () -> () - %test_case = convert_function %test_case_nothrow : $@convention(thin) @async () -> () to $@convention(thin) @async () -> @error Error - %thick_test_case = thin_to_thick_function %test_case : $@convention(thin) @async () -> @error Error to $@callee_guaranteed @async () -> @error Error + %thick_test_case = thin_to_thick_function %test_case_nothrow : $@convention(thin) @async () -> () to $@callee_guaranteed @async () -> () + %thunk = function_ref @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error + %throwing = partial_apply [callee_guaranteed] %thunk(%thick_test_case) : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error %runAsyncMain = function_ref @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () - %result = apply %runAsyncMain(%thick_test_case) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () + %result = apply %runAsyncMain(%throwing) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> () %out_literal = integer_literal $Builtin.Int32, 0 %out = struct $Int32 (%out_literal : $Builtin.Int32) return %out : $Int32 diff --git a/test/IRGen/objc.swift b/test/IRGen/objc.swift index bc3512ccb9ea7..87f14a01c206a 100644 --- a/test/IRGen/objc.swift +++ b/test/IRGen/objc.swift @@ -145,7 +145,7 @@ class WeakObjC { // CHECK: i32 1, !"Objective-C Version", i32 2} // CHECK: i32 1, !"Objective-C Image Info Version", i32 0} // CHECK: i32 1, !"Objective-C Image Info Section", !"__DATA,__objc_imageinfo,regular,no_dead_strip"} -// 84150016 == (5 << 24) | (4 << 16) | (7 << 8). -// 5 and 3 is the current major.minor version. 7 is the Swift ABI version. -// CHECK: i32 4, !"Objective-C Garbage Collection", i32 84150016} +// 84215552 == (5 << 24) | (5 << 16) | (7 << 8). +// 5 and 5 is the current major.minor version. 7 is the Swift ABI version. +// CHECK: i32 4, !"Objective-C Garbage Collection", i32 84215552} // CHECK: i32 1, !"Swift Version", i32 7} diff --git a/test/IRGen/unmanaged_objc_throw_func.swift b/test/IRGen/unmanaged_objc_throw_func.swift index c8ad72381d033..4134ab188c1f5 100644 --- a/test/IRGen/unmanaged_objc_throw_func.swift +++ b/test/IRGen/unmanaged_objc_throw_func.swift @@ -36,12 +36,16 @@ import Foundation // CHECK: [[L2]]: ; preds = %entry // CHECK-NEXT: %[[T4:.+]] = phi %TSo10CFArrayRefa* [ %[[T0]], %entry ] +// CHECK-NEXT: %[[T4a:.+]] = bitcast %T25unmanaged_objc_throw_func9SR_9035_CC* %{{.+}} to i8* +// CHECK-NEXT: call void @llvm.objc.release(i8* %[[T4a]]) // CHECK-NEXT: %[[T5:.+]] = ptrtoint %TSo10CFArrayRefa* %[[T4]] to i{{32|64}} // CHECK-NEXT: br label %[[L3:.+]] // CHECK: [[L1]]: ; preds = %entry // CHECK-NEXT: %[[T6:.+]] = phi %swift.error* [ %[[T2]], %entry ] // CHECK-NEXT: store %swift.error* null, %swift.error** %swifterror, align {{[0-9]+}} +// CHECK-NEXT: %[[T6a:.+]] = bitcast %T25unmanaged_objc_throw_func9SR_9035_CC* %{{.+}} to i8* +// CHECK-NEXT: call void @llvm.objc.release(i8* %[[T6a]]) // CHECK-NEXT: %[[T7:.+]] = icmp eq i{{32|64}} %{{.+}}, 0 // CHECK-NEXT: br i1 %[[T7]], label %[[L4:.+]], label %[[L5:.+]] @@ -66,7 +70,5 @@ import Foundation // CHECK: [[L3]]: ; preds = %[[L2]], %[[L7]] // CHECK-NEXT: %[[T12:.+]] = phi i{{32|64}} [ 0, %[[L7]] ], [ %[[T5]], %[[L2]] ] -// CHECK-NEXT: %[[T13:.+]] = bitcast %T25unmanaged_objc_throw_func9SR_9035_CC* %{{.+}} to i8* -// CHECK-NEXT: call void @llvm.objc.release(i8* %[[T13]]) // CHECK-NEXT: %[[T14:.+]] = inttoptr i{{32|64}} %[[T12]] to %struct.__CFArray* // CHECK-NEXT: ret %struct.__CFArray* %[[T14]] diff --git a/test/Interop/Cxx/class/Inputs/invalid-nested-struct.h b/test/Interop/Cxx/class/Inputs/invalid-nested-struct.h new file mode 100644 index 0000000000000..49379786af32c --- /dev/null +++ b/test/Interop/Cxx/class/Inputs/invalid-nested-struct.h @@ -0,0 +1,63 @@ +// When we import this class, make sure that we bail before trying to import +// its sub-decls (i.e., "ForwardDeclaredSibling"). +struct CannotImport { + void test(struct ForwardDeclaredSibling *) {} + + ~CannotImport() = delete; + CannotImport(CannotImport const &) = delete; +}; + +// We shouldn't be able to import this class either because it also doesn't have +// a copy ctor or destructor. +struct ForwardDeclaredSibling : CannotImport {}; + +// This is a longer regression test to make sure we don't improperly cache a +// typedef that's invalid. +namespace RegressionTest { + +template +struct pointer_traits { + template + struct rebind { + typedef To other; + }; +}; + +template +struct Convert { + typedef typename pointer_traits::template rebind::other type; +}; + +template +struct Forward; + +template +struct SomeTypeTrait { + typedef Forward *F; + typedef typename Convert::type A; +}; + +template +struct Forward { + typedef typename SomeTypeTrait::A A; + +private: + ~Forward() = delete; + Forward(Forward const &) = delete; +}; + +template +struct SomeOtherTypeTrait : SomeTypeTrait { + typedef typename SomeTypeTrait::A A; +}; + +// Just to instantiate all the templates. +struct FinalUser { + typedef Forward F; + typedef SomeOtherTypeTrait O; + typedef SomeTypeTrait Z; +}; + +void test(typename FinalUser::Z) {} + +} // namespace RegressionTest diff --git a/test/Interop/Cxx/class/Inputs/module.modulemap b/test/Interop/Cxx/class/Inputs/module.modulemap index a50d6806cc660..2f463d9111b79 100644 --- a/test/Interop/Cxx/class/Inputs/module.modulemap +++ b/test/Interop/Cxx/class/Inputs/module.modulemap @@ -67,3 +67,8 @@ module LinkedRecords { header "linked-records.h" requires cplusplus } + +module InvalidNestedStruct { + header "invalid-nested-struct.h" + requires cplusplus +} diff --git a/test/Interop/Cxx/class/invalid-nested-struct-module-interface.swift b/test/Interop/Cxx/class/invalid-nested-struct-module-interface.swift new file mode 100644 index 0000000000000..bda590f4ffd73 --- /dev/null +++ b/test/Interop/Cxx/class/invalid-nested-struct-module-interface.swift @@ -0,0 +1,4 @@ +// RUN: %target-swift-ide-test -print-module -module-to-print=InvalidNestedStruct -I %S/Inputs/ -source-filename=x -enable-cxx-interop | %FileCheck %s + +// CHECK-NOT: CannotImport +// CHECK-NOT: ForwardDeclaredSibling diff --git a/test/Interop/Cxx/class/type-classification-loadable-silgen.swift b/test/Interop/Cxx/class/type-classification-loadable-silgen.swift index c39ac1a996c07..e272852331217 100644 --- a/test/Interop/Cxx/class/type-classification-loadable-silgen.swift +++ b/test/Interop/Cxx/class/type-classification-loadable-silgen.swift @@ -52,21 +52,6 @@ func pass(s: StructWithSubobjectDefaultedCopyConstructor) { // CHECK: bb0(%0 : $StructWithSubobjectDefaultedCopyConstructor): } -// CHECK-LABEL: sil hidden [ossa] @$s4main4pass{{.*[ (]}}StructWithMoveConstructor) -func pass(s: StructWithMoveConstructor) { - // CHECK: bb0(%0 : $*StructWithMoveConstructor): -} - -// CHECK-LABEL: sil hidden [ossa] @$s4main4pass{{.*[ (]}}StructWithInheritedMoveConstructor) -func pass(s: StructWithInheritedMoveConstructor) { - // CHECK: bb0(%0 : $*StructWithInheritedMoveConstructor): -} - -// CHECK-LABEL: sil hidden [ossa] @$s4main4pass{{.*[ (]}}StructWithSubobjectMoveConstructor) -func pass(s: StructWithSubobjectMoveConstructor) { - // CHECK: bb0(%0 : $*StructWithSubobjectMoveConstructor): -} - // CHECK-LABEL: sil hidden [ossa] @$s4main4pass{{.*[ (]}}StructWithCopyAssignment) func pass(s: StructWithCopyAssignment) { // CHECK: bb0(%0 : $*StructWithCopyAssignment): @@ -82,21 +67,6 @@ func pass(s: StructWithSubobjectCopyAssignment) { // CHECK: bb0(%0 : $*StructWithSubobjectCopyAssignment): } -// CHECK-LABEL: sil hidden [ossa] @$s4main4pass{{.*[ (]}}StructWithMoveAssignment) -func pass(s: StructWithMoveAssignment) { - // CHECK: bb0(%0 : $*StructWithMoveAssignment): -} - -// CHECK-LABEL: sil hidden [ossa] @$s4main4pass{{.*[ (]}}StructWithInheritedMoveAssignment) -func pass(s: StructWithInheritedMoveAssignment) { - // CHECK: bb0(%0 : $*StructWithInheritedMoveAssignment): -} - -// CHECK-LABEL: sil hidden [ossa] @$s4main4pass{{.*[ (]}}StructWithSubobjectMoveAssignment) -func pass(s: StructWithSubobjectMoveAssignment) { - // CHECK: bb0(%0 : $*StructWithSubobjectMoveAssignment): -} - // CHECK-LABEL: sil hidden [ossa] @$s4main4pass{{.*[ (]}}StructWithDestructor) func pass(s: StructWithDestructor) { // CHECK: bb0(%0 : $*StructWithDestructor): @@ -133,8 +103,3 @@ func pass(s: StructWithSubobjectDefaultedDestructor) { func pass(s: StructTriviallyCopyableMovable) { // CHECK: bb0(%0 : $StructTriviallyCopyableMovable): } - -// CHECK-LABEL: sil hidden [ossa] @$s4main4pass{{.*[ (]}}StructNonCopyableNonMovable) -func pass(s: StructNonCopyableNonMovable) { - // CHECK: bb0(%0 : $StructNonCopyableNonMovable): -} diff --git a/test/Interop/Cxx/class/type-classification-module-interface.swift b/test/Interop/Cxx/class/type-classification-module-interface.swift index 72dd0085d3bc9..f29064f3dfe40 100644 --- a/test/Interop/Cxx/class/type-classification-module-interface.swift +++ b/test/Interop/Cxx/class/type-classification-module-interface.swift @@ -5,6 +5,13 @@ // CHECK-NOT: StructWithInheritedPrivateDefaultedCopyConstructor // CHECK-NOT: StructWithSubobjectPrivateDefaultedCopyConstructor // CHECK-NOT: StructNonCopyableTriviallyMovable +// CHECK-NOT: StructNonCopyableNonMovable +// CHECK-NOT: StructWithMoveConstructor +// CHECK-NOT: StructWithInheritedMoveConstructor +// CHECK-NOT: StructWithSubobjectMoveConstructor +// CHECK-NOT: StructWithMoveAssignment +// CHECK-NOT: StructWithInheritedMoveAssignment +// CHECK-NOT: StructWithSubobjectMoveAssignment // CHECK-NOT: StructWithPrivateDefaultedDestructor // CHECK-NOT: StructWithInheritedPrivateDefaultedDestructor // CHECK-NOT: StructWithSubobjectPrivateDefaultedDestructor diff --git a/test/Interpreter/builtin_bridge_object.swift b/test/Interpreter/builtin_bridge_object.swift index df15921346a84..9146a7eca1dc3 100644 --- a/test/Interpreter/builtin_bridge_object.swift +++ b/test/Interpreter/builtin_bridge_object.swift @@ -65,6 +65,7 @@ if true { // CHECK-NEXT: true print(x === x2) // CHECK-OPT-NEXT: deallocated + // CHECK-DBG-NEXT: deallocated print(nonPointerBits(bo) == 0) // CHECK-NEXT: true @@ -78,7 +79,6 @@ if true { _fixLifetime(bo3) _fixLifetime(bo4) } -// CHECK-DBG-NEXT: deallocated // CHECK-NEXT: deallocated // Try with all spare bits set. @@ -94,6 +94,7 @@ if true { // CHECK-NEXT: true print(x === x2) // CHECK-OPT-NEXT: deallocated + // CHECK-DBG-NEXT: deallocated print(nonPointerBits(bo) == NATIVE_SPARE_BITS) // CHECK-NEXT: true @@ -107,7 +108,6 @@ if true { _fixLifetime(bo3) _fixLifetime(bo4) } -// CHECK-DBG-NEXT: deallocated // CHECK-NEXT: deallocated diff --git a/test/LTO/module_summary_generic_type_ref.swift b/test/LTO/module_summary_generic_type_ref.swift index d8c2fef8950f2..1c30a5b20d0c5 100644 --- a/test/LTO/module_summary_generic_type_ref.swift +++ b/test/LTO/module_summary_generic_type_ref.swift @@ -1,6 +1,6 @@ // RUN: %empty-directory(%t) // RUN: %target-swift-frontend -emit-sib -emit-module-summary-path %t/default_wt.swiftmodule.summary -module-name default_wt -Xllvm -module-summary-embed-debug-name %s -// RUN: %swift_frontend_plain -merge-module-summary %t/default_wt.swiftmodule.summary -module-summary-embed-debug-name -o %t/default_wt.swiftmodule.merged-summary +// RUN: %swift_frontend_plain -merge-module-summary %t/default_wt.swiftmodule.summary -Xllvm -module-summary-embed-debug-name -o %t/default_wt.swiftmodule.merged-summary // RUN: %swift-module-summary-test --to-yaml %t/default_wt.swiftmodule.merged-summary -o %t/default_wt.merged-summary.yaml // Ensure that optimizer won't eliminate PrimitiveSequenceType.getPrimitiveSequence diff --git a/test/SILGen/async_builtins.swift b/test/SILGen/async_builtins.swift index b9dc74d49c4c6..531ad442d7488 100644 --- a/test/SILGen/async_builtins.swift +++ b/test/SILGen/async_builtins.swift @@ -18,22 +18,22 @@ public struct X { // CHECK-LABEL: sil hidden [ossa] @$s4test1XV12launchFutureyyxlF : $@convention(method) (@in_guaranteed T, X) -> () func launchFuture(_ value: T) { - // CHECK: builtin "createAsyncTaskFuture"([[ZERO:%.*]] : $Int, [[NIL:%.*]] : $Optional, [[FN:%.*]] : $@async @callee_guaranteed @substituted <Ï„_0_0> () -> (@out Ï„_0_0, @error Error) for ) : $(Builtin.NativeObject, Builtin.RawPointer) - let task = Builtin.createAsyncTaskFuture(0, nil) { () async throws -> T in + // CHECK: builtin "createAsyncTaskFuture"([[ZERO:%.*]] : $Int, [[FN:%.*]] : $@async @callee_guaranteed @substituted <Ï„_0_0> () -> (@out Ï„_0_0, @error Error) for ) : $(Builtin.NativeObject, Builtin.RawPointer) + let task = Builtin.createAsyncTaskFuture(0) { () async throws -> T in return value } } // CHECK-LABEL: sil hidden [ossa] @$s4test1XV16launchGroupChildyyxlF : $@convention(method) (@in_guaranteed T, X) -> () { func launchGroupChild(_ value: T) { - // CHECK: builtin "createAsyncTaskGroupFuture"([[ZERO:%.*]] : $Int, [[NIL:%.*]] : $Optional, [[NIL:%.*]] : $Optional, [[FN:%.*]] : $@async @callee_guaranteed @substituted <Ï„_0_0> () -> (@out Ï„_0_0, @error Error) for ) : $(Builtin.NativeObject, Builtin.RawPointer) - let task = Builtin.createAsyncTaskGroupFuture(0, nil, nil) { () async throws -> T in + // CHECK: builtin "createAsyncTaskGroupFuture"([[ZERO:%.*]] : $Int, [[NIL:%.*]] : $Optional, [[FN:%.*]] : $@async @callee_guaranteed @substituted <Ï„_0_0> () -> (@out Ï„_0_0, @error Error) for ) : $(Builtin.NativeObject, Builtin.RawPointer) + let task = Builtin.createAsyncTaskGroupFuture(0, nil) { () async throws -> T in return value } } public func launchRocker(closure: @escaping () async throws -> T) { - _ = Builtin.createAsyncTaskFuture(0, nil, closure) + _ = Builtin.createAsyncTaskFuture(0, closure) } } diff --git a/test/SILGen/capture_order.swift b/test/SILGen/capture_order.swift index 06f7954e5584f..75713fa150cc2 100644 --- a/test/SILGen/capture_order.swift +++ b/test/SILGen/capture_order.swift @@ -119,25 +119,6 @@ func captureInClosure() { /// Regression tests -func sr3210_crash() { - defer { // expected-error {{'defer' block captures 'b' before it is declared}} - print("\(b)") // expected-note {{captured here}} - } - - return - - let b = 2 // expected-note {{captured value declared here}} - // expected-warning@-1 {{code after 'return' will never be executed}} -} - -func sr3210() { - defer { - print("\(b)") - } - - let b = 2 -} - class SR4812 { public func foo() { let bar = { [weak self] in diff --git a/test/SILGen/global_actor_function_mangling.swift b/test/SILGen/global_actor_function_mangling.swift new file mode 100644 index 0000000000000..88901046d61d4 --- /dev/null +++ b/test/SILGen/global_actor_function_mangling.swift @@ -0,0 +1,9 @@ +// RUN: %target-swift-frontend -emit-silgen %s -module-name test -swift-version 5 -enable-experimental-concurrency | %FileCheck %s +// REQUIRES: concurrency + +// Declarations don't mangle global actor types. +// CHECK: @$s4test10returnsOptyxycSgAClF +func returnsOpt(_ fn: (@MainActor () -> R)?) -> (() -> R)? { + typealias Fn = (() -> R)? + return unsafeBitCast(fn, to: Fn.self) +} diff --git a/test/SILOptimizer/definite_init_diagnostics.swift b/test/SILOptimizer/definite_init_diagnostics.swift index ee320b5ca5119..d1681ea2bb32b 100644 --- a/test/SILOptimizer/definite_init_diagnostics.swift +++ b/test/SILOptimizer/definite_init_diagnostics.swift @@ -1,5 +1,4 @@ // RUN: %target-swift-frontend -emit-sil -primary-file %s -o /dev/null -verify -// RUN: %target-swift-frontend -emit-sil -primary-file %s -o /dev/null -verify import Swift @@ -1606,4 +1605,29 @@ class A { self.init(x: i) } } // expected-error {{'self.init' isn't called on all paths before returning from initializer}} - } +} + +@propertyWrapper +struct Wrapper { + var wrappedValue: T + + init(wrappedValue initialValue: T) { + self.wrappedValue = initialValue + } +} + +func foo(_ d: DerivedWrappedProperty) { + print(d) +} + +class DerivedWrappedProperty : SomeClass { + @Wrapper var y: String + var z : String + + init(s: String) { + y = s + z = s + foo(self) // expected-error {{'self' used in method call 'foo' before 'super.init' call}} + } // expected-error {{'super.init' isn't called on all paths before returning from initializer}} + +} diff --git a/test/SILOptimizer/globalopt_let_propagation.swift b/test/SILOptimizer/globalopt_let_propagation.swift index 9a29268e49e72..35098f523200a 100644 --- a/test/SILOptimizer/globalopt_let_propagation.swift +++ b/test/SILOptimizer/globalopt_let_propagation.swift @@ -72,6 +72,10 @@ var VPI = 3.1415 var VI = 100 var VS = "String2" +struct GenericStruct { + var x: T +} + // Define some static let variables inside a struct. struct B { static let PI = 3.1415 @@ -109,6 +113,8 @@ struct B { static let IT1 = ((10, 20), 30, 40) static let IT2 = (100, 200, 300) + + static let emptyStruct = GenericStruct(x: ()) } // Define some static let variables inside a class. diff --git a/test/SILOptimizer/globalopt_trivial_nontrivial_ossa.sil b/test/SILOptimizer/globalopt_trivial_nontrivial_ossa.sil index 433aff21f011f..e7de17d4bac9e 100644 --- a/test/SILOptimizer/globalopt_trivial_nontrivial_ossa.sil +++ b/test/SILOptimizer/globalopt_trivial_nontrivial_ossa.sil @@ -18,6 +18,10 @@ public class TClass { deinit } +struct GenericStruct { + var x: T +} + let nontrivialglobal: TClass // CHECK-LABEL: sil_global hidden [let] @$trivialglobal : $TStruct = { @@ -32,6 +36,9 @@ sil_global private @globalinit_nontrivialglobal_token : $Builtin.Word sil_global hidden [let] @$nontrivialglobal : $TClass +sil_global hidden [let] @empty_global : $GenericStruct<()> +sil_global private @empty_global_token : $Builtin.Word + sil private [global_init_once_fn] [ossa] @globalinit_trivialglobal_func : $@convention(c) () -> () { bb0: alloc_global @$trivialglobal @@ -126,3 +133,28 @@ bb0: return %5 : $Int32 } +// Check that we don't crash on an initializer struct with an "undef" operand. +// CHECK-LABEL: sil hidden [global_init_once_fn] [ossa] @globalinit_empty_global : +// CHECK: struct $GenericStruct<()> (undef : $()) +// CHECK-LABEL: } // end sil function 'globalinit_empty_global' +sil hidden [global_init_once_fn] [ossa] @globalinit_empty_global : $@convention(c) () -> () { +bb0: + alloc_global @empty_global + %1 = global_addr @empty_global : $*GenericStruct<()> + %2 = struct $GenericStruct<()> (undef : $()) + store %2 to [trivial] %1 : $*GenericStruct<()> + %4 = tuple () + return %4 : $() +} + +sil hidden [global_init] [ossa] @empty_global_accessor : $@convention(thin) () -> Builtin.RawPointer { +bb0: + %0 = global_addr @empty_global_token : $*Builtin.Word + %1 = address_to_pointer %0 : $*Builtin.Word to $Builtin.RawPointer + %2 = function_ref @globalinit_empty_global : $@convention(c) () -> () + %3 = builtin "once"(%1 : $Builtin.RawPointer, %2 : $@convention(c) () -> ()) : $() + %4 = global_addr @empty_global : $*GenericStruct<()> + %5 = address_to_pointer %4 : $*GenericStruct<()> to $Builtin.RawPointer + return %5 : $Builtin.RawPointer +} + diff --git a/test/SILOptimizer/mem2reg.sil b/test/SILOptimizer/mem2reg.sil index 3f398c97586b3..0bbaecf00b39e 100644 --- a/test/SILOptimizer/mem2reg.sil +++ b/test/SILOptimizer/mem2reg.sil @@ -438,8 +438,8 @@ bb3(%20 : $((), ())): } // CHECK-LABEL: sil @load_tuple_of_void -// CHECK-NOT: alloc_stack -// CHECK: return undef : $((), ()) +// CHECK: [[T:%[0-9]+]] = tuple (%{{[0-9]+}} : $(), %{{[0-9]+}} : $()) +// CHECK: return [[T]] : $((), ()) // CHECK: } // end sil function 'load_tuple_of_void' sil @load_tuple_of_void : $@convention(thin) () -> ((), ()) { bb0: diff --git a/test/SILOptimizer/mem2reg_ossa.sil b/test/SILOptimizer/mem2reg_ossa.sil index 83ffbb3bf4873..9ccfc15d70f91 100644 --- a/test/SILOptimizer/mem2reg_ossa.sil +++ b/test/SILOptimizer/mem2reg_ossa.sil @@ -478,7 +478,8 @@ bb3(%20 : $((), ())): // CHECK-LABEL: sil [ossa] @load_tuple_of_void : // CHECK-NOT: alloc_stack -// CHECK: return undef : $((), ()) +// CHECK: [[T:%[0-9]+]] = tuple (%{{[0-9]+}} : $(), %{{[0-9]+}} : $()) +// CHECK: return [[T]] : $((), ()) // CHECK: } // end sil function 'load_tuple_of_void' sil [ossa] @load_tuple_of_void : $@convention(thin) () -> ((), ()) { bb0: diff --git a/test/SILOptimizer/sil_combine.sil b/test/SILOptimizer/sil_combine.sil index 807c4b7bb7593..ea037da6c5ab3 100644 --- a/test/SILOptimizer/sil_combine.sil +++ b/test/SILOptimizer/sil_combine.sil @@ -4203,4 +4203,26 @@ bb1(%result : $Builtin.NativeObject): bb2(%error : $Error): unreachable -} \ No newline at end of file +} + +sil_global private @outlined_global : $_ContiguousArrayStorage + +// CHECK-LABEL: sil @test_global_value +// CHECK-NOT: retain +// CHECK-NOT: release +// CHECK-NOT: debug_value +// CHECK: } // end sil function 'test_global_value' +sil @test_global_value : $@convention(thin) () -> Int { +bb0: + %0 = global_value @outlined_global : $_ContiguousArrayStorage + strong_retain %0 : $_ContiguousArrayStorage + debug_value %0 : $_ContiguousArrayStorage, let, name "x" + %2 = upcast %0 : $_ContiguousArrayStorage to $__ContiguousArrayStorageBase + strong_retain %2 : $__ContiguousArrayStorageBase + %13 = ref_tail_addr [immutable] %2 : $__ContiguousArrayStorageBase, $Int + %16 = load %13 : $*Int + strong_release %2 : $__ContiguousArrayStorageBase + strong_release %0 : $_ContiguousArrayStorage + return %16 : $Int +} // end sil function 'test_global_value' + diff --git a/test/SILOptimizer/static_arrays.swift b/test/SILOptimizer/static_arrays.swift index a83d75a71bf0b..8b5b5a3b460aa 100644 --- a/test/SILOptimizer/static_arrays.swift +++ b/test/SILOptimizer/static_arrays.swift @@ -1,4 +1,5 @@ // RUN: %target-swift-frontend -primary-file %s -O -sil-verify-all -Xllvm -sil-disable-pass=FunctionSignatureOpts -module-name=test -emit-sil | %FileCheck %s +// RUN: %target-swift-frontend -primary-file %s -O -sil-verify-all -Xllvm -sil-disable-pass=FunctionSignatureOpts -module-name=test -emit-ir | %FileCheck %s -check-prefix=CHECK-LLVM // Also do an end-to-end test to check all components, including IRGen. // RUN: %empty-directory(%t) @@ -98,9 +99,18 @@ // CHECK: return public let globalVariable = [ 100, 101, 102 ] -// CHECK-LABEL: sil {{.*}}arrayLookup{{.*}} : $@convention(thin) (Int) -> Int { -// CHECK: global_value @{{.*}}arrayLookup{{.*}} -// CHECK: return +// CHECK-LABEL: sil [noinline] @$s4test11arrayLookupyS2iF +// CHECK: global_value @$s4test11arrayLookupyS2iFTv_ +// CHECK-NOT: retain +// CHECK-NOT: release +// CHECK: } // end sil function '$s4test11arrayLookupyS2iF' + +// CHECK-LLVM-LABEL: define {{.*}} @"$s4test11arrayLookupyS2iF" +// CHECK-LLVM-NOT: call +// CHECK-LLVM: [[E:%[0-9]+]] = getelementptr {{.*}} @"$s4test11arrayLookupyS2iFTv_" +// CHECK-LLVM-NEXT: [[L:%[0-9]+]] = load {{.*}} [[E]] +// CHECK-LLVM-NEXT: ret {{.*}} [[L]] +// CHECK-LLVM: } @inline(never) public func arrayLookup(_ i: Int) -> Int { let lookupTable = [10, 11, 12] diff --git a/test/Sanitizers/tsan-emptyarraystorage.swift b/test/Sanitizers/tsan-emptyarraystorage.swift index 13c51491c91d7..af9deb347e0f8 100644 --- a/test/Sanitizers/tsan-emptyarraystorage.swift +++ b/test/Sanitizers/tsan-emptyarraystorage.swift @@ -6,9 +6,6 @@ // REQUIRES: foundation // UNSUPPORTED: OS=tvos -// rdar://problem/75006869 -// XFAIL: OS=macosx && CPU=arm64 - import Foundation let sem = DispatchSemaphore(value: 0) diff --git a/test/Sanitizers/tsan-libdispatch.swift b/test/Sanitizers/tsan-libdispatch.swift index 49aebb5608c94..4739735da8795 100644 --- a/test/Sanitizers/tsan-libdispatch.swift +++ b/test/Sanitizers/tsan-libdispatch.swift @@ -9,9 +9,6 @@ // don't support TSan. // UNSUPPORTED: remote_run -// rdar://problem/75006869 -// XFAIL: OS=macosx && CPU=arm64 - // Test ThreadSanitizer execution end-to-end with libdispatch. import Dispatch diff --git a/test/Sanitizers/tsan-norace-block-release.swift b/test/Sanitizers/tsan-norace-block-release.swift index 1ff754fdc8551..2a2486b98d975 100644 --- a/test/Sanitizers/tsan-norace-block-release.swift +++ b/test/Sanitizers/tsan-norace-block-release.swift @@ -8,9 +8,6 @@ // don't support TSan. // UNSUPPORTED: remote_run -// rdar://problem/75006869 -// UNSUPPORTED: OS=macosx && CPU=arm64 - // Test that we do not report a race on block release operation. import Dispatch #if canImport(Darwin) diff --git a/test/Sanitizers/tsan-norace-deinit-run-time.swift b/test/Sanitizers/tsan-norace-deinit-run-time.swift index b6583d133a968..584448ad3194e 100644 --- a/test/Sanitizers/tsan-norace-deinit-run-time.swift +++ b/test/Sanitizers/tsan-norace-deinit-run-time.swift @@ -8,9 +8,6 @@ // don't support TSan. // UNSUPPORTED: remote_run -// rdar://problem/75006869 -// XFAIL: OS=macosx && CPU=arm64 - // Test that we do not report a race on deinit; the synchronization is guaranteed by runtime. import Dispatch #if canImport(Darwin) diff --git a/test/Sanitizers/tsan-static-exclusivity.swift b/test/Sanitizers/tsan-static-exclusivity.swift index c258d1d6fd7bd..a841d1f7bb2aa 100644 --- a/test/Sanitizers/tsan-static-exclusivity.swift +++ b/test/Sanitizers/tsan-static-exclusivity.swift @@ -5,6 +5,7 @@ // don't support TSan. // UNSUPPORTED: remote_run + struct OtherStruct { mutating func mutableTakingClosure(_ c: () -> Void) { } diff --git a/test/Sanitizers/tsan.swift b/test/Sanitizers/tsan.swift index fe72b332b7070..6b51cf07034a0 100644 --- a/test/Sanitizers/tsan.swift +++ b/test/Sanitizers/tsan.swift @@ -6,9 +6,6 @@ // UNSUPPORTED: OS=tvos // UNSUPPORTED: CPU=powerpc64le -// rdar://problem/75006869 -// XFAIL: OS=macosx && CPU=arm64 - // FIXME: This should be covered by "tsan_runtime"; older versions of Apple OSs // don't support TSan. // UNSUPPORTED: remote_run diff --git a/test/Sanitizers/tsan/actor_counters.swift b/test/Sanitizers/tsan/actor_counters.swift new file mode 100644 index 0000000000000..85e29b8fa6afd --- /dev/null +++ b/test/Sanitizers/tsan/actor_counters.swift @@ -0,0 +1,83 @@ +// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency %import-libdispatch -parse-as-library -sanitize=thread) + +// REQUIRES: executable_test +// REQUIRES: concurrency +// REQUIRES: libdispatch +// REQUIRES: tsan_runtime +// UNSUPPORTED: linux +// UNSUPPORTED: windows + +#if canImport(Darwin) +import Darwin +#elseif canImport(Glibc) +import Glibc +#endif + +actor Counter { + private var value = 0 + private let scratchBuffer: UnsafeMutableBufferPointer + + init(maxCount: Int) { + scratchBuffer = .allocate(capacity: maxCount) + scratchBuffer.initialize(repeating: 0) + } + + func next() -> Int { + let current = value + + // Make sure we haven't produced this value before + assert(scratchBuffer[current] == 0) + scratchBuffer[current] = 1 + + value = value + 1 + return current + } +} + + +func worker(identity: Int, counters: [Counter], numIterations: Int) async { + for i in 0..] = [] + for i in 0..= 2 ? Int(args[1])! : 10 + let workers = args.count >= 3 ? Int(args[2])! : 100 + let iterations = args.count >= 4 ? Int(args[3])! : 1000 + print("counters: \(counters), workers: \(workers), iterations: \(iterations)") + await runTest(numCounters: counters, numWorkers: workers, numIterations: iterations) + } +} diff --git a/test/Sanitizers/tsan/async_let_fibonacci.swift b/test/Sanitizers/tsan/async_let_fibonacci.swift new file mode 100644 index 0000000000000..78e3fc32545da --- /dev/null +++ b/test/Sanitizers/tsan/async_let_fibonacci.swift @@ -0,0 +1,56 @@ +// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency %import-libdispatch -parse-as-library -sanitize=thread) + +// REQUIRES: executable_test +// REQUIRES: concurrency +// REQUIRES: libdispatch +// REQUIRES: tsan_runtime + +#if canImport(Darwin) +import Darwin +#elseif canImport(Glibc) +import Glibc +#endif + +func fib(_ n: Int) -> Int { + var first = 0 + var second = 1 + for _ in 0.. Int { + if n == 0 || n == 1 { + return n + } + + async let first = await asyncFib(n-2) + async let second = await asyncFib(n-1) + + // Sleep a random amount of time waiting on the result producing a result. + usleep(UInt32.random(in: 0..<100) * 1000) + + let result = await first + second + + // Sleep a random amount of time before producing a result. + usleep(UInt32.random(in: 0..<100) * 1000) + + return result +} + +func runFibonacci(_ n: Int) async { + let result = await asyncFib(n) + + print() + print("Async fib = \(result), sequential fib = \(fib(n))") + assert(result == fib(n)) +} + +@main struct Main { + static func main() async { + await runFibonacci(10) + } +} diff --git a/test/Sanitizers/tsan/basic_future.swift b/test/Sanitizers/tsan/basic_future.swift new file mode 100644 index 0000000000000..0c54eafacf312 --- /dev/null +++ b/test/Sanitizers/tsan/basic_future.swift @@ -0,0 +1,85 @@ +// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency %import-libdispatch -parse-as-library -sanitize=thread) + +// REQUIRES: executable_test +// REQUIRES: concurrency +// REQUIRES: libdispatch +// REQUIRES: tsan_runtime + +import Dispatch + +#if canImport(Darwin) +import Darwin +#elseif canImport(Glibc) +import Glibc +#endif + +enum HomeworkError: Error, Equatable { + case dogAteIt(String) +} + +func formGreeting(name: String) async -> String { + return "Hello \(name) from async world" +} + +func testSimple( + name: String, dogName: String, shouldThrow: Bool, doSuspend: Bool +) async { + print("Testing name: \(name), dog: \(dogName), shouldThrow: \(shouldThrow) doSuspend: \(doSuspend)") + + var completed = false + + let taskHandle: Task.Handle = Task.runDetached { + let greeting = await formGreeting(name: name) + + // If the intent is to test suspending, wait a bit so the second task + // can complete. + if doSuspend { + print("- Future sleeping") + sleep(1) + } + + if (shouldThrow) { + print("- Future throwing") + throw HomeworkError.dogAteIt(dogName + " the dog") + } + + print("- Future returning normally") + return greeting + "!" + } + + // If the intent is not to test suspending, wait a bit so the first task + // can complete. + if !doSuspend { + print("+ Reader sleeping") + sleep(1) + } + + do { + print("+ Reader waiting for the result") + let result = try await taskHandle.get() + completed = true + print("+ Normal return: \(result)") + assert(result == "Hello \(name) from async world!") + } catch HomeworkError.dogAteIt(let badDog) { + completed = true + print("+ Error return: HomeworkError.dogAteIt(\(badDog))") + assert(badDog == dogName + " the dog") + } catch { + fatalError("Caught a different exception?") + } + + assert(completed) + print("Finished test") +} + + +@main struct Main { + static func main() async { + await testSimple(name: "Ted", dogName: "Hazel", shouldThrow: false, doSuspend: false) + await testSimple(name: "Ted", dogName: "Hazel", shouldThrow: true, doSuspend: false) + await testSimple(name: "Ted", dogName: "Hazel", shouldThrow: false, doSuspend: true) + await testSimple(name: "Ted", dogName: "Hazel", shouldThrow: true, doSuspend: true) + + print("Done") + } +} diff --git a/test/Sanitizers/tsan/mainactor.swift b/test/Sanitizers/tsan/mainactor.swift new file mode 100644 index 0000000000000..6fe56f8e5c845 --- /dev/null +++ b/test/Sanitizers/tsan/mainactor.swift @@ -0,0 +1,84 @@ +// RUN: %target-run-simple-swift(-parse-as-library -Xfrontend -enable-experimental-concurrency %import-libdispatch -sanitize=thread) | %FileCheck %s + +// REQUIRES: executable_test +// REQUIRES: concurrency +// REQUIRES: libdispatch +// REQUIRES: tsan_runtime + +import Dispatch + +/// @returns true iff the expected answer is actually the case, i.e., correct. +/// If the current queue does not match expectations, this function may return +/// false or just crash the program with non-zero exit code, depending on SDK. +func checkIfMainQueue(expectedAnswer expected: Bool) -> Bool { + if #available(macOS 10.12, iOS 10, tvOS 10, watchOS 3, *) { + dispatchPrecondition(condition: expected ? .onQueue(DispatchQueue.main) + : .notOnQueue(DispatchQueue.main)) + } + return true +} + +actor A { + func onCorrectQueue(_ count : Int) -> Int { + if checkIfMainQueue(expectedAnswer: false) { + print("on actor instance's queue") + return count + 1 + } + print("ERROR: not on actor instance's queue") + return -10 + } +} + +@MainActor func checkAnotherFn(_ count : Int) -> Int { + if checkIfMainQueue(expectedAnswer: true) { + print("on main queue again!") + return count + 1 + } else { + print("ERROR: left the main queue?") + return -10 + } +} + +@MainActor func enterMainActor(_ initialCount : Int) async -> Int { + if checkIfMainQueue(expectedAnswer: true) { + print("hello from main actor!") + } else { + print("ERROR: not on correct queue!") + } + + // try calling a function on another actor. + let count = await A().onCorrectQueue(initialCount) + + guard checkIfMainQueue(expectedAnswer: true) else { + print("ERROR: did not switch back to main actor!") + return -10 + } + + return checkAnotherFn(count) + 1 +} + +@concurrent func someFunc() async -> Int { + // NOTE: the "return" counter is just to make sure we're properly returning values. + // the expected number should be equal to the number of "plus-one" expressions. + // since there are no loops or duplicate function calls + return await enterMainActor(0) + 1 +} + + +// CHECK: starting +// CHECK-NOT: ERROR +// CHECK: hello from main actor! +// CHECK-NOT: ERROR +// CHECK: on actor instance's queue +// CHECK-NOT: ERROR +// CHECK: on main queue again! +// CHECK-NOT: ERROR +// CHECK: finished with return counter = 4 + +@main struct RunIt { + static func main() async { + print("starting") + let result = await someFunc() + print("finished with return counter = \(result)") + } +} diff --git a/test/Sanitizers/tsan/racy_actor_counters.swift b/test/Sanitizers/tsan/racy_actor_counters.swift new file mode 100644 index 0000000000000..8e7a63ed4e156 --- /dev/null +++ b/test/Sanitizers/tsan/racy_actor_counters.swift @@ -0,0 +1,67 @@ +// RUN: %target-swiftc_driver %s -Xfrontend -enable-experimental-concurrency -parse-as-library %import-libdispatch -target %sanitizers-target-triple -g -sanitize=thread -o %t +// RUN: %target-codesign %t +// RUN: env %env-TSAN_OPTIONS="abort_on_error=0" not %target-run %t 2>&1 | %swift-demangle --simplified | %FileCheck %s + +// REQUIRES: executable_test +// REQUIRES: concurrency +// REQUIRES: libdispatch +// REQUIRES: tsan_runtime + +var globalCounterValue = 0 + +actor Counter { + func next() -> Int { + let current = globalCounterValue + globalCounterValue += 1 + return current + } +} + +func worker(identity: Int, counters: [Counter], numIterations: Int) async { + for _ in 0..] = [] + for i in 0..= 2 ? Int(args[1])! : 10 + let workers = args.count >= 3 ? Int(args[2])! : 10 + let iterations = args.count >= 4 ? Int(args[3])! : 100 + print("counters: \(counters), workers: \(workers), iterations: \(iterations)") + await runTest(numCounters: counters, numWorkers: workers, numIterations: iterations) + } +} + +// CHECK: ThreadSanitizer: {{(Swift access|data)}} race +// CHECK: Location is global 'globalCounterValue' diff --git a/test/Sanitizers/tsan/racy_async_let_fibonacci.swift b/test/Sanitizers/tsan/racy_async_let_fibonacci.swift new file mode 100644 index 0000000000000..32162198a5837 --- /dev/null +++ b/test/Sanitizers/tsan/racy_async_let_fibonacci.swift @@ -0,0 +1,65 @@ +// RUN: %target-swiftc_driver %s -Xfrontend -enable-experimental-concurrency -parse-as-library %import-libdispatch -target %sanitizers-target-triple -g -sanitize=thread -o %t +// RUN: %target-codesign %t +// RUN: env %env-TSAN_OPTIONS="abort_on_error=0" not %target-run %t 2>&1 | %swift-demangle --simplified | %FileCheck %s + +// REQUIRES: executable_test +// REQUIRES: concurrency +// REQUIRES: libdispatch +// REQUIRES: tsan_runtime + +#if canImport(Darwin) +import Darwin +#elseif canImport(Glibc) +import Glibc +#endif + +func fib(_ n: Int) -> Int { + var first = 0 + var second = 1 + for _ in 0.. Int { + racyCounter += 1 + if n == 0 || n == 1 { + return n + } + + async let first = await asyncFib(n-2) + async let second = await asyncFib(n-1) + + // Sleep a random amount of time waiting on the result producing a result. + usleep(UInt32.random(in: 0..<100) * 1000) + + let result = await first + second + + // Sleep a random amount of time before producing a result. + usleep(UInt32.random(in: 0..<100) * 1000) + + return result +} + +func runFibonacci(_ n: Int) async { + let result = await asyncFib(n) + + print() + print("Async fib = \(result), sequential fib = \(fib(n))") + assert(result == fib(n)) + print("asyncFib() called around \(racyCounter) times") +} + +@main struct Main { + static func main() async { + await runFibonacci(10) + } +} + +// CHECK: ThreadSanitizer: Swift access race +// CHECK: Location is global 'racyCounter' diff --git a/test/Serialization/Recovery/types-5-to-4.swift b/test/Serialization/Recovery/types-5-to-4.swift index 2fcdc33729793..a64544c1d7c7b 100644 --- a/test/Serialization/Recovery/types-5-to-4.swift +++ b/test/Serialization/Recovery/types-5-to-4.swift @@ -16,8 +16,8 @@ import Lib func requiresConformance(_: B_RequiresConformance) {} func requiresConformance(_: B_RequiresConformance) {} -class Sub: Base {} // expected-error {{cannot inherit from class 'Base' (compiled with Swift 5.4) because it has overridable members that could not be loaded in Swift 4.1.50}} -class Impl: Proto {} // expected-error {{type 'Impl' cannot conform to protocol 'Proto' (compiled with Swift 5.4) because it has requirements that could not be loaded in Swift 4.1.50}} +class Sub: Base {} // expected-error {{cannot inherit from class 'Base' (compiled with Swift 5.5) because it has overridable members that could not be loaded in Swift 4.1.50}} +class Impl: Proto {} // expected-error {{type 'Impl' cannot conform to protocol 'Proto' (compiled with Swift 5.5) because it has requirements that could not be loaded in Swift 4.1.50}} #else // TEST diff --git a/test/SourceKit/CursorInfo/cursor_symbol_graph.swift b/test/SourceKit/CursorInfo/cursor_symbol_graph.swift index 40fae77130d4a..ea88769281546 100644 --- a/test/SourceKit/CursorInfo/cursor_symbol_graph.swift +++ b/test/SourceKit/CursorInfo/cursor_symbol_graph.swift @@ -745,7 +745,7 @@ enum MyEnum { // CHECKCASE: "spelling": "someCase" // CHECKCASE: } // CHECKCASE: ], -// CHECKCASE: "title": "someCase" +// CHECKCASE: "title": "MyEnum.someCase" // CHECKCASE: }, // CHECKCASE: "pathComponents": [ // CHECKCASE: "MyEnum", diff --git a/test/SourceKit/DocSupport/.#doc_clang_module.swift b/test/SourceKit/DocSupport/.#doc_clang_module.swift deleted file mode 120000 index 4447a9f517b98..0000000000000 --- a/test/SourceKit/DocSupport/.#doc_clang_module.swift +++ /dev/null @@ -1 +0,0 @@ -dgregor@Trinsic.local.724 \ No newline at end of file diff --git a/test/SourceKit/Misc/compiler_version.swift b/test/SourceKit/Misc/compiler_version.swift index 72dd451c37e7a..545e742b0b280 100644 --- a/test/SourceKit/Misc/compiler_version.swift +++ b/test/SourceKit/Misc/compiler_version.swift @@ -1,5 +1,5 @@ // RUN: %sourcekitd-test -req=compiler-version | %FileCheck %s // CHECK: key.version_major: 5 -// CHECK: key.version_minor: 4 +// CHECK: key.version_minor: 5 // CHECK: key.version_patch: 0 diff --git a/test/SymbolGraph/Symbols/Mixins/Availability/PlatformAgnostic.swift b/test/SymbolGraph/Symbols/Mixins/Availability/PlatformAgnostic.swift new file mode 100644 index 0000000000000..43f79de25817a --- /dev/null +++ b/test/SymbolGraph/Symbols/Mixins/Availability/PlatformAgnostic.swift @@ -0,0 +1,19 @@ +// RUN: %empty-directory(%t) +// RUN: %target-build-swift %s -module-name PlatformAgnostic -emit-module -emit-module-path %t/ +// RUN: %target-swift-symbolgraph-extract -module-name PlatformAgnostic -I %t -pretty-print -output-dir %t + +// RUN: %FileCheck %s --input-file %t/PlatformAgnostic.symbols.json --check-prefix CHECK-FS +// RUN: %FileCheck %s --input-file %t/PlatformAgnostic.symbols.json --check-prefix CHECK-FP +// RUN: %FileCheck %s --input-file %t/PlatformAgnostic.symbols.json --check-prefix CHECK-SO + +// CHECK-FS: FutureSwift +@available(swift 99) +public struct FutureSwift {} + +// CHECK-FP: FuturePackage +@available(_PackageDescription 99) +public struct FuturePackage {} + +// CHECK-SO: SwiftObsolete +@available(swift, obsoleted: 1.0) +public struct SwiftObsolete {} diff --git a/test/SymbolGraph/Symbols/Names.swift b/test/SymbolGraph/Symbols/Names.swift index 88ed6102377a5..bad344fa441c4 100644 --- a/test/SymbolGraph/Symbols/Names.swift +++ b/test/SymbolGraph/Symbols/Names.swift @@ -5,6 +5,8 @@ // RUN: %FileCheck %s --input-file %t/Names.symbols.json --check-prefix=FUNC // RUN: %FileCheck %s --input-file %t/Names.symbols.json --check-prefix=INNERTYPE // RUN: %FileCheck %s --input-file %t/Names.symbols.json --check-prefix=INNERTYPEALIAS +// RUN: %FileCheck %s --input-file %t/Names.symbols.json --check-prefix=INNERENUM +// RUN: %FileCheck %s --input-file %t/Names.symbols.json --check-prefix=INNERCASE public struct MyStruct { public struct InnerStruct {} @@ -12,6 +14,10 @@ public struct MyStruct { public typealias InnerTypeAlias = InnerStruct public func foo() {} + + public enum InnerEnum { + case InnerCase + } } // CHECK-LABEL: "precise": "s:5Names8MyStructV" @@ -29,3 +35,11 @@ public struct MyStruct { // INNERTYPEALIAS-LABEL: "precise": "s:5Names8MyStructV14InnerTypeAliasa" // INNERTYPEALIAS: names // INNERTYPEALIAS-NEXT: "title": "MyStruct.InnerTypeAlias" + +// INNERENUM-LABEL: "precise": "s:5Names8MyStructV9InnerEnumO", +// INNERENUM: names +// INNERENUM-NEXT: "title": "MyStruct.InnerEnum" + +// INNERCASE-LABEL: "precise": "s:5Names8MyStructV9InnerEnumO0D4CaseyA2EmF", +// INNERCASE: names +// INNERCASE-NEXT: "title": "MyStruct.InnerEnum.InnerCase", diff --git a/test/SymbolGraph/Symbols/Unavailable.swift b/test/SymbolGraph/Symbols/Unavailable.swift index 5404b5d7a35a3..732e7f945be97 100644 --- a/test/SymbolGraph/Symbols/Unavailable.swift +++ b/test/SymbolGraph/Symbols/Unavailable.swift @@ -25,13 +25,4 @@ extension ShouldAppear { public func shouldntAppear2() {} } -// CHECK-NOT: SwiftObsoleted -@available(swift, obsoleted: 1.0) -public struct SwiftObsoleted {} - -@available(swift, obsoleted: 1.0) -extension ShouldAppear { - public func shouldntAppear3() {} -} - // CHECK-NOT: shouldntAppear diff --git a/test/Syntax/Outputs/round_trip_parse_gen.swift.withkinds b/test/Syntax/Outputs/round_trip_parse_gen.swift.withkinds index 5bb514fb29d4b..96f62f93792d1 100644 --- a/test/Syntax/Outputs/round_trip_parse_gen.swift.withkinds +++ b/test/Syntax/Outputs/round_trip_parse_gen.swift.withkinds @@ -145,7 +145,7 @@ typealias G = (a x: = () rethrows -> () typealias I = (A & B<C>) -> C & D typealias J = inout @autoclosure () -> Int -typealias K = (@invalidAttr Int, inout Int, __shared Int, __owned Int) -> () +typealias K = (@invalidAttr Int, inout Int, __shared Int, __owned Int) -> () @objc private typealias T<a,b> = Int @objc private typealias T<a,b> diff --git a/test/attr/attr_objc_async.swift b/test/attr/attr_objc_async.swift index e1357c49061c9..b02b25ed24092 100644 --- a/test/attr/attr_objc_async.swift +++ b/test/attr/attr_objc_async.swift @@ -1,6 +1,6 @@ -// RUN: %target-swift-frontend -disable-objc-attr-requires-foundation-module -typecheck -verify -verify-ignore-unknown %s -swift-version 5 -enable-source-import -I %S/Inputs -enable-experimental-concurrency +// RUN: %target-swift-frontend -disable-objc-attr-requires-foundation-module -typecheck -verify -verify-ignore-unknown %s -swift-version 5 -enable-source-import -I %S/Inputs -enable-experimental-concurrency -warn-concurrency // RUN: %target-swift-ide-test -skip-deinit=false -print-ast-typechecked -source-filename %s -function-definitions=true -prefer-type-repr=false -print-implicit-attrs=true -explode-pattern-binding-decls=true -disable-objc-attr-requires-foundation-module -swift-version 5 -enable-source-import -I %S/Inputs -enable-experimental-concurrency | %FileCheck %s -// RUN: not %target-swift-frontend -typecheck -dump-ast -disable-objc-attr-requires-foundation-module %s -swift-version 5 -enable-source-import -I %S/Inputs -enable-experimental-concurrency > %t.ast +// RUN: not %target-swift-frontend -typecheck -dump-ast -disable-objc-attr-requires-foundation-module %s -swift-version 5 -enable-source-import -I %S/Inputs -enable-experimental-concurrency -warn-concurrency > %t.ast // RUN: %FileCheck -check-prefix CHECK-DUMP %s < %t.ast // REQUIRES: objc_interop // REQUIRES: concurrency diff --git a/test/attr/attr_specialize.swift b/test/attr/attr_specialize.swift index 9c329e603ce5a..c3ae29daccf0e 100644 --- a/test/attr/attr_specialize.swift +++ b/test/attr/attr_specialize.swift @@ -27,15 +27,16 @@ class NonSub {} // CHECK: @_specialize(exported: false, kind: full, where T == S) @_specialize(where T == S) @_specialize(where T == Int, U == Int) // expected-error{{cannot find type 'U' in scope}}, -// expected-error@-1{{Only one concrete type should be used in the same-type requirement in '_specialize' attribute}} @_specialize(where T == T1) // expected-error{{cannot find type 'T1' in scope}} +// expected-error@-1 {{too few generic parameters are specified in '_specialize' attribute (got 0, but expected 1)}} +// expected-note@-2 {{missing constraint for 'T' in '_specialize' attribute}} public func oneGenericParam(_ t: T) -> T { return t } // CHECK: @_specialize(exported: false, kind: full, where T == Int, U == Int) @_specialize(where T == Int, U == Int) -@_specialize(where T == Int) // expected-error{{too few type parameters are specified in '_specialize' attribute (got 1, but expected 2)}} expected-error{{Missing constraint for 'U' in '_specialize' attribute}} +@_specialize(where T == Int) // expected-error{{too few generic parameters are specified in '_specialize' attribute (got 1, but expected 2)}} expected-note{{missing constraint for 'U' in '_specialize' attribute}} public func twoGenericParams(_ t: T, u: U) -> (T, U) { return (t, u) } @@ -49,17 +50,21 @@ func nonGenericParam(x: Int) {} class G { // CHECK: @_specialize(exported: false, kind: full, where T == Int) @_specialize(where T == Int) - @_specialize(where T == T) // expected-error{{Only concrete type same-type requirements are supported by '_specialize' attribute}} - @_specialize(where T == S) // expected-error{{Only concrete type same-type requirements are supported by '_specialize' attribute}} + @_specialize(where T == T) // expected-warning{{redundant same-type constraint 'T' == 'T'}} + // expected-error@-1 {{too few generic parameters are specified in '_specialize' attribute (got 0, but expected 1)}} + // expected-note@-2 {{missing constraint for 'T' in '_specialize' attribute}} + @_specialize(where T == S) // expected-error{{same-type constraint 'T' == 'S' is recursive}} + // expected-error@-1 {{too few generic parameters are specified in '_specialize' attribute (got 0, but expected 1)}} + // expected-note@-2 {{missing constraint for 'T' in '_specialize' attribute}} @_specialize(where T == Int, U == Int) // expected-error{{cannot find type 'U' in scope}} - // expected-error@-1{{Only one concrete type should be used in the same-type requirement in '_specialize' attribute}} + func noGenericParams() {} // CHECK: @_specialize(exported: false, kind: full, where T == Int, U == Float) @_specialize(where T == Int, U == Float) // CHECK: @_specialize(exported: false, kind: full, where T == Int, U == S) @_specialize(where T == Int, U == S) - @_specialize(where T == Int) // expected-error{{too few type parameters are specified in '_specialize' attribute (got 1, but expected 2)}} expected-error {{Missing constraint for 'U' in '_specialize' attribute}} + @_specialize(where T == Int) // expected-error{{too few generic parameters are specified in '_specialize' attribute (got 1, but expected 2)}} expected-note {{missing constraint for 'U' in '_specialize' attribute}} func oneGenericParam(_ t: T, u: U) -> (U, T) { return (u, t) } @@ -75,6 +80,9 @@ struct AThing : Thing {} // CHECK: @_specialize(exported: false, kind: full, where T == AThing) @_specialize(where T == AThing) @_specialize(where T == Int) // expected-error{{same-type constraint type 'Int' does not conform to required protocol 'Thing'}} +// expected-error@-1 {{too few generic parameters are specified in '_specialize' attribute (got 0, but expected 1)}} +// expected-note@-2 {{missing constraint for 'T' in '_specialize' attribute}} + func oneRequirement(_ t: T) {} protocol HasElt { @@ -98,7 +106,7 @@ func superTypeRequirement(_ t: T) {} public func requirementOnNonGenericFunction(x: Int, y: Int) { } -@_specialize(where Y == Int) // expected-error{{too few type parameters are specified in '_specialize' attribute (got 1, but expected 2)}} expected-error{{Missing constraint for 'X' in '_specialize' attribute}} +@_specialize(where Y == Int) // expected-error{{too few generic parameters are specified in '_specialize' attribute (got 1, but expected 2)}} expected-note{{missing constraint for 'X' in '_specialize' attribute}} public func missingRequirement(x: X, y: Y) { } @@ -109,21 +117,18 @@ public func funcWithEmptySpecializeAttr(x: X, y: Y) { @_specialize(where X:_Trivial(8), Y:_Trivial(32), Z == Int) // expected-error{{cannot find type 'Z' in scope}} -// expected-error@-1{{Only one concrete type should be used in the same-type requirement in '_specialize' attribute}} @_specialize(where X:_Trivial(8), Y:_Trivial(32, 4)) -@_specialize(where X == Int) // expected-error{{too few type parameters are specified in '_specialize' attribute (got 1, but expected 2)}} expected-error{{Missing constraint for 'Y' in '_specialize' attribute}} -@_specialize(where Y:_Trivial(32)) // expected-error {{too few type parameters are specified in '_specialize' attribute (got 1, but expected 2)}} expected-error{{Missing constraint for 'X' in '_specialize' attribute}} -@_specialize(where Y: P) // expected-error{{Only same-type and layout requirements are supported by '_specialize' attribute}} expected-error{{too few type parameters are specified in '_specialize' attribute (got 1, but expected 2)}} expected-error{{Missing constraint for 'X' in '_specialize' attribute}} -@_specialize(where Y: MyClass) // expected-error{{cannot find type 'MyClass' in scope}} expected-error{{too few type parameters are specified in '_specialize' attribute (got 1, but expected 2)}} expected-error{{Missing constraint for 'X' in '_specialize' attribute}} -// expected-error@-1{{Only conformances to protocol types are supported by '_specialize' attribute}} +@_specialize(where X == Int) // expected-error{{too few generic parameters are specified in '_specialize' attribute (got 1, but expected 2)}} expected-note{{missing constraint for 'Y' in '_specialize' attribute}} +@_specialize(where Y:_Trivial(32)) // expected-error {{too few generic parameters are specified in '_specialize' attribute (got 1, but expected 2)}} expected-note{{missing constraint for 'X' in '_specialize' attribute}} +@_specialize(where Y: P) // expected-error{{only same-type and layout requirements are supported by '_specialize' attribute}} +@_specialize(where Y: MyClass) // expected-error{{cannot find type 'MyClass' in scope}} expected-error{{too few generic parameters are specified in '_specialize' attribute (got 0, but expected 2)}} expected-note{{missing constraint for 'X' in '_specialize' attribute}} expected-note{{missing constraint for 'Y' in '_specialize' attribute}} @_specialize(where X:_Trivial(8), Y == Int) @_specialize(where X == Int, Y == Int) -@_specialize(where X == Int, X == Int) // expected-error{{too few type parameters are specified in '_specialize' attribute (got 1, but expected 2)}} expected-error{{Missing constraint for 'Y' in '_specialize' attribute}} +@_specialize(where X == Int, X == Int) // expected-error{{too few generic parameters are specified in '_specialize' attribute (got 1, but expected 2)}} expected-note{{missing constraint for 'Y' in '_specialize' attribute}} // expected-warning@-1{{redundant same-type constraint 'X' == 'Int'}} // expected-note@-2{{same-type constraint 'X' == 'Int' written here}} @_specialize(where Y:_Trivial(32), X == Float) -@_specialize(where X1 == Int, Y1 == Int) // expected-error{{cannot find type 'X1' in scope}} expected-error{{cannot find type 'Y1' in scope}} expected-error{{too few type parameters are specified in '_specialize' attribute (got 0, but expected 2)}} expected-error{{Missing constraint for 'X' in '_specialize' attribute}} expected-error{{Missing constraint for 'Y' in '_specialize' attribute}} -// expected-error@-1 2{{Only one concrete type should be used in the same-type requirement in '_specialize' attribute}} +@_specialize(where X1 == Int, Y1 == Int) // expected-error{{cannot find type 'X1' in scope}} expected-error{{cannot find type 'Y1' in scope}} expected-error{{too few generic parameters are specified in '_specialize' attribute (got 0, but expected 2)}} expected-note{{missing constraint for 'X' in '_specialize' attribute}} expected-note{{missing constraint for 'Y' in '_specialize' attribute}} public func funcWithTwoGenericParameters(x: X, y: Y) { } @@ -149,16 +154,19 @@ public func funcWithTwoGenericParameters(x: X, y: Y) { @_specialize(kind: partial, kind: partial, where X == Int, Y == Int) // expected-error{{parameter 'kind' was already defined in '_specialize' attribute}} @_specialize(where X == Int, Y == Int, exported: true, kind: partial) // expected-error{{cannot find type 'exported' in scope}} expected-error{{cannot find type 'kind' in scope}} expected-error{{cannot find type 'partial' in scope}} expected-error{{expected type}} -// expected-error@-1 2{{Only conformances to protocol types are supported by '_specialize' attribute}} public func anotherFuncWithTwoGenericParameters(x: X, y: Y) { } -@_specialize(where T: P) // expected-error{{Only same-type and layout requirements are supported by '_specialize' attribute}} -@_specialize(where T: Int) // expected-error{{Only conformances to protocol types are supported by '_specialize' attribute}} +@_specialize(where T: P) // expected-error{{only same-type and layout requirements are supported by '_specialize' attribute}} +@_specialize(where T: Int) // expected-error{{type 'T' constrained to non-protocol, non-class type 'Int'}} expected-note {{use 'T == Int' to require 'T' to be 'Int'}} +// expected-error@-1 {{too few generic parameters are specified in '_specialize' attribute (got 0, but expected 1)}} +// expected-note@-2 {{missing constraint for 'T' in '_specialize' attribute}} -@_specialize(where T: S1) // expected-error{{Only conformances to protocol types are supported by '_specialize' attribute}} -@_specialize(where T: C1) // expected-error{{Only conformances to protocol types are supported by '_specialize' attribute}} -@_specialize(where Int: P) // expected-error{{Only same-type and layout requirements are supported by '_specialize' attribute}} expected-error{{too few type parameters are specified in '_specialize' attribute (got 0, but expected 1)}} expected-error{{Missing constraint for 'T' in '_specialize' attribute}} +@_specialize(where T: S1) // expected-error{{type 'T' constrained to non-protocol, non-class type 'S1'}} expected-note {{use 'T == S1' to require 'T' to be 'S1'}} +// expected-error@-1 {{too few generic parameters are specified in '_specialize' attribute (got 0, but expected 1)}} +// expected-note@-2 {{missing constraint for 'T' in '_specialize' attribute}} +@_specialize(where T: C1) // expected-error{{only same-type and layout requirements are supported by '_specialize' attribute}} +@_specialize(where Int: P) // expected-error{{type 'Int' in conformance requirement does not refer to a generic parameter or associated type}} expected-error{{too few generic parameters are specified in '_specialize' attribute (got 0, but expected 1)}} expected-note{{missing constraint for 'T' in '_specialize' attribute}} func funcWithForbiddenSpecializeRequirement(_ t: T) { } @@ -173,8 +181,10 @@ func funcWithForbiddenSpecializeRequirement(_ t: T) { @_specialize(where T: _RefCountedObject, T: _NativeRefCountedObject) // expected-warning@-1{{redundant constraint 'T' : '_RefCountedObject'}} // expected-note@-2 1{{constraint 'T' : '_NativeRefCountedObject' written here}} -@_specialize(where Array == Int) // expected-error{{Only requirements on generic parameters are supported by '_specialize' attribute}} -@_specialize(where T.Element == Int) // expected-error{{Only requirements on generic parameters are supported by '_specialize' attribute}} +@_specialize(where Array == Int) // expected-error{{generic signature requires types 'Array' and 'Int' to be the same}} +// expected-error@-1 {{too few generic parameters are specified in '_specialize' attribute (got 0, but expected 1)}} +// expected-note@-2 {{missing constraint for 'T' in '_specialize' attribute}} +@_specialize(where T.Element == Int) // expected-error{{only requirements on generic parameters are supported by '_specialize' attribute}} public func funcWithComplexSpecializeRequirements(t: T) -> Int { return 55555 } @@ -183,10 +193,16 @@ public protocol Proto: class { } @_specialize(where T: _RefCountedObject) +// expected-error@-1 {{too few generic parameters are specified in '_specialize' attribute (got 0, but expected 1)}} +// expected-note@-2 {{missing constraint for 'T' in '_specialize' attribute}} @_specialize(where T: _Trivial) // expected-error@-1{{generic parameter 'T' has conflicting constraints '_Trivial' and '_NativeClass'}} +// expected-error@-2 {{too few generic parameters are specified in '_specialize' attribute (got 0, but expected 1)}} +// expected-note@-3 {{missing constraint for 'T' in '_specialize' attribute}} @_specialize(where T: _Trivial(64)) // expected-error@-1{{generic parameter 'T' has conflicting constraints '_Trivial(64)' and '_NativeClass'}} +// expected-error@-2 {{too few generic parameters are specified in '_specialize' attribute (got 0, but expected 1)}} +// expected-note@-3 {{missing constraint for 'T' in '_specialize' attribute}} public func funcWithABaseClassRequirement(t: T) -> Int where T: C1 { return 44444 } @@ -223,7 +239,7 @@ public func copyValueAndReturn(_ t: S, s: inout S) -> S where S: P{ struct OuterStruct { struct MyStruct { - @_specialize(where T == Int, U == Float) // expected-error{{too few type parameters are specified in '_specialize' attribute (got 2, but expected 3)}} expected-error{{Missing constraint for 'S' in '_specialize' attribute}} + @_specialize(where T == Int, U == Float) // expected-error{{too few generic parameters are specified in '_specialize' attribute (got 2, but expected 3)}} expected-note{{missing constraint for 'S' in '_specialize' attribute}} public func foo(u : U) { } @@ -297,3 +313,10 @@ extension Container { @_specialize(exported: true, target: targetFun2(_:), where T == Int) // expected-error{{target function 'targetFun2' could not be found}} public func specifyTargetFunc2(_ t: T) { } } + +// Make sure we don't complain that 'E' is not explicitly specialized here. +// E becomes concrete via the combination of 'S == Set' and +// 'E == S.Element'. +@_specialize(where S == Set) +public func takesSequenceAndElement(_: S, _: E) + where S : Sequence, E == S.Element {} \ No newline at end of file diff --git a/test/attr/attributes.swift b/test/attr/attributes.swift index 7f0eb8fb3198b..64ed67e5721ad 100644 --- a/test/attr/attributes.swift +++ b/test/attr/attributes.swift @@ -205,8 +205,8 @@ func func_with_unknown_attr2(x: @unknown(_) Int) {} // expected-error {{unknown func func_with_unknown_attr3(x: @unknown(Int) -> Int) {} // expected-error {{unknown attribute 'unknown'}} func func_with_unknown_attr4(x: @unknown(Int) throws -> Int) {} // expected-error {{unknown attribute 'unknown'}} func func_with_unknown_attr5(x: @unknown (x: Int, y: Int)) {} // expected-error {{unknown attribute 'unknown'}} -func func_with_unknown_attr6(x: @unknown(x: Int, y: Int)) {} // expected-error {{unknown attribute 'unknown'}} expected-error {{expected parameter type following ':'}} -func func_with_unknown_attr7(x: @unknown (Int) () -> Int) {} // expected-error {{unknown attribute 'unknown'}} expected-error {{expected ',' separator}} {{47-47=,}} expected-error {{unnamed parameters must be written with the empty name '_'}} {{48-48=_: }} +func func_with_unknown_attr6(x: @unknown(x: Int, y: Int)) {} // expected-error {{unknown attribute 'unknown'}} +func func_with_unknown_attr7(x: @unknown (Int) () -> Int) {} // expected-error {{unknown attribute 'unknown'}} func func_type_attribute_with_space(x: @convention (c) () -> Int) {} // OK. Known attributes can have space before its paren. diff --git a/test/decl/func/rethrows.swift b/test/decl/func/rethrows.swift index d1b29d6888ff8..71a4bf00a20d4 100644 --- a/test/decl/func/rethrows.swift +++ b/test/decl/func/rethrows.swift @@ -612,3 +612,19 @@ func rdar_47550715() { func foo(_: A? = nil) {} // Ok func bar(_: A? = .none) {} // Ok } + +// SR-14270 - test case for diagnostic note 'because_rethrows_default_argument_throws' +func nonThrowableDefaultRethrows(_ f: () throws -> () = {}) rethrows { + try f() +} +// NOTE: This should compile and not emit a diagnostic because ideally the compiler could statically +// know the default argument value could never throw. See SR-1524. +nonThrowableDefaultRethrows() // expected-error {{call can throw but is not marked with 'try'}} + // expected-note@-1 {{call is to 'rethrows' function, but a defaulted argument function can throw}} + +func throwableDefaultRethrows(_ f: () throws -> () = { throw SomeError.Badness }) rethrows { + try f() +} +// This should always emit a diagnostic because we can statically know that default argument can throw. +throwableDefaultRethrows() // expected-error {{call can throw but is not marked with 'try'}} + // expected-note@-1 {{call is to 'rethrows' function, but a defaulted argument function can throw}} diff --git a/test/expr/unary/keypath/keypath.swift b/test/expr/unary/keypath/keypath.swift index 08282b4cd1bf2..50bdded7d12bc 100644 --- a/test/expr/unary/keypath/keypath.swift +++ b/test/expr/unary/keypath/keypath.swift @@ -1052,3 +1052,45 @@ func testSyntaxErrors() { _ = \A.a?; _ = \A.a!; } + +// SR-13364 - keypath missing optional crashes compiler: "Inactive constraints left over?" +func sr13364() { + let _: KeyPath = \.utf8.count // expected-error {{no exact matches in reference to property 'count'}} + // expected-note@-1 {{found candidate with type 'Int'}} +} + +// rdar://74711236 - crash due to incorrect member access in key path +func rdar74711236() { + struct S { + var arr: [V] = [] + } + + struct V : Equatable { + } + + enum Type { + case store + } + + struct Context { + func supported() -> [Type] { + return [] + } + } + + func test(context: Context?) { + var s = S() + + s.arr = { + // FIXME: Missing member reference is pattern needs a better diagnostic + if let type = context?.store { // expected-error {{type of expression is ambiguous without more context}} + // `isSupported` should be an invalid declaration to trigger a crash in `map(\.option)` + let isSupported = context!.supported().contains(type) // expected-error {{missing argument label 'where:' in call}} expected-error {{converting non-escaping value to '(Type) throws -> Bool' may allow it to escape}} + return (isSupported ? [type] : []).map(\.option) + // expected-error@-1 {{value of type 'Any' has no member 'option'}} + // expected-note@-2 {{cast 'Any' to 'AnyObject' or use 'as!' to force downcast to a more specific type to access members}} + } + return [] + }() + } +} diff --git a/test/sil-passpipeline-dump/basic.test-sh b/test/sil-passpipeline-dump/basic.test-sh index be06b84d2ff73..ac756a910403a 100644 --- a/test/sil-passpipeline-dump/basic.test-sh +++ b/test/sil-passpipeline-dump/basic.test-sh @@ -2,7 +2,8 @@ // CHECK: --- // CHECK: name: non-Diagnostic Enabling Mandatory Optimizations -// CHECK: passes: [ "for-each-loop-unroll", "mandatory-combine", "mandatory-arc-opts" ] +// CHECK: passes: [ "for-each-loop-unroll", "mandatory-combine", "mandatory-copy-propagation", +// CHECK: "mandatory-arc-opts" ] // CHECK: --- // CHECK: name: Serialization // CHECK: passes: [ "serialize-sil", "ownership-model-eliminator" ] diff --git a/test/stmt/defer.swift b/test/stmt/defer.swift new file mode 100644 index 0000000000000..ac113a4b1baaa --- /dev/null +++ b/test/stmt/defer.swift @@ -0,0 +1,163 @@ +// RUN: %target-typecheck-verify-swift + +func voidReturn1() {} +func breakContinue(_: Int) -> Int {} + +func testDefer(_ a : Int) { + + defer { voidReturn1() } + defer { breakContinue(1)+42 } // expected-warning {{result of operator '+' is unused}} + + // Ok: + defer { while false { break } } + + // Not ok. + while false { defer { break } } // expected-error {{'break' cannot transfer control out of a defer statement}} + // expected-warning@-1 {{'defer' statement at end of scope always executes immediately}}{{17-22=do}} + defer { return } // expected-error {{'return' cannot transfer control out of a defer statement}} + // expected-warning@-1 {{'defer' statement at end of scope always executes immediately}}{{3-8=do}} +} + +class SomeTestClass { + var x = 42 + + func method() { + defer { x = 97 } // self. not required here! + // expected-warning@-1 {{'defer' statement at end of scope always executes immediately}}{{5-10=do}} + } +} + +enum DeferThrowError: Error { + case someError +} + +func throwInDefer() { + defer { throw DeferThrowError.someError } // expected-error {{errors cannot be thrown out of a defer body}} + print("Foo") +} + +func throwInDeferOK1() { + defer { + do { + throw DeferThrowError.someError + } catch {} + } + print("Bar") +} + +func throwInDeferOK2() throws { + defer { + do { + throw DeferThrowError.someError + } catch {} + } + print("Bar") +} + +func throwingFuncInDefer1() throws { + defer { try throwingFunctionCalledInDefer() } // expected-error {{errors cannot be thrown out of a defer body}} + print("Bar") +} + +func throwingFuncInDefer1a() throws { + defer { + do { + try throwingFunctionCalledInDefer() + } catch {} + } + print("Bar") +} + +func throwingFuncInDefer2() throws { + defer { throwingFunctionCalledInDefer() } // expected-error {{errors cannot be thrown out of a defer body}} + print("Bar") +} + +func throwingFuncInDefer2a() throws { + defer { + do { + throwingFunctionCalledInDefer() + // expected-error@-1 {{call can throw but is not marked with 'try'}} + // expected-note@-2 {{did you mean to use 'try'?}} + // expected-note@-3 {{did you mean to handle error as optional value?}} + // expected-note@-4 {{did you mean to disable error propagation?}} + } catch {} + } + print("Bar") +} + +func throwingFuncInDefer3() { + defer { try throwingFunctionCalledInDefer() } // expected-error {{errors cannot be thrown out of a defer body}} + print("Bar") +} + +func throwingFuncInDefer3a() { + defer { + do { + try throwingFunctionCalledInDefer() + } catch {} + } + print("Bar") +} + +func throwingFuncInDefer4() { + defer { throwingFunctionCalledInDefer() } // expected-error {{errors cannot be thrown out of a defer body}} + print("Bar") +} + +func throwingFuncInDefer4a() { + defer { + do { + throwingFunctionCalledInDefer() + // expected-error@-1 {{call can throw but is not marked with 'try'}} + // expected-note@-2 {{did you mean to use 'try'?}} + // expected-note@-3 {{did you mean to handle error as optional value?}} + // expected-note@-4 {{did you mean to disable error propagation?}} + } catch {} + } + print("Bar") +} + +func throwingFunctionCalledInDefer() throws { + throw DeferThrowError.someError +} + +class SomeDerivedClass: SomeTestClass { + override init() { + defer { + super.init() // expected-error {{initializer chaining ('super.init') cannot be nested in another expression}} + } + } +} + +// rdar://75088379 -- 'defer' should not be able to forward-reference captures +func badForwardReference() { + defer { + _ = x2 // expected-error {{use of local variable 'x2' before its declaration}} + + let x1 = 0 + let y1 = 0 + + defer { + _ = x1 + _ = x2 // expected-error {{use of local variable 'x2' before its declaration}} + _ = y1 + _ = y2 // expected-error {{use of local variable 'y2' before its declaration}} + } + + let y2 = 0 // expected-note {{'y2' declared here}} + } + + let x2 = 0 // expected-note 2{{'x2' declared here}} + + func localFunc() { + defer { + _ = z1 // expected-error {{use of local variable 'z1' before its declaration}} + _ = z2 + } + + let z1 = 0 // expected-note {{'z1' declared here}} + } + + let z2 = 0 +} diff --git a/test/stmt/statements.swift b/test/stmt/statements.swift index b2cf3632f5808..5b16e9263356f 100644 --- a/test/stmt/statements.swift +++ b/test/stmt/statements.swift @@ -357,136 +357,6 @@ func testMyEnumWithCaseLabels(_ a : MyEnumWithCaseLabels) { } - -// "defer" - -func test_defer(_ a : Int) { - - defer { VoidReturn1() } - defer { breakContinue(1)+42 } // expected-warning {{result of operator '+' is unused}} - - // Ok: - defer { while false { break } } - - // Not ok. - while false { defer { break } } // expected-error {{'break' cannot transfer control out of a defer statement}} - // expected-warning@-1 {{'defer' statement at end of scope always executes immediately}}{{17-22=do}} - defer { return } // expected-error {{'return' cannot transfer control out of a defer statement}} - // expected-warning@-1 {{'defer' statement at end of scope always executes immediately}}{{3-8=do}} -} - -class SomeTestClass { - var x = 42 - - func method() { - defer { x = 97 } // self. not required here! - // expected-warning@-1 {{'defer' statement at end of scope always executes immediately}}{{5-10=do}} - } -} - -enum DeferThrowError: Error { - case someError -} - -func throwInDefer() { - defer { throw DeferThrowError.someError } // expected-error {{errors cannot be thrown out of a defer body}} - print("Foo") -} - -func throwInDeferOK1() { - defer { - do { - throw DeferThrowError.someError - } catch {} - } - print("Bar") -} - -func throwInDeferOK2() throws { - defer { - do { - throw DeferThrowError.someError - } catch {} - } - print("Bar") -} - -func throwingFuncInDefer1() throws { - defer { try throwingFunctionCalledInDefer() } // expected-error {{errors cannot be thrown out of a defer body}} - print("Bar") -} - -func throwingFuncInDefer1a() throws { - defer { - do { - try throwingFunctionCalledInDefer() - } catch {} - } - print("Bar") -} - -func throwingFuncInDefer2() throws { - defer { throwingFunctionCalledInDefer() } // expected-error {{errors cannot be thrown out of a defer body}} - print("Bar") -} - -func throwingFuncInDefer2a() throws { - defer { - do { - throwingFunctionCalledInDefer() - // expected-error@-1 {{call can throw but is not marked with 'try'}} - // expected-note@-2 {{did you mean to use 'try'?}} - // expected-note@-3 {{did you mean to handle error as optional value?}} - // expected-note@-4 {{did you mean to disable error propagation?}} - } catch {} - } - print("Bar") -} - -func throwingFuncInDefer3() { - defer { try throwingFunctionCalledInDefer() } // expected-error {{errors cannot be thrown out of a defer body}} - print("Bar") -} - -func throwingFuncInDefer3a() { - defer { - do { - try throwingFunctionCalledInDefer() - } catch {} - } - print("Bar") -} - -func throwingFuncInDefer4() { - defer { throwingFunctionCalledInDefer() } // expected-error {{errors cannot be thrown out of a defer body}} - print("Bar") -} - -func throwingFuncInDefer4a() { - defer { - do { - throwingFunctionCalledInDefer() - // expected-error@-1 {{call can throw but is not marked with 'try'}} - // expected-note@-2 {{did you mean to use 'try'?}} - // expected-note@-3 {{did you mean to handle error as optional value?}} - // expected-note@-4 {{did you mean to disable error propagation?}} - } catch {} - } - print("Bar") -} - -func throwingFunctionCalledInDefer() throws { - throw DeferThrowError.someError -} - -class SomeDerivedClass: SomeTestClass { - override init() { - defer { - super.init() // expected-error {{initializer chaining ('super.init') cannot be nested in another expression}} - } - } -} - func test_guard(_ x : Int, y : Int??, cond : Bool) { // These are all ok. diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 071142db86e97..15184e5bebb4e 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -25,7 +25,6 @@ add_swift_tool_subdirectory(sil-llvm-gen) add_swift_tool_subdirectory(sil-nm) add_swift_tool_subdirectory(sil-passpipeline-dumper) add_swift_tool_subdirectory(swift-llvm-opt) -add_swift_tool_subdirectory(swift-api-digester) add_swift_tool_subdirectory(swift-ast-script) add_swift_tool_subdirectory(swift-refactor) add_swift_tool_subdirectory(libSwiftScan) diff --git a/tools/driver/CMakeLists.txt b/tools/driver/CMakeLists.txt index fe788d83f1be1..ce9319b941bcd 100644 --- a/tools/driver/CMakeLists.txt +++ b/tools/driver/CMakeLists.txt @@ -3,6 +3,7 @@ add_swift_host_tool(swift-frontend autolink_extract_main.cpp modulewrap_main.cpp cross_module_opt_main.cpp + swift_api_digester_main.cpp swift_indent_main.cpp swift_symbolgraph_extract_main.cpp swift_api_extract_main.cpp @@ -10,6 +11,7 @@ add_swift_host_tool(swift-frontend ) target_link_libraries(swift-frontend PRIVATE + swiftAPIDigester swiftDriver swiftFrontendTool swiftSymbolGraphGen @@ -45,12 +47,18 @@ swift_create_post_build_symlink(swift-frontend DESTINATION "swift-autolink-extract${CMAKE_EXECUTABLE_SUFFIX}" WORKING_DIRECTORY "${SWIFT_RUNTIME_OUTPUT_INTDIR}") +swift_create_post_build_symlink(swift-frontend + SOURCE "swift-frontend${CMAKE_EXECUTABLE_SUFFIX}" + DESTINATION "swift-api-digester${CMAKE_EXECUTABLE_SUFFIX}" + WORKING_DIRECTORY "${SWIFT_RUNTIME_OUTPUT_INTDIR}") + add_swift_tool_symlink(swift swift-frontend compiler) add_swift_tool_symlink(swiftc swift-frontend compiler) add_swift_tool_symlink(swift-symbolgraph-extract swift-frontend compiler) add_swift_tool_symlink(swift-api-extract swift-frontend compiler) add_swift_tool_symlink(swift-autolink-extract swift-frontend autolink-driver) add_swift_tool_symlink(swift-indent swift-frontend editor-integration) +add_swift_tool_symlink(swift-api-digester swift-frontend compiler) # If building as part of clang, make sure the headers are installed. if(NOT SWIFT_BUILT_STANDALONE) @@ -70,6 +78,9 @@ swift_install_in_component(FILES "${SWIFT_RUNTIME_OUTPUT_INTDIR}/swift-symbolgra swift_install_in_component(FILES "${SWIFT_RUNTIME_OUTPUT_INTDIR}/swift-api-extract${CMAKE_EXECUTABLE_SUFFIX}" DESTINATION "bin" COMPONENT compiler) +swift_install_in_component(FILES "${SWIFT_RUNTIME_OUTPUT_INTDIR}/swift-api-digester${CMAKE_EXECUTABLE_SUFFIX}" + DESTINATION "bin" + COMPONENT compiler) add_dependencies(autolink-driver swift-frontend) swift_install_in_component(FILES "${SWIFT_RUNTIME_OUTPUT_INTDIR}/swift-autolink-extract${CMAKE_EXECUTABLE_SUFFIX}" DESTINATION "bin" diff --git a/tools/driver/cross_module_opt_main.cpp b/tools/driver/cross_module_opt_main.cpp index 2c55353441da5..5d60896f5fd4d 100644 --- a/tools/driver/cross_module_opt_main.cpp +++ b/tools/driver/cross_module_opt_main.cpp @@ -26,15 +26,48 @@ using namespace llvm::opt; using namespace swift; using namespace modulesummary; +class MergeModuleSummaryInvocation { +public: + std::string OutputFilename; + std::vector InputFilenames; + + bool parseArgs(ArrayRef Args, DiagnosticEngine &Diags) { + using namespace options; + + std::unique_ptr Table = createSwiftOptTable(); + unsigned MissingIndex; + unsigned MissingCount; + llvm::opt::InputArgList ParsedArgs = + Table->ParseArgs(Args, MissingIndex, MissingCount, SwiftMergeModuleSummaryOption); + + if (MissingCount) { + Diags.diagnose(SourceLoc(), diag::error_missing_arg_value, + ParsedArgs.getArgString(MissingIndex), MissingCount); + return true; + } + + for (const Arg *A : ParsedArgs.filtered(OPT_INPUT)) { + InputFilenames.push_back(A->getValue()); + } + + if (const Arg *A = ParsedArgs.getLastArg(OPT_o)) { + OutputFilename = A->getValue(); + } + + std::vector LLVMArgs {""}; + for (const Arg *A : ParsedArgs.filtered(OPT_Xllvm)) { + LLVMArgs.push_back(A->getValue()); + } + + llvm::cl::ParseCommandLineOptions(LLVMArgs.size(), LLVMArgs.data(), ""); + return false; + } +}; + static llvm::cl::opt LTOPrintLiveTrace("lto-print-live-trace", llvm::cl::init(""), llvm::cl::desc("Print liveness trace for the symbol")); -static llvm::cl::list - InputFilenames(llvm::cl::Positional, llvm::cl::desc("[input files...]")); -static llvm::cl::opt - OutputFilename("o", llvm::cl::desc("output filename")); - static llvm::DenseSet computePreservedGUIDs(ModuleSummaryIndex *summary) { llvm::DenseSet Set(1); for (auto FI = summary->functions_begin(), FE = summary->functions_end(); @@ -239,13 +272,16 @@ int cross_module_opt_main(ArrayRef Args, const char *Argv0, void *MainAddr) { INITIALIZE_LLVM(); - llvm::cl::ParseCommandLineOptions(Args.size(), Args.data(), "Swift LTO\n"); - CompilerInstance Instance; PrintingDiagnosticConsumer PDC; Instance.addDiagnosticConsumer(&PDC); - if (InputFilenames.empty()) { + MergeModuleSummaryInvocation Invocation; + if (Invocation.parseArgs(Args, Instance.getDiags())) { + return true; + } + + if (Invocation.InputFilenames.empty()) { Instance.getDiags().diagnose(SourceLoc(), diag::error_mode_requires_an_input_file); return 1; @@ -253,7 +289,7 @@ int cross_module_opt_main(ArrayRef Args, const char *Argv0, auto TheSummary = std::make_unique(); - for (auto Filename : InputFilenames) { + for (auto Filename : Invocation.InputFilenames) { LLVM_DEBUG(llvm::dbgs() << "Loading module summary " << Filename << "\n"); auto ErrOrBuf = llvm::MemoryBuffer::getFile(Filename); if (!ErrOrBuf) { @@ -276,6 +312,6 @@ int cross_module_opt_main(ArrayRef Args, const char *Argv0, markDeadSymbols(*TheSummary.get(), PreservedGUIDs); modulesummary::writeModuleSummaryIndex(*TheSummary, Instance.getDiags(), - OutputFilename); + Invocation.OutputFilename); return 0; } diff --git a/tools/driver/driver.cpp b/tools/driver/driver.cpp index 406ecde94777d..37873d9db027f 100644 --- a/tools/driver/driver.cpp +++ b/tools/driver/driver.cpp @@ -78,6 +78,10 @@ extern int swift_indent_main(ArrayRef Args, const char *Argv0, extern int swift_symbolgraph_extract_main(ArrayRef Args, const char *Argv0, void *MainAddr); +/// Run 'swift-api-digester' +extern int swift_api_digester_main(ArrayRef Args, + const char *Argv0, void *MainAddr); + /// Run 'swift-api-extract' extern int swift_api_extract_main(ArrayRef Args, const char *Argv0, void *MainAddr); @@ -151,6 +155,26 @@ static bool shouldDisallowNewDriver(StringRef ExecName, return false; } +static bool appendSwiftDriverName(SmallString<256> &buffer) { + assert(llvm::sys::fs::exists(buffer)); + if (auto driverNameOp = llvm::sys::Process::GetEnv("SWIFT_USE_NEW_DRIVER")) { + llvm::sys::path::append(buffer, *driverNameOp); + return true; + } +#ifdef __APPLE__ + // FIXME: use swift-driver as the default driver for all platforms. + llvm::sys::path::append(buffer, "swift-driver"); + if (llvm::sys::fs::exists(buffer)) { + return true; + } + llvm::sys::path::remove_filename(buffer); + llvm::sys::path::append(buffer, "swift-driver-new"); + return true; +#else + return false; +#endif +} + static int run_driver(StringRef ExecName, const ArrayRef argv) { // Handle integrated tools. @@ -191,16 +215,12 @@ static int run_driver(StringRef ExecName, DiagnosticEngine Diags(SM); Diags.addConsumer(PDC); - std::string newDriverName = "swift-driver-new"; - if (auto driverNameOp = llvm::sys::Process::GetEnv("SWIFT_USE_NEW_DRIVER")) { - newDriverName = driverNameOp.getValue(); - } // Forwarding calls to the swift driver if the C++ driver is invoked as `swift` // or `swiftc`, and an environment variable SWIFT_USE_NEW_DRIVER is defined. if (!shouldDisallowNewDriver(ExecName, argv)) { SmallString<256> NewDriverPath(llvm::sys::path::parent_path(Path)); - llvm::sys::path::append(NewDriverPath, newDriverName); - if (llvm::sys::fs::exists(NewDriverPath)) { + if (appendSwiftDriverName(NewDriverPath) && + llvm::sys::fs::exists(NewDriverPath)) { SmallVector subCommandArgs; // Rewrite the program argument. subCommandArgs.push_back(NewDriverPath.c_str()); @@ -210,8 +230,6 @@ static int run_driver(StringRef ExecName, assert(ExecName == "swift"); subCommandArgs.push_back("--driver-mode=swift"); } - subCommandArgs.insert(subCommandArgs.end(), argv.begin() + 1, argv.end()); - // Push these non-op frontend arguments so the build log can indicate // the new driver is used. subCommandArgs.push_back("-Xfrontend"); @@ -219,6 +237,9 @@ static int run_driver(StringRef ExecName, subCommandArgs.push_back("-Xfrontend"); subCommandArgs.push_back(NewDriverPath.c_str()); + // Push on the source program arguments + subCommandArgs.insert(subCommandArgs.end(), argv.begin() + 1, argv.end()); + // Execute the subcommand. subCommandArgs.push_back(nullptr); ExecuteInPlace(NewDriverPath.c_str(), subCommandArgs.data()); @@ -247,6 +268,10 @@ static int run_driver(StringRef ExecName, return swift_api_extract_main( TheDriver.getArgsWithoutProgramNameAndDriverMode(argv), argv[0], (void *)(intptr_t)getExecutablePath); + case Driver::DriverKind::APIDigester: + return swift_api_digester_main( + TheDriver.getArgsWithoutProgramNameAndDriverMode(argv), argv[0], + (void *)(intptr_t)getExecutablePath); default: break; } diff --git a/tools/swift-api-digester/swift-api-digester.cpp b/tools/driver/swift_api_digester_main.cpp similarity index 97% rename from tools/swift-api-digester/swift-api-digester.cpp rename to tools/driver/swift_api_digester_main.cpp index fc450d0589165..1e247922a1b87 100644 --- a/tools/swift-api-digester/swift-api-digester.cpp +++ b/tools/driver/swift_api_digester_main.cpp @@ -33,8 +33,8 @@ #include "swift/AST/DiagnosticsModuleDiffer.h" #include "swift/IDE/APIDigesterData.h" #include -#include "ModuleAnalyzerNodes.h" -#include "ModuleDiagsConsumer.h" +#include "swift/APIDigester/ModuleAnalyzerNodes.h" +#include "swift/APIDigester/ModuleDiagsConsumer.h" using namespace swift; using namespace ide; @@ -2551,13 +2551,6 @@ static int generateMigrationScript(StringRef LeftPath, StringRef RightPath, return 0; } -// This function isn't referenced outside its translation unit, but it -// can't use the "static" keyword because its address is used for -// getMainExecutable (since some platforms don't support taking the -// address of main, and some platforms can't implement getMainExecutable -// without being given the address of a function in the main executable). -void anchorForGetMainExecutable() {} - static void setSDKPath(CompilerInvocation &InitInvok, bool IsBaseline) { if (IsBaseline) { // Set baseline SDK @@ -2578,12 +2571,10 @@ static void setSDKPath(CompilerInvocation &InitInvok, bool IsBaseline) { } } -static int prepareForDump(const char *Main, +static int prepareForDump(std::string MainExecutablePath, CompilerInvocation &InitInvok, - llvm::StringSet<> &Modules, - bool IsBaseline = false) { - InitInvok.setMainExecutablePath(fs::getMainExecutable(Main, - reinterpret_cast(&anchorForGetMainExecutable))); + llvm::StringSet<> &Modules, bool IsBaseline = false) { + InitInvok.setMainExecutablePath(MainExecutablePath); InitInvok.setModuleName("swift_ide_test"); setSDKPath(InitInvok, IsBaseline); @@ -2692,7 +2683,7 @@ static int deserializeNameCorrection(APIDiffItemStore &Store, return EC.value(); } -static CheckerOptions getCheckOpts(int argc, char *argv[]) { +static CheckerOptions getCheckOpts(ArrayRef Args) { CheckerOptions Opts; Opts.AvoidLocation = options::AvoidLocation; Opts.AvoidToolArgs = options::AvoidToolArgs; @@ -2708,8 +2699,8 @@ static CheckerOptions getCheckOpts(int argc, char *argv[]) { Opts.SkipOSCheck = options::DisableOSChecks; Opts.CompilerStyle = options::CompilerStyleDiags || !options::SerializedDiagPath.empty(); - for (int i = 1; i < argc; ++i) - Opts.ToolArgs.push_back(argv[i]); + for (auto Arg : Args) + Opts.ToolArgs.push_back(Arg); if (!options::SDK.empty()) { auto Ver = getSDKBuildVersion(options::SDK); @@ -2721,10 +2712,11 @@ static CheckerOptions getCheckOpts(int argc, char *argv[]) { return Opts; } -static SDKNodeRoot *getSDKRoot(const char *Main, SDKContext &Ctx, bool IsBaseline) { +static SDKNodeRoot *getSDKRoot(std::string MainExecutablePath, SDKContext &Ctx, + bool IsBaseline) { CompilerInvocation Invok; llvm::StringSet<> Modules; - if (prepareForDump(Main, Invok, Modules, IsBaseline)) + if (prepareForDump(MainExecutablePath, Invok, Modules, IsBaseline)) return nullptr; return getSDKNodeRoot(Ctx, Invok, Modules); } @@ -2749,20 +2741,18 @@ static ComparisonInputMode checkComparisonInputMode() { return ComparisonInputMode::BaselineJson; } -static std::string getDefaultBaselineDir(const char *Main) { +static std::string getDefaultBaselineDir(std::string MainExecutablePath) { llvm::SmallString<128> BaselineDir; - // The path of the swift-api-digester executable. - std::string ExePath = llvm::sys::fs::getMainExecutable(Main, - reinterpret_cast(&anchorForGetMainExecutable)); - BaselineDir.append(ExePath); + BaselineDir.append(MainExecutablePath); llvm::sys::path::remove_filename(BaselineDir); // Remove /swift-api-digester llvm::sys::path::remove_filename(BaselineDir); // Remove /bin llvm::sys::path::append(BaselineDir, "lib", "swift", "FrameworkABIBaseline"); return BaselineDir.str().str(); } -static std::string getEmptyBaselinePath(const char *Main) { - llvm::SmallString<128> BaselinePath(getDefaultBaselineDir(Main)); +static std::string getEmptyBaselinePath(std::string MainExecutablePath) { + llvm::SmallString<128> BaselinePath( + getDefaultBaselineDir(MainExecutablePath)); llvm::sys::path::append(BaselinePath, "nil.json"); return BaselinePath.str().str(); } @@ -2788,10 +2778,11 @@ static StringRef getBaselineFilename(llvm::Triple Triple) { } } -static std::string getDefaultBaselinePath(const char *Main, StringRef Module, - llvm::Triple Triple, +static std::string getDefaultBaselinePath(std::string MainExecutablePath, + StringRef Module, llvm::Triple Triple, bool ABI) { - llvm::SmallString<128> BaselinePath(getDefaultBaselineDir(Main)); + llvm::SmallString<128> BaselinePath( + getDefaultBaselineDir(MainExecutablePath)); llvm::sys::path::append(BaselinePath, Module); // Look for ABI or API baseline llvm::sys::path::append(BaselinePath, ABI? "ABI": "API"); @@ -2807,12 +2798,13 @@ static std::string getCustomBaselinePath(llvm::Triple Triple, bool ABI) { return BaselinePath.str().str(); } -static SDKNodeRoot *getBaselineFromJson(const char *Main, SDKContext &Ctx) { +static SDKNodeRoot *getBaselineFromJson(std::string MainExecutablePath, + SDKContext &Ctx) { SwiftDeclCollector Collector(Ctx); CompilerInvocation Invok; llvm::StringSet<> Modules; // We need to call prepareForDump to parse target triple. - if (prepareForDump(Main, Invok, Modules, true)) + if (prepareForDump(MainExecutablePath, Invok, Modules, true)) return nullptr; assert(Modules.size() == 1 && @@ -2825,9 +2817,9 @@ static SDKNodeRoot *getBaselineFromJson(const char *Main, SDKContext &Ctx) { Path = getCustomBaselinePath(Invok.getLangOptions().Target, Ctx.checkingABI()); } else if (options::UseEmptyBaseline) { - Path = getEmptyBaselinePath(Main); + Path = getEmptyBaselinePath(MainExecutablePath); } else { - Path = getDefaultBaselinePath(Main, Modules.begin()->getKey(), + Path = getDefaultBaselinePath(MainExecutablePath, Modules.begin()->getKey(), Invok.getLangOptions().Target, Ctx.checkingABI()); } @@ -2860,26 +2852,37 @@ static std::string getJsonOutputFilePath(llvm::Triple Triple, bool ABI) { exit(1); } -int main(int argc, char *argv[]) { - PROGRAM_START(argc, argv); +int swift_api_digester_main(ArrayRef Args, const char *Argv0, + void *MainAddr) { INITIALIZE_LLVM(); + // LLVM Command Line parsing expects to trim off argv[0]. + SmallVector ArgsWithArgv0{Argv0}; + ArgsWithArgv0.append(Args.begin(), Args.end()); + + std::string MainExecutablePath = fs::getMainExecutable(Argv0, MainAddr); + llvm::cl::HideUnrelatedOptions(options::Category); - llvm::cl::ParseCommandLineOptions(argc, argv, "Swift SDK Digester\n"); + llvm::cl::ParseCommandLineOptions(ArgsWithArgv0.size(), + llvm::makeArrayRef(ArgsWithArgv0).data(), + "Swift SDK Digester\n"); CompilerInvocation InitInvok; llvm::StringSet<> Modules; std::vector PrintApis; llvm::StringSet<> IgnoredUsrs; readIgnoredUsrs(IgnoredUsrs); - CheckerOptions Opts = getCheckOpts(argc, argv); + CheckerOptions Opts = getCheckOpts(Args); for (auto Name : options::ApisPrintUsrs) PrintApis.push_back(Name); switch (options::Action) { case ActionType::DumpSDK: - return (prepareForDump(argv[0], InitInvok, Modules)) ? 1 : - dumpSDKContent(InitInvok, Modules, - getJsonOutputFilePath(InitInvok.getLangOptions().Target, Opts.ABI), + return (prepareForDump(MainExecutablePath, InitInvok, Modules)) + ? 1 + : dumpSDKContent( + InitInvok, Modules, + getJsonOutputFilePath(InitInvok.getLangOptions().Target, + Opts.ABI), Opts); case ActionType::MigratorGen: case ActionType::DiagnoseSDKs: { @@ -2904,17 +2907,17 @@ int main(int argc, char *argv[]) { } case ComparisonInputMode::BaselineJson: { SDKContext Ctx(Opts); - return diagnoseModuleChange(Ctx, getBaselineFromJson(argv[0], Ctx), - getSDKRoot(argv[0], Ctx, false), - options::OutputFile, - std::move(protocolAllowlist)); + return diagnoseModuleChange( + Ctx, getBaselineFromJson(MainExecutablePath, Ctx), + getSDKRoot(MainExecutablePath, Ctx, false), options::OutputFile, + std::move(protocolAllowlist)); } case ComparisonInputMode::BothLoad: { SDKContext Ctx(Opts); - return diagnoseModuleChange(Ctx, getSDKRoot(argv[0], Ctx, true), - getSDKRoot(argv[0], Ctx, false), - options::OutputFile, - std::move(protocolAllowlist)); + return diagnoseModuleChange( + Ctx, getSDKRoot(MainExecutablePath, Ctx, true), + getSDKRoot(MainExecutablePath, Ctx, false), options::OutputFile, + std::move(protocolAllowlist)); } } } diff --git a/tools/libSwiftSyntaxParser/libSwiftSyntaxParser.cpp b/tools/libSwiftSyntaxParser/libSwiftSyntaxParser.cpp index d5002a74ceaae..033a7049a7cb1 100644 --- a/tools/libSwiftSyntaxParser/libSwiftSyntaxParser.cpp +++ b/tools/libSwiftSyntaxParser/libSwiftSyntaxParser.cpp @@ -245,12 +245,21 @@ class CLibParseActions final : public SyntaxParseActions { OpaqueSyntaxNode makeDeferredLayout( syntax::SyntaxKind k, bool isMissing, - const ArrayRef &children) override { + const MutableArrayRef &parsedChildren) override { assert(!isMissing && "Missing layout nodes not implemented yet"); + auto childrenMem = DeferredNodeAllocator.Allocate( + parsedChildren.size()); + auto children = + llvm::makeMutableArrayRef(childrenMem, parsedChildren.size()); + // Compute the length of this node. unsigned length = 0; - for (auto &child : children) { + size_t index = 0; + for (auto &parsedChild : parsedChildren) { + auto child = parsedChild.takeRecordedOrDeferredNode(); + children[index++] = child; + switch (child.getKind()) { case RecordedOrDeferredNode::Kind::Null: break; diff --git a/tools/swift-api-digester/CMakeLists.txt b/tools/swift-api-digester/CMakeLists.txt deleted file mode 100644 index 1d009b3d7cb95..0000000000000 --- a/tools/swift-api-digester/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -add_swift_host_tool(swift-api-digester - swift-api-digester.cpp - ModuleAnalyzerNodes.cpp - ModuleDiagsConsumer.cpp - SWIFT_COMPONENT toolchain-tools -) -target_link_libraries(swift-api-digester - PRIVATE - swiftFrontend - swiftSIL - swiftIDE) diff --git a/unittests/runtime/Actor.cpp b/unittests/runtime/Actor.cpp index 36ec2406218cc..5bc62461c518a 100644 --- a/unittests/runtime/Actor.cpp +++ b/unittests/runtime/Actor.cpp @@ -118,15 +118,14 @@ class TaskContinuationFromLambda { static llvm::Optional lambdaStorage; SWIFT_CC(swiftasync) - static void invoke(AsyncTask *task, ExecutorRef executor, - SWIFT_ASYNC_CONTEXT AsyncContext *context) { - (*lambdaStorage)(task, executor, static_cast(context)); + static void invoke(SWIFT_ASYNC_CONTEXT AsyncContext *context, SWIFT_CONTEXT HeapObject *) { + (*lambdaStorage)(static_cast(context)); } public: static TaskContinuationFunction *get(Fn &&fn) { lambdaStorage.emplace(std::move(fn)); - return &invoke; + return (TaskContinuationFunction*) &invoke; } }; @@ -142,7 +141,6 @@ createTaskWithContext(JobPriority priority, Fn &&fn) { TaskContinuationFromLambda::get(std::move(fn)); auto pair = swift_task_create_f(JobFlags(JobKind::Task, priority), - /*parent*/ nullptr, invoke, sizeof(Context)); return std::make_pair(pair.Task, @@ -163,6 +161,11 @@ static void parkTask(AsyncTask *task, Context *context, Fn &&fn) { task->ResumeContext = context; } +template +static TaskContinuationFunction *prepareContinuation(Fn &&fn) { + return TaskContinuationFromLambda::get(std::move(fn)); +} + namespace { template class TupleContext : public AsyncContext { @@ -216,23 +219,23 @@ static AsyncTask *createTaskStoring(JobPriority priority, TEST(ActorTest, validateTestHarness) { run([] { auto task0 = createTask(JobPriority::Background, - [](AsyncTask *task, ExecutorRef executor, AsyncContext *context) { + [](AsyncContext *context) { EXPECT_PROGRESS(5); EXPECT_PROGRESS(6); finishTest(); - return context->resumeParent(task, executor); + return context->ResumeParent(context); }); auto task1 = createTask(JobPriority::Default, - [](AsyncTask *task, ExecutorRef executor, AsyncContext *context) { + [](AsyncContext *context) { EXPECT_PROGRESS(1); EXPECT_PROGRESS(2); - return context->resumeParent(task, executor); + return context->ResumeParent(context); }); auto task2 = createTask(JobPriority::Default, - [](AsyncTask *task, ExecutorRef executor, AsyncContext *context) { + [](AsyncContext *context) { EXPECT_PROGRESS(3); EXPECT_PROGRESS(4); - return context->resumeParent(task, executor); + return context->ResumeParent(context); }); swift_task_enqueueGlobal(task0); @@ -250,30 +253,32 @@ TEST(ActorTest, actorSwitch) { auto actor = createActor(); auto task0 = createTaskStoring(JobPriority::Default, (AsyncTask*) nullptr, actor, - [](AsyncTask *task, ExecutorRef executor, Context *context) { + [](Context *context) { EXPECT_PROGRESS(1); - EXPECT_TRUE(executor.isGeneric()); + EXPECT_TRUE(swift_task_getCurrentExecutor().isGeneric()); EXPECT_EQ(nullptr, context->get<0>()); - std::get<0>(context->values) = task; + std::get<0>(context->values) = swift_task_getCurrent(); - parkTask(task, context, - [](AsyncTask *task, ExecutorRef executor, Context *context) { + auto continuation = prepareContinuation( + [](Context *context) { EXPECT_PROGRESS(2); + auto executor = swift_task_getCurrentExecutor(); EXPECT_FALSE(executor.isGeneric()); EXPECT_EQ(ExecutorRef::forDefaultActor(context->get<1>()), executor); - EXPECT_EQ(task, context->get<0>()); - parkTask(task, context, - [](AsyncTask *task, ExecutorRef executor, Context *context) { + EXPECT_EQ(swift_task_getCurrent(), context->get<0>()); + auto continuation = prepareContinuation( + [](Context *context) { EXPECT_PROGRESS(3); - EXPECT_TRUE(executor.isGeneric()); - EXPECT_EQ(task, context->get<0>()); + EXPECT_TRUE(swift_task_getCurrentExecutor().isGeneric()); + EXPECT_EQ(swift_task_getCurrent(), context->get<0>()); finishTest(); - return context->resumeParent(task, executor); + return context->ResumeParent(context); }); - return swift_task_switch(task, executor, ExecutorRef::generic()); + return swift_task_switch(context, continuation, + ExecutorRef::generic()); }); - return swift_task_switch(task, executor, + return swift_task_switch(context, continuation, ExecutorRef::forDefaultActor(context->get<1>())); }); swift_task_enqueueGlobal(task0); @@ -290,25 +295,29 @@ TEST(ActorTest, actorContention) { auto task0 = createTaskStoring(JobPriority::Default, (AsyncTask*) nullptr, actor, - [](AsyncTask *task, ExecutorRef executor, Context *context) { + [](Context *context) { EXPECT_PROGRESS(1); - EXPECT_TRUE(executor.isGeneric()); + EXPECT_TRUE(swift_task_getCurrentExecutor().isGeneric()); EXPECT_EQ(nullptr, context->get<0>()); + auto task = swift_task_getCurrent(); + EXPECT_FALSE(task == nullptr); std::get<0>(context->values) = task; parkTask(task, context, - [](AsyncTask *task, ExecutorRef executor, Context *context) { + [](Context *context) { EXPECT_PROGRESS(3); + auto executor = swift_task_getCurrentExecutor(); EXPECT_FALSE(executor.isGeneric()); EXPECT_EQ(ExecutorRef::forDefaultActor(context->get<1>()), executor); + auto task = swift_task_getCurrent(); EXPECT_EQ(task, context->get<0>()); parkTask(task, context, - [](AsyncTask *task, ExecutorRef executor, Context *context) { + [](Context *context) { EXPECT_PROGRESS(4); - EXPECT_TRUE(executor.isGeneric()); - EXPECT_EQ(task, context->get<0>()); - return context->resumeParent(task, executor); + EXPECT_TRUE(swift_task_getCurrentExecutor().isGeneric()); + EXPECT_EQ(swift_task_getCurrent(), context->get<0>()); + return context->ResumeParent(context); }); swift_task_enqueue(task, ExecutorRef::generic()); }); @@ -319,21 +328,23 @@ TEST(ActorTest, actorContention) { auto task1 = createTaskStoring(JobPriority::Background, (AsyncTask*) nullptr, actor, - [](AsyncTask *task, ExecutorRef executor, Context *context) { + [](Context *context) { EXPECT_PROGRESS(2); + auto executor = swift_task_getCurrentExecutor(); EXPECT_FALSE(executor.isGeneric()); EXPECT_EQ(ExecutorRef::forDefaultActor(context->get<1>()), executor); EXPECT_EQ(nullptr, context->get<0>()); + auto task = swift_task_getCurrent(); std::get<0>(context->values) = task; parkTask(task, context, - [](AsyncTask *task, ExecutorRef executor, Context *context) { + [](Context *context) { EXPECT_PROGRESS(5); - EXPECT_TRUE(executor.isGeneric()); - EXPECT_EQ(task, context->get<0>()); + EXPECT_TRUE(swift_task_getCurrentExecutor().isGeneric()); + EXPECT_EQ(swift_task_getCurrent(), context->get<0>()); finishTest(); - return context->resumeParent(task, executor); + return context->ResumeParent(context); }); swift_task_enqueue(task, ExecutorRef::generic()); diff --git a/unittests/runtime/TaskStatus.cpp b/unittests/runtime/TaskStatus.cpp index f9aaa602e9e28..6e845fa862005 100644 --- a/unittests/runtime/TaskStatus.cpp +++ b/unittests/runtime/TaskStatus.cpp @@ -21,9 +21,7 @@ template struct ValueContext; template using InvokeFunctionRef = - llvm::function_ref *context)>; + llvm::function_ref *context)>; using BodyFunctionRef = llvm::function_ref; @@ -39,10 +37,10 @@ using undeduced = template SWIFT_CC(swiftasync) -static void simpleTaskInvokeFunction(AsyncTask *task, ExecutorRef executor, - SWIFT_ASYNC_CONTEXT AsyncContext *context) { +static void simpleTaskInvokeFunction(SWIFT_ASYNC_CONTEXT AsyncContext *context, + SWIFT_CONTEXT HeapObject *) { auto valueContext = static_cast*>(context); - valueContext->StoredInvokeFn(task, executor, valueContext); + valueContext->StoredInvokeFn(valueContext); // Destroy the stored value. valueContext->Value.T::~T(); @@ -50,7 +48,7 @@ static void simpleTaskInvokeFunction(AsyncTask *task, ExecutorRef executor, // Return to finish off the task. // In a normal situation we'd need to free the context, but here // we know we're at the top level. - valueContext->ResumeParent(task, executor, valueContext->Parent); + valueContext->ResumeParent(valueContext); } template @@ -58,9 +56,10 @@ static void withSimpleTask(JobFlags flags, T &&value, undeduced> invokeFn, BodyFunctionRef body) { auto taskAndContext = - swift_task_create_f(flags, /*parent*/ nullptr, - &simpleTaskInvokeFunction, - sizeof(ValueContext)); + swift_task_create_f(flags, + reinterpret_cast( + &simpleTaskInvokeFunction), + sizeof(ValueContext)); auto valueContext = static_cast*>(taskAndContext.InitialContext); @@ -92,13 +91,12 @@ TEST(TaskStatusTest, basicTasks) { struct Storage { int value; }; withSimpleTask(Storage{47}, - [&](AsyncTask *task, ExecutorRef executor, - ValueContext *context) { + [&](ValueContext *context) { // The task passed in should be the task we created. - EXPECT_EQ(createdTask, task); + EXPECT_EQ(createdTask, swift_task_getCurrent()); // The executor passed in should be the executor we created. - EXPECT_EQ(createdExecutor, executor); + //EXPECT_EQ(createdExecutor, executor); // We shouldn't have run yet. EXPECT_FALSE(hasRun); @@ -112,7 +110,7 @@ TEST(TaskStatusTest, basicTasks) { createdTask = task; EXPECT_FALSE(hasRun); - createdTask->runInFullyEstablishedContext(createdExecutor); + swift_job_run(task, createdExecutor); EXPECT_TRUE(hasRun); createdTask = nullptr; @@ -125,15 +123,15 @@ TEST(TaskStatusTest, basicTasks) { TEST(TaskStatusTest, cancellation_simple) { struct Storage { int value; }; withSimpleTask(Storage{47}, - [&](AsyncTask *task, ExecutorRef executor, - ValueContext *context) { + [&](ValueContext *context) { + auto task = swift_task_getCurrent(); EXPECT_FALSE(task->isCancelled()); swift_task_cancel(task); EXPECT_TRUE(task->isCancelled()); swift_task_cancel(task); EXPECT_TRUE(task->isCancelled()); }, [&](AsyncTask *task) { - task->runInFullyEstablishedContext(createFakeExecutor(1234)); + swift_job_run(task, createFakeExecutor(1234)); }); } @@ -143,8 +141,8 @@ TEST(TaskStatusTest, cancellation_simple) { TEST(TaskStatusTest, deadline) { struct Storage { int value; }; withSimpleTask(Storage{47}, - [&](AsyncTask *task, ExecutorRef executor, - ValueContext *context) { + [&](ValueContext *context) { + auto task = swift_task_getCurrent(); EXPECT_FALSE(task->isCancelled()); TaskDeadline deadlineOne = { 1234 }; @@ -157,7 +155,7 @@ TEST(TaskStatusTest, deadline) { EXPECT_EQ(NearestTaskDeadline::None, nearest.ValueKind); // Add deadline 1. Check that we haven't been cancelled yet. - result = swift_task_addStatusRecord(task, &recordOne); + result = swift_task_addStatusRecord(&recordOne); EXPECT_TRUE(result); // There should now be an active deadline. @@ -166,7 +164,7 @@ TEST(TaskStatusTest, deadline) { EXPECT_EQ(deadlineOne, nearest.Value); // Remove deadline 1. Check that we haven't been cancelled yet. - result = swift_task_removeStatusRecord(task, &recordOne); + result = swift_task_removeStatusRecord(&recordOne); EXPECT_TRUE(result); // There shouldn't be an active deadline anymore. @@ -174,9 +172,9 @@ TEST(TaskStatusTest, deadline) { EXPECT_EQ(NearestTaskDeadline::None, nearest.ValueKind); // Add deadline 1, then 2. - result = swift_task_addStatusRecord(task, &recordOne); + result = swift_task_addStatusRecord(&recordOne); EXPECT_TRUE(result); - result = swift_task_addStatusRecord(task, &recordTwo); + result = swift_task_addStatusRecord(&recordTwo); EXPECT_TRUE(result); // The nearest deadline should be deadline 1. @@ -185,13 +183,13 @@ TEST(TaskStatusTest, deadline) { EXPECT_EQ(deadlineOne, nearest.Value); // Remove the deadlines. - result = swift_task_removeStatusRecord(task, &recordTwo); + result = swift_task_removeStatusRecord(&recordTwo); EXPECT_TRUE(result); - result = swift_task_removeStatusRecord(task, &recordOne); + result = swift_task_removeStatusRecord(&recordOne); EXPECT_TRUE(result); // Add deadline 2, then 1s. - result = swift_task_addStatusRecord(task, &recordTwo); + result = swift_task_addStatusRecord(&recordTwo); EXPECT_TRUE(result); // In the middle, the nearest deadline should be deadline 2. @@ -199,7 +197,7 @@ TEST(TaskStatusTest, deadline) { EXPECT_EQ(NearestTaskDeadline::Active, nearest.ValueKind); EXPECT_EQ(deadlineTwo, nearest.Value); - result = swift_task_addStatusRecord(task, &recordOne); + result = swift_task_addStatusRecord(&recordOne); EXPECT_TRUE(result); // The nearest deadline should be deadline 1. @@ -208,41 +206,41 @@ TEST(TaskStatusTest, deadline) { EXPECT_EQ(deadlineOne, nearest.Value); // Remove the deadlines. - result = swift_task_removeStatusRecord(task, &recordOne); + result = swift_task_removeStatusRecord(&recordOne); EXPECT_TRUE(result); - result = swift_task_removeStatusRecord(task, &recordTwo); + result = swift_task_removeStatusRecord(&recordTwo); EXPECT_TRUE(result); // Do the same thing with tryAddStatus. - result = swift_task_tryAddStatusRecord(task, &recordTwo); + result = swift_task_tryAddStatusRecord(&recordTwo); EXPECT_TRUE(result); - result = swift_task_tryAddStatusRecord(task, &recordOne); + result = swift_task_tryAddStatusRecord(&recordOne); EXPECT_TRUE(result); // The nearest deadline should be deadline 1. nearest = swift_task_getNearestDeadline(task); EXPECT_EQ(NearestTaskDeadline::Active, nearest.ValueKind); EXPECT_EQ(deadlineOne, nearest.Value); - result = swift_task_removeStatusRecord(task, &recordOne); + result = swift_task_removeStatusRecord(&recordOne); EXPECT_TRUE(result); - result = swift_task_removeStatusRecord(task, &recordTwo); + result = swift_task_removeStatusRecord(&recordTwo); EXPECT_TRUE(result); // Remove out of order. - result = swift_task_addStatusRecord(task, &recordTwo); + result = swift_task_addStatusRecord(&recordTwo); EXPECT_TRUE(result); - result = swift_task_addStatusRecord(task, &recordOne); + result = swift_task_addStatusRecord(&recordOne); EXPECT_TRUE(result); // The nearest deadline should be deadline 1. nearest = swift_task_getNearestDeadline(task); EXPECT_EQ(NearestTaskDeadline::Active, nearest.ValueKind); EXPECT_EQ(deadlineOne, nearest.Value); - result = swift_task_removeStatusRecord(task, &recordTwo); + result = swift_task_removeStatusRecord(&recordTwo); EXPECT_TRUE(result); - result = swift_task_removeStatusRecord(task, &recordOne); + result = swift_task_removeStatusRecord(&recordOne); EXPECT_TRUE(result); // Add deadline 2, then cancel. - result = swift_task_addStatusRecord(task, &recordTwo); + result = swift_task_addStatusRecord(&recordTwo); EXPECT_TRUE(result); // The nearest deadline should be deadline 2. @@ -259,19 +257,19 @@ TEST(TaskStatusTest, deadline) { EXPECT_EQ(NearestTaskDeadline::AlreadyCancelled, nearest.ValueKind); // Add deadline 1. - result = swift_task_addStatusRecord(task, &recordOne); + result = swift_task_addStatusRecord(&recordOne); EXPECT_FALSE(result); nearest = swift_task_getNearestDeadline(task); EXPECT_EQ(NearestTaskDeadline::AlreadyCancelled, nearest.ValueKind); - result = swift_task_removeStatusRecord(task, &recordOne); + result = swift_task_removeStatusRecord(&recordOne); EXPECT_FALSE(result); - result = swift_task_tryAddStatusRecord(task, &recordOne); + result = swift_task_tryAddStatusRecord(&recordOne); EXPECT_FALSE(result); - result = swift_task_removeStatusRecord(task, &recordTwo); + result = swift_task_removeStatusRecord(&recordTwo); EXPECT_FALSE(result); nearest = swift_task_getNearestDeadline(task); @@ -279,6 +277,6 @@ TEST(TaskStatusTest, deadline) { EXPECT_TRUE(task->isCancelled()); }, [&](AsyncTask *task) { - task->runInFullyEstablishedContext(createFakeExecutor(1234)); + swift_job_run(task, createFakeExecutor(1234)); }); } diff --git a/utils/build-script b/utils/build-script index e39158f899f0e..d29eea08f86bc 100755 --- a/utils/build-script +++ b/utils/build-script @@ -898,8 +898,6 @@ class BuildScriptInvocation(object): product_classes = [] if self.args.build_swiftpm: product_classes.append(products.SwiftPM) - if self.args.build_swift_driver or self.args.install_swift_driver: - product_classes.append(products.SwiftDriver) if self.args.build_swiftsyntax: product_classes.append(products.SwiftSyntax) if self.args.build_skstresstester: @@ -920,6 +918,13 @@ class BuildScriptInvocation(object): product_classes.append(products.SwiftInspect) if self.args.tsan_libdispatch_test: product_classes.append(products.TSanLibDispatch) + + # Keep SwiftDriver at last. + # swift-driver's integration with the build scripts is not fully + # supported. Using swift-driver to build these products may hit + # failures. + if self.args.build_swift_driver or self.args.install_swift_driver: + product_classes.append(products.SwiftDriver) # Sanity check that all of our non-impl classes are actually # not build_script_impl products. for prod in product_classes: diff --git a/utils/build_swift/build_swift/defaults.py b/utils/build_swift/build_swift/defaults.py index 24e4844a05095..f39163fd33fd8 100644 --- a/utils/build_swift/build_swift/defaults.py +++ b/utils/build_swift/build_swift/defaults.py @@ -49,7 +49,7 @@ CMAKE_GENERATOR = 'Ninja' COMPILER_VENDOR = 'none' -SWIFT_USER_VISIBLE_VERSION = Version('5.4') +SWIFT_USER_VISIBLE_VERSION = Version('5.5') CLANG_USER_VISIBLE_VERSION = Version('10.0.0') SWIFT_ANALYZE_CODE_COVERAGE = 'false' diff --git a/utils/gyb_syntax_support/Token.py b/utils/gyb_syntax_support/Token.py index 6a2eb85ac5318..6738c5a3aea59 100644 --- a/utils/gyb_syntax_support/Token.py +++ b/utils/gyb_syntax_support/Token.py @@ -9,7 +9,8 @@ class Token(object): """ def __init__(self, name, kind, serialization_code, unprefixed_kind=None, - text=None, classification='None', is_keyword=False): + text=None, classification='None', is_keyword=False, + requires_leading_space=False, requires_trailing_space=False): self.name = name self.kind = kind if unprefixed_kind is None: @@ -20,6 +21,8 @@ def __init__(self, name, kind, serialization_code, unprefixed_kind=None, self.text = text or "" self.classification = classification_by_name(classification) self.is_keyword = is_keyword + self.requires_leading_space = requires_leading_space + self.requires_trailing_space = requires_trailing_space def swift_kind(self): name = lowercase_first_word(self.name) @@ -37,7 +40,8 @@ def __init__(self, name, text, serialization_code, classification='Keyword'): Token.__init__(self, name, 'kw_' + text, serialization_code, unprefixed_kind=text, text=text, - classification=classification, is_keyword=True) + classification=classification, is_keyword=True, + requires_trailing_space=True) def macro_name(self): return "KEYWORD" @@ -78,7 +82,8 @@ def __init__(self, name, kind, text, serialization_code, classification='Keyword'): Token.__init__(self, name, 'pound_' + kind, serialization_code, unprefixed_kind=kind, text=text, - classification=classification, is_keyword=True) + classification=classification, is_keyword=True, + requires_trailing_space=True) def macro_name(self): return "POUND_KEYWORD" @@ -215,24 +220,31 @@ def macro_name(self): serialization_code=92), Punctuator('RightSquareBracket', 'r_square', text=']', serialization_code=93), - Punctuator('LeftAngle', 'l_angle', text='<', serialization_code=94), - Punctuator('RightAngle', 'r_angle', text='>', serialization_code=95), + Punctuator('LeftAngle', 'l_angle', text='<', requires_leading_space=True, + requires_trailing_space=True, serialization_code=94), + Punctuator('RightAngle', 'r_angle', text='>', requires_leading_space=True, + requires_trailing_space=True, serialization_code=95), Punctuator('Period', 'period', text='.', serialization_code=85), Punctuator('PrefixPeriod', 'period_prefix', text='.', serialization_code=87), - Punctuator('Comma', 'comma', text=',', serialization_code=84), + Punctuator('Comma', 'comma', text=',', requires_trailing_space=True, + serialization_code=84), Punctuator('Ellipsis', 'ellipsis', text='...', serialization_code=118), - Punctuator('Colon', 'colon', text=':', serialization_code=82), + Punctuator('Colon', 'colon', text=':', requires_trailing_space=True, + serialization_code=82), Punctuator('Semicolon', 'semi', text=';', serialization_code=83), - Punctuator('Equal', 'equal', text='=', serialization_code=86), + Punctuator('Equal', 'equal', text='=', requires_leading_space=True, + requires_trailing_space=True, serialization_code=86), Punctuator('AtSign', 'at_sign', text='@', classification='Attribute', serialization_code=80), Punctuator('Pound', 'pound', text='#', serialization_code=81), Punctuator('PrefixAmpersand', 'amp_prefix', text='&', + requires_leading_space=True, requires_trailing_space=True, serialization_code=96), - Punctuator('Arrow', 'arrow', text='->', serialization_code=78), + Punctuator('Arrow', 'arrow', text='->', requires_trailing_space=True, + serialization_code=78), Punctuator('Backtick', 'backtick', text='`', serialization_code=79), diff --git a/validation-test/Sema/SwiftUI/rdar75367157.swift b/validation-test/Sema/SwiftUI/rdar75367157.swift new file mode 100644 index 0000000000000..9d19ba229b3cf --- /dev/null +++ b/validation-test/Sema/SwiftUI/rdar75367157.swift @@ -0,0 +1,30 @@ +// RUN: %target-typecheck-verify-swift -target x86_64-apple-macosx10.15 -swift-version 5 +// REQUIRES: objc_interop +// REQUIRES: OS=macosx + +import SwiftUI + +enum E : String { + case a + case b + + var description: String { get { "" } } +} + +struct S : View { + var test: E = .a + + func check(_: String) -> Bool {} + + var body: some View { + List { + if test != E.b.description { // expected-error {{cannot convert value of type 'E' to expected argument type 'String'}} {{14-14=.rawValue}} + EmptyView() + } + + if (check(self.test)) { // expected-error {{cannot convert value of type 'E' to expected argument type 'String'}} {{26-26=.rawValue}} + Spacer() + } + } + } +} diff --git a/validation-test/compiler_crashers_2/sr13849.swift b/validation-test/compiler_crashers_2/sr13849.swift new file mode 100644 index 0000000000000..9ef1f3d48cbc2 --- /dev/null +++ b/validation-test/compiler_crashers_2/sr13849.swift @@ -0,0 +1,13 @@ +// RUN: not --crash %target-swift-frontend -emit-ir %s + +public protocol Prot { + associatedtype T +} + +public class C where P.T: Hashable { +} + +public class Spam where P.T == Int { + public func m(_ f: (C

) -> C

) { + } +} diff --git a/validation-test/compiler_crashers_2_fixed/rdar65297215.swift b/validation-test/compiler_crashers_2_fixed/rdar65297215.swift new file mode 100644 index 0000000000000..0328239c1ac50 --- /dev/null +++ b/validation-test/compiler_crashers_2_fixed/rdar65297215.swift @@ -0,0 +1,23 @@ +// RUN: %target-swift-frontend -emit-ir %s + +public protocol LinkedListNode: AnyObject { + associatedtype T +} + +public class LinkedList where N.T: Hashable { + public typealias T = N.T +} + +public struct LinkedListIterator: IteratorProtocol { + public mutating func next() -> N.T? { + return nil + } +} + +extension LinkedList: Sequence { + public typealias Element = T + public typealias Iterator = LinkedListIterator + public __consuming func makeIterator() -> Iterator { + fatalError() + } +} diff --git a/validation-test/compiler_crashers_2_fixed/rdar69073431.swift b/validation-test/compiler_crashers_2_fixed/rdar69073431.swift new file mode 100644 index 0000000000000..8db1bf480d644 --- /dev/null +++ b/validation-test/compiler_crashers_2_fixed/rdar69073431.swift @@ -0,0 +1,11 @@ +// RUN: %target-swift-frontend -emit-ir %s +// REQUIRES: OS=macosx + +import Combine + +@available(macOS 10.15, *) +extension Publishers.Share { + func foo() where Upstream == Publishers.FlatMap, B.Output == UInt8 { + + } +} diff --git a/validation-test/stdlib/FixedPoint.swift.gyb b/validation-test/stdlib/FixedPoint.swift.gyb index 0d8bdfa4d5965..cdd478e576bdb 100644 --- a/validation-test/stdlib/FixedPoint.swift.gyb +++ b/validation-test/stdlib/FixedPoint.swift.gyb @@ -1,6 +1,11 @@ // RUN: %target-run-stdlib-swiftgyb // REQUIRES: executable_test +// FIXME: [SR-14363] +// FixedPoint.swift.gyb slowed down with -Onone copy propagation +// We should be able to move this out of long_test once fixed. +// REQUIRES: long_test + import StdlibUnittest diff --git a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug32_ToInt.swift b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug32_ToInt.swift index 2e714d800c89e..bd073f6eed161 100644 --- a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug32_ToInt.swift +++ b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug32_ToInt.swift @@ -14,1498 +14,612 @@ import StdlibUnittest -let FixedPointConversion_Debug32_ToInt = TestSuite("FixedPointConversion_Debug32_ToInt") +let FixedPointConversion_Debug32_ToInt = TestSuite( + "FixedPointConversion_Debug32_ToInt" +) //===----------------------------------------------------------------------===// -// MARK: UInt8: (0)...(255) +// MARK: UInt8: (+0)...(+255) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt.test("FromUInt8(0)_NeverTraps") { - let input = getUInt8(0) - let actual = Int(input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToInt +.test("FromUInt8_NeverTraps") +.forEach(in: [ + (getInt(+0), getUInt8(+0)), + (getInt(+255), getUInt8(+255)), +]) { + expectEqual($0.0, Int($0.1)) } -FixedPointConversion_Debug32_ToInt.test("FromUInt8(0)_NeverFails") { - let input = getUInt8(0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromUInt8(255)_NeverTraps") { - let input = getUInt8(255) - let actual = Int(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromUInt8(255)_NeverFails") { - let input = getUInt8(255) - let actual = Int(exactly: input) - expectEqual(255, actual) +FixedPointConversion_Debug32_ToInt +.test("FromUInt8_NeverFails") +.forEach(in: [ + (getInt(+0), getUInt8(+0)), + (getInt(+255), getUInt8(+255)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int8: (-128)...(127) +// MARK: Int8: (-128)...(+127) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt.test("FromInt8(-128)_NeverTraps") { - let input = getInt8(-128) - let actual = Int(input) - expectEqual(-128, actual) +FixedPointConversion_Debug32_ToInt +.test("FromInt8_NeverTraps") +.forEach(in: [ + (getInt(-128), getInt8(-128)), + (getInt(+0), getInt8(+0)), + (getInt(+127), getInt8(+127)), +]) { + expectEqual($0.0, Int($0.1)) } -FixedPointConversion_Debug32_ToInt.test("FromInt8(-128)_NeverFails") { - let input = getInt8(-128) - let actual = Int(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromInt8(0)_NeverTraps") { - let input = getInt8(0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromInt8(0)_NeverFails") { - let input = getInt8(0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromInt8(127)_NeverTraps") { - let input = getInt8(127) - let actual = Int(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromInt8(127)_NeverFails") { - let input = getInt8(127) - let actual = Int(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Debug32_ToInt +.test("FromInt8_NeverFails") +.forEach(in: [ + (getInt(-128), getInt8(-128)), + (getInt(+0), getInt8(+0)), + (getInt(+127), getInt8(+127)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt16: (0)...(65535) +// MARK: UInt16: (+0)...(+65535) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt.test("FromUInt16(0)_NeverTraps") { - let input = getUInt16(0) - let actual = Int(input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToInt +.test("FromUInt16_NeverTraps") +.forEach(in: [ + (getInt(+0), getUInt16(+0)), + (getInt(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, Int($0.1)) } -FixedPointConversion_Debug32_ToInt.test("FromUInt16(0)_NeverFails") { - let input = getUInt16(0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromUInt16(65535)_NeverTraps") { - let input = getUInt16(65535) - let actual = Int(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromUInt16(65535)_NeverFails") { - let input = getUInt16(65535) - let actual = Int(exactly: input) - expectEqual(65535, actual) +FixedPointConversion_Debug32_ToInt +.test("FromUInt16_NeverFails") +.forEach(in: [ + (getInt(+0), getUInt16(+0)), + (getInt(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int16: (-32768)...(32767) +// MARK: Int16: (-32768)...(+32767) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt.test("FromInt16(-32768)_NeverTraps") { - let input = getInt16(-32768) - let actual = Int(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromInt16(-32768)_NeverFails") { - let input = getInt16(-32768) - let actual = Int(exactly: input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromInt16(0)_NeverTraps") { - let input = getInt16(0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromInt16(0)_NeverFails") { - let input = getInt16(0) - let actual = Int(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToInt +.test("FromInt16_NeverTraps") +.forEach(in: [ + (getInt(-32768), getInt16(-32768)), + (getInt(+0), getInt16(+0)), + (getInt(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, Int($0.1)) } -FixedPointConversion_Debug32_ToInt.test("FromInt16(32767)_NeverTraps") { - let input = getInt16(32767) - let actual = Int(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromInt16(32767)_NeverFails") { - let input = getInt16(32767) - let actual = Int(exactly: input) - expectEqual(32767, actual) +FixedPointConversion_Debug32_ToInt +.test("FromInt16_NeverFails") +.forEach(in: [ + (getInt(-32768), getInt16(-32768)), + (getInt(+0), getInt16(+0)), + (getInt(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt32: (0)...(4294967295) +// MARK: UInt32: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt.test("FromUInt32(0)_NeverTraps") { - let input = getUInt32(0) - let actual = Int(input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToInt +.test("FromUInt32_NeverTraps") +.forEach(in: [ + (getInt(+0), getUInt32(+0)), + (getInt(+2147483647), getUInt32(+2147483647)), +]) { + expectEqual($0.0, Int($0.1)) } -FixedPointConversion_Debug32_ToInt.test("FromUInt32(0)_NeverFails") { - let input = getUInt32(0) - let actual = Int(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToInt +.test("FromUInt32_NeverFails") +.forEach(in: [ + (getInt(+0), getUInt32(+0)), + (getInt(+2147483647), getUInt32(+2147483647)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) } -FixedPointConversion_Debug32_ToInt.test("FromUInt32(2147483647)_NeverTraps") { - let input = getUInt32(2147483647) - let actual = Int(input) - expectEqual(2147483647, actual) +FixedPointConversion_Debug32_ToInt +.test("FromUInt32_AlwaysTraps") +.forEach(in: [ + getUInt32(+2147483648), + getUInt32(+4294967295), +]) { + expectCrashLater() + _blackHole(Int($0)) } -FixedPointConversion_Debug32_ToInt.test("FromUInt32(2147483647)_NeverFails") { - let input = getUInt32(2147483647) - let actual = Int(exactly: input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromUInt32(2147483648)_AlwaysTraps") { - let input = getUInt32(2147483648) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromUInt32(2147483648)_AlwaysFails") { - let input = getUInt32(2147483648) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromUInt32(4294967295)_AlwaysTraps") { - let input = getUInt32(4294967295) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromUInt32(4294967295)_AlwaysFails") { - let input = getUInt32(4294967295) - let actual = Int(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt +.test("FromUInt32_AlwaysFails") +.forEach(in: [ + getUInt32(+2147483648), + getUInt32(+4294967295), +]) { + expectNil(Int(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int32: (-2147483648)...(2147483647) +// MARK: Int32: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt.test("FromInt32(-2147483648)_NeverTraps") { - let input = getInt32(-2147483648) - let actual = Int(input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromInt32(-2147483648)_NeverFails") { - let input = getInt32(-2147483648) - let actual = Int(exactly: input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromInt32(0)_NeverTraps") { - let input = getInt32(0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromInt32(0)_NeverFails") { - let input = getInt32(0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromInt32(2147483647)_NeverTraps") { - let input = getInt32(2147483647) - let actual = Int(input) - expectEqual(2147483647, actual) +FixedPointConversion_Debug32_ToInt +.test("FromInt32_NeverTraps") +.forEach(in: [ + (getInt(-2147483648), getInt32(-2147483648)), + (getInt(+0), getInt32(+0)), + (getInt(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, Int($0.1)) } -FixedPointConversion_Debug32_ToInt.test("FromInt32(2147483647)_NeverFails") { - let input = getInt32(2147483647) - let actual = Int(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Debug32_ToInt +.test("FromInt32_NeverFails") +.forEach(in: [ + (getInt(-2147483648), getInt32(-2147483648)), + (getInt(+0), getInt32(+0)), + (getInt(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt64: (0)...(18446744073709551615) +// MARK: UInt64: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt.test("FromUInt64(0)_NeverTraps") { - let input = getUInt64(0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromUInt64(0)_NeverFails") { - let input = getUInt64(0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromUInt64(2147483647)_NeverTraps") { - let input = getUInt64(2147483647) - let actual = Int(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromUInt64(2147483647)_NeverFails") { - let input = getUInt64(2147483647) - let actual = Int(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Debug32_ToInt +.test("FromUInt64_NeverTraps") +.forEach(in: [ + (getInt(+0), getUInt64(+0)), + (getInt(+2147483647), getUInt64(+2147483647)), +]) { + expectEqual($0.0, Int($0.1)) } -FixedPointConversion_Debug32_ToInt.test("FromUInt64(2147483648)_AlwaysTraps") { - let input = getUInt64(2147483648) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } +FixedPointConversion_Debug32_ToInt +.test("FromUInt64_NeverFails") +.forEach(in: [ + (getInt(+0), getUInt64(+0)), + (getInt(+2147483647), getUInt64(+2147483647)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) } -FixedPointConversion_Debug32_ToInt.test("FromUInt64(2147483648)_AlwaysFails") { - let input = getUInt64(2147483648) - let actual = Int(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt +.test("FromUInt64_AlwaysTraps") +.forEach(in: [ + getUInt64(+2147483648), + getUInt64(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(Int($0)) } -FixedPointConversion_Debug32_ToInt.test("FromUInt64(18446744073709551615)_AlwaysTraps") { - let input = getUInt64(18446744073709551615) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromUInt64(18446744073709551615)_AlwaysFails") { - let input = getUInt64(18446744073709551615) - let actual = Int(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt +.test("FromUInt64_AlwaysFails") +.forEach(in: [ + getUInt64(+2147483648), + getUInt64(+18446744073709551615), +]) { + expectNil(Int(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int64: (-9223372036854775808)...(9223372036854775807) +// MARK: Int64: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt.test("FromInt64(-9223372036854775808)_AlwaysTraps") { - let input = getInt64(-9223372036854775808) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromInt64(-9223372036854775808)_AlwaysFails") { - let input = getInt64(-9223372036854775808) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromInt64(-2147483649)_AlwaysTraps") { - let input = getInt64(-2147483649) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromInt64(-2147483649)_AlwaysFails") { - let input = getInt64(-2147483649) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromInt64(-2147483648)_NeverTraps") { - let input = getInt64(-2147483648) - let actual = Int(input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromInt64(-2147483648)_NeverFails") { - let input = getInt64(-2147483648) - let actual = Int(exactly: input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromInt64(0)_NeverTraps") { - let input = getInt64(0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromInt64(0)_NeverFails") { - let input = getInt64(0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromInt64(2147483647)_NeverTraps") { - let input = getInt64(2147483647) - let actual = Int(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromInt64(2147483647)_NeverFails") { - let input = getInt64(2147483647) - let actual = Int(exactly: input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromInt64(2147483648)_AlwaysTraps") { - let input = getInt64(2147483648) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromInt64(2147483648)_AlwaysFails") { - let input = getInt64(2147483648) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromInt64(9223372036854775807)_AlwaysTraps") { - let input = getInt64(9223372036854775807) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromInt64(9223372036854775807)_AlwaysFails") { - let input = getInt64(9223372036854775807) - let actual = Int(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt +.test("FromInt64_NeverTraps") +.forEach(in: [ + (getInt(-2147483648), getInt64(-2147483648)), + (getInt(+0), getInt64(+0)), + (getInt(+2147483647), getInt64(+2147483647)), +]) { + expectEqual($0.0, Int($0.1)) +} + +FixedPointConversion_Debug32_ToInt +.test("FromInt64_NeverFails") +.forEach(in: [ + (getInt(-2147483648), getInt64(-2147483648)), + (getInt(+0), getInt64(+0)), + (getInt(+2147483647), getInt64(+2147483647)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToInt +.test("FromInt64_AlwaysTraps") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-2147483649), + getInt64(+2147483648), + getInt64(+9223372036854775807), +]) { + expectCrashLater() + _blackHole(Int($0)) +} + +FixedPointConversion_Debug32_ToInt +.test("FromInt64_AlwaysFails") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-2147483649), + getInt64(+2147483648), + getInt64(+9223372036854775807), +]) { + expectNil(Int(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt: (0)...(4294967295) +// MARK: UInt: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt.test("FromUInt(0)_NeverTraps") { - let input = getUInt(0) - let actual = Int(input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToInt +.test("FromUInt_NeverTraps") +.forEach(in: [ + (getInt(+0), getUInt(+0)), + (getInt(+2147483647), getUInt(+2147483647)), +]) { + expectEqual($0.0, Int($0.1)) } -FixedPointConversion_Debug32_ToInt.test("FromUInt(0)_NeverFails") { - let input = getUInt(0) - let actual = Int(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToInt +.test("FromUInt_NeverFails") +.forEach(in: [ + (getInt(+0), getUInt(+0)), + (getInt(+2147483647), getUInt(+2147483647)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) } -FixedPointConversion_Debug32_ToInt.test("FromUInt(2147483647)_NeverTraps") { - let input = getUInt(2147483647) - let actual = Int(input) - expectEqual(2147483647, actual) +FixedPointConversion_Debug32_ToInt +.test("FromUInt_AlwaysTraps") +.forEach(in: [ + getUInt(+2147483648), + getUInt(+4294967295), +]) { + expectCrashLater() + _blackHole(Int($0)) } -FixedPointConversion_Debug32_ToInt.test("FromUInt(2147483647)_NeverFails") { - let input = getUInt(2147483647) - let actual = Int(exactly: input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromUInt(2147483648)_AlwaysTraps") { - let input = getUInt(2147483648) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromUInt(2147483648)_AlwaysFails") { - let input = getUInt(2147483648) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromUInt(4294967295)_AlwaysTraps") { - let input = getUInt(4294967295) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromUInt(4294967295)_AlwaysFails") { - let input = getUInt(4294967295) - let actual = Int(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt +.test("FromUInt_AlwaysFails") +.forEach(in: [ + getUInt(+2147483648), + getUInt(+4294967295), +]) { + expectNil(Int(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int: (-2147483648)...(2147483647) +// MARK: Int: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt.test("FromInt(-2147483648)_NeverTraps") { - let input = getInt(-2147483648) - let actual = Int(input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromInt(-2147483648)_NeverFails") { - let input = getInt(-2147483648) - let actual = Int(exactly: input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromInt(0)_NeverTraps") { - let input = getInt(0) - let actual = Int(input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToInt +.test("FromInt_NeverTraps") +.forEach(in: [ + (getInt(-2147483648), getInt(-2147483648)), + (getInt(+0), getInt(+0)), + (getInt(+2147483647), getInt(+2147483647)), +]) { + expectEqual($0.0, Int($0.1)) } -FixedPointConversion_Debug32_ToInt.test("FromInt(0)_NeverFails") { - let input = getInt(0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromInt(2147483647)_NeverTraps") { - let input = getInt(2147483647) - let actual = Int(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromInt(2147483647)_NeverFails") { - let input = getInt(2147483647) - let actual = Int(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Debug32_ToInt +.test("FromInt_NeverFails") +.forEach(in: [ + (getInt(-2147483648), getInt(-2147483648)), + (getInt(+0), getInt(+0)), + (getInt(+2147483647), getInt(+2147483647)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Float16: (-2047)...(2047) +// MARK: Float16: (-2047)...(+2047) //===----------------------------------------------------------------------===// #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -FixedPointConversion_Debug32_ToInt.test("FromFloat16(-2047)_NeverTraps") { - let input = getFloat16(-2047) - let actual = Int(input) - expectEqual(-2047, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat16(-2047)_NeverFails") { - let input = getFloat16(-2047) - let actual = Int(exactly: input) - expectEqual(-2047, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat16(-128.5)_NeverTraps") { - let input = getFloat16(-128.5) - let actual = Int(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat16(-128.5)_AlwaysFails") { - let input = getFloat16(-128.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat16(-0.5)_NeverTraps") { - let input = getFloat16(-0.5) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat16(-0.5)_AlwaysFails") { - let input = getFloat16(-0.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat16(-0.0)_NeverTraps") { - let input = getFloat16(-0.0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat16(-0.0)_NeverFails") { - let input = getFloat16(-0.0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat16(0.0)_NeverTraps") { - let input = getFloat16(0.0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat16(0.0)_NeverFails") { - let input = getFloat16(0.0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat16(0.5)_NeverTraps") { - let input = getFloat16(0.5) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat16(0.5)_AlwaysFails") { - let input = getFloat16(0.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat16(127.5)_NeverTraps") { - let input = getFloat16(127.5) - let actual = Int(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat16(127.5)_AlwaysFails") { - let input = getFloat16(127.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat16(255.5)_NeverTraps") { - let input = getFloat16(255.5) - let actual = Int(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat16(255.5)_AlwaysFails") { - let input = getFloat16(255.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat16(2047)_NeverTraps") { - let input = getFloat16(2047) - let actual = Int(input) - expectEqual(2047, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat16(2047)_NeverFails") { - let input = getFloat16(2047) - let actual = Int(exactly: input) - expectEqual(2047, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat16(-.infinity)_AlwaysTraps") { - let input = getFloat16(-.infinity) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat16(-.infinity)_AlwaysFails") { - let input = getFloat16(-.infinity) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat16(+.infinity)_AlwaysTraps") { - let input = getFloat16(+.infinity) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat16(+.infinity)_AlwaysFails") { - let input = getFloat16(+.infinity) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat16(-.nan)_AlwaysTraps") { - let input = getFloat16(-.nan) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat16(-.nan)_AlwaysFails") { - let input = getFloat16(-.nan) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat16(+.nan)_AlwaysTraps") { - let input = getFloat16(+.nan) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat16(+.nan)_AlwaysFails") { - let input = getFloat16(+.nan) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat16(-.signalingNaN)_AlwaysTraps") { - let input = getFloat16(-.signalingNaN) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat16(-.signalingNaN)_AlwaysFails") { - let input = getFloat16(-.signalingNaN) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat16(+.signalingNaN)_AlwaysTraps") { - let input = getFloat16(+.signalingNaN) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat16(+.signalingNaN)_AlwaysFails") { - let input = getFloat16(+.signalingNaN) - let actual = Int(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt +.test("FromFloat16_NeverTraps") +.forEach(in: [ + (getInt(-2047), getFloat16(-2047)), + (getInt(-128), getFloat16(-128.5)), + (getInt(+0), getFloat16(-0.5)), + (getInt(+0), getFloat16(+0)), + (getInt(+0), getFloat16(-0)), + (getInt(+0), getFloat16(+0.5)), + (getInt(+127), getFloat16(+127.5)), + (getInt(+255), getFloat16(+255.5)), + (getInt(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, Int($0.1)) +} + +FixedPointConversion_Debug32_ToInt +.test("FromFloat16_NeverFails") +.forEach(in: [ + (getInt(-2047), getFloat16(-2047)), + (getInt(+0), getFloat16(+0)), + (getInt(+0), getFloat16(-0)), + (getInt(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToInt +.test("FromFloat16_AlwaysTraps") +.forEach(in: [ + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int($0)) +} + +FixedPointConversion_Debug32_ToInt +.test("FromFloat16_AlwaysFails") +.forEach(in: [ + getFloat16(-128.5), + getFloat16(-0.5), + getFloat16(+0.5), + getFloat16(+127.5), + getFloat16(+255.5), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectNil(Int(exactly: $0)) } } #endif // Float16 //===----------------------------------------------------------------------===// -// MARK: Float32: (-16777215)...(16777215) +// MARK: Float32: (-16777215)...(+16777215) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt.test("FromFloat32(-16777215)_NeverTraps") { - let input = getFloat32(-16777215) - let actual = Int(input) - expectEqual(-16777215, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat32(-16777215)_NeverFails") { - let input = getFloat32(-16777215) - let actual = Int(exactly: input) - expectEqual(-16777215, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat32(-32768.5)_NeverTraps") { - let input = getFloat32(-32768.5) - let actual = Int(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat32(-32768.5)_AlwaysFails") { - let input = getFloat32(-32768.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat32(-128.5)_NeverTraps") { - let input = getFloat32(-128.5) - let actual = Int(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat32(-128.5)_AlwaysFails") { - let input = getFloat32(-128.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat32(-0.5)_NeverTraps") { - let input = getFloat32(-0.5) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat32(-0.5)_AlwaysFails") { - let input = getFloat32(-0.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat32(-0.0)_NeverTraps") { - let input = getFloat32(-0.0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat32(-0.0)_NeverFails") { - let input = getFloat32(-0.0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat32(0.0)_NeverTraps") { - let input = getFloat32(0.0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat32(0.0)_NeverFails") { - let input = getFloat32(0.0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat32(0.5)_NeverTraps") { - let input = getFloat32(0.5) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat32(0.5)_AlwaysFails") { - let input = getFloat32(0.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat32(127.5)_NeverTraps") { - let input = getFloat32(127.5) - let actual = Int(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat32(127.5)_AlwaysFails") { - let input = getFloat32(127.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat32(255.5)_NeverTraps") { - let input = getFloat32(255.5) - let actual = Int(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat32(255.5)_AlwaysFails") { - let input = getFloat32(255.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat32(32767.5)_NeverTraps") { - let input = getFloat32(32767.5) - let actual = Int(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat32(32767.5)_AlwaysFails") { - let input = getFloat32(32767.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat32(65535.5)_NeverTraps") { - let input = getFloat32(65535.5) - let actual = Int(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat32(65535.5)_AlwaysFails") { - let input = getFloat32(65535.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat32(16777215)_NeverTraps") { - let input = getFloat32(16777215) - let actual = Int(input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat32(16777215)_NeverFails") { - let input = getFloat32(16777215) - let actual = Int(exactly: input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat32(-.infinity)_AlwaysTraps") { - let input = getFloat32(-.infinity) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat32(-.infinity)_AlwaysFails") { - let input = getFloat32(-.infinity) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat32(+.infinity)_AlwaysTraps") { - let input = getFloat32(+.infinity) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat32(+.infinity)_AlwaysFails") { - let input = getFloat32(+.infinity) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat32(-.nan)_AlwaysTraps") { - let input = getFloat32(-.nan) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat32(-.nan)_AlwaysFails") { - let input = getFloat32(-.nan) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat32(+.nan)_AlwaysTraps") { - let input = getFloat32(+.nan) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat32(+.nan)_AlwaysFails") { - let input = getFloat32(+.nan) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat32(-.signalingNaN)_AlwaysTraps") { - let input = getFloat32(-.signalingNaN) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat32(-.signalingNaN)_AlwaysFails") { - let input = getFloat32(-.signalingNaN) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat32(+.signalingNaN)_AlwaysTraps") { - let input = getFloat32(+.signalingNaN) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat32(+.signalingNaN)_AlwaysFails") { - let input = getFloat32(+.signalingNaN) - let actual = Int(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt +.test("FromFloat32_NeverTraps") +.forEach(in: [ + (getInt(-16777215), getFloat32(-16777215)), + (getInt(-32768), getFloat32(-32768.5)), + (getInt(-128), getFloat32(-128.5)), + (getInt(+0), getFloat32(-0.5)), + (getInt(+0), getFloat32(+0)), + (getInt(+0), getFloat32(-0)), + (getInt(+0), getFloat32(+0.5)), + (getInt(+127), getFloat32(+127.5)), + (getInt(+255), getFloat32(+255.5)), + (getInt(+32767), getFloat32(+32767.5)), + (getInt(+65535), getFloat32(+65535.5)), + (getInt(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, Int($0.1)) +} + +FixedPointConversion_Debug32_ToInt +.test("FromFloat32_NeverFails") +.forEach(in: [ + (getInt(-16777215), getFloat32(-16777215)), + (getInt(+0), getFloat32(+0)), + (getInt(+0), getFloat32(-0)), + (getInt(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToInt +.test("FromFloat32_AlwaysTraps") +.forEach(in: [ + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int($0)) +} + +FixedPointConversion_Debug32_ToInt +.test("FromFloat32_AlwaysFails") +.forEach(in: [ + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-0.5), + getFloat32(+0.5), + getFloat32(+127.5), + getFloat32(+255.5), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectNil(Int(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float64: (-9007199254740991)...(9007199254740991) +// MARK: Float64: (-9007199254740991)...(+9007199254740991) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt.test("FromFloat64(-9007199254740991)_AlwaysTraps") { - let input = getFloat64(-9007199254740991) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(-9007199254740991)_AlwaysFails") { - let input = getFloat64(-9007199254740991) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(-2147483649)_AlwaysTraps") { - let input = getFloat64(-2147483649) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(-2147483649)_AlwaysFails") { - let input = getFloat64(-2147483649) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(-2147483648)_NeverTraps") { - let input = getFloat64(-2147483648) - let actual = Int(input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(-2147483648)_NeverFails") { - let input = getFloat64(-2147483648) - let actual = Int(exactly: input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(-32768.5)_NeverTraps") { - let input = getFloat64(-32768.5) - let actual = Int(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(-32768.5)_AlwaysFails") { - let input = getFloat64(-32768.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(-128.5)_NeverTraps") { - let input = getFloat64(-128.5) - let actual = Int(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(-128.5)_AlwaysFails") { - let input = getFloat64(-128.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(-0.5)_NeverTraps") { - let input = getFloat64(-0.5) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(-0.5)_AlwaysFails") { - let input = getFloat64(-0.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(-0.0)_NeverTraps") { - let input = getFloat64(-0.0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(-0.0)_NeverFails") { - let input = getFloat64(-0.0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(0.0)_NeverTraps") { - let input = getFloat64(0.0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(0.0)_NeverFails") { - let input = getFloat64(0.0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(0.5)_NeverTraps") { - let input = getFloat64(0.5) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(0.5)_AlwaysFails") { - let input = getFloat64(0.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(127.5)_NeverTraps") { - let input = getFloat64(127.5) - let actual = Int(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(127.5)_AlwaysFails") { - let input = getFloat64(127.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(255.5)_NeverTraps") { - let input = getFloat64(255.5) - let actual = Int(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(255.5)_AlwaysFails") { - let input = getFloat64(255.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(32767.5)_NeverTraps") { - let input = getFloat64(32767.5) - let actual = Int(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(32767.5)_AlwaysFails") { - let input = getFloat64(32767.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(65535.5)_NeverTraps") { - let input = getFloat64(65535.5) - let actual = Int(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(65535.5)_AlwaysFails") { - let input = getFloat64(65535.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(2147483647)_NeverTraps") { - let input = getFloat64(2147483647) - let actual = Int(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(2147483647)_NeverFails") { - let input = getFloat64(2147483647) - let actual = Int(exactly: input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(2147483648)_AlwaysTraps") { - let input = getFloat64(2147483648) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(2147483648)_AlwaysFails") { - let input = getFloat64(2147483648) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(9007199254740991)_AlwaysTraps") { - let input = getFloat64(9007199254740991) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(9007199254740991)_AlwaysFails") { - let input = getFloat64(9007199254740991) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(-.infinity)_AlwaysTraps") { - let input = getFloat64(-.infinity) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(-.infinity)_AlwaysFails") { - let input = getFloat64(-.infinity) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(+.infinity)_AlwaysTraps") { - let input = getFloat64(+.infinity) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(+.infinity)_AlwaysFails") { - let input = getFloat64(+.infinity) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(-.nan)_AlwaysTraps") { - let input = getFloat64(-.nan) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(-.nan)_AlwaysFails") { - let input = getFloat64(-.nan) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(+.nan)_AlwaysTraps") { - let input = getFloat64(+.nan) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(+.nan)_AlwaysFails") { - let input = getFloat64(+.nan) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(-.signalingNaN)_AlwaysTraps") { - let input = getFloat64(-.signalingNaN) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(-.signalingNaN)_AlwaysFails") { - let input = getFloat64(-.signalingNaN) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(+.signalingNaN)_AlwaysTraps") { - let input = getFloat64(+.signalingNaN) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat64(+.signalingNaN)_AlwaysFails") { - let input = getFloat64(+.signalingNaN) - let actual = Int(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt +.test("FromFloat64_NeverTraps") +.forEach(in: [ + (getInt(-2147483648), getFloat64(-2147483648)), + (getInt(-32768), getFloat64(-32768.5)), + (getInt(-128), getFloat64(-128.5)), + (getInt(+0), getFloat64(-0.5)), + (getInt(+0), getFloat64(-0)), + (getInt(+0), getFloat64(+0)), + (getInt(+0), getFloat64(+0.5)), + (getInt(+127), getFloat64(+127.5)), + (getInt(+255), getFloat64(+255.5)), + (getInt(+32767), getFloat64(+32767.5)), + (getInt(+65535), getFloat64(+65535.5)), + (getInt(+2147483647), getFloat64(+2147483647)), +]) { + expectEqual($0.0, Int($0.1)) +} + +FixedPointConversion_Debug32_ToInt +.test("FromFloat64_NeverFails") +.forEach(in: [ + (getInt(-2147483648), getFloat64(-2147483648)), + (getInt(+0), getFloat64(-0)), + (getInt(+0), getFloat64(+0)), + (getInt(+2147483647), getFloat64(+2147483647)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToInt +.test("FromFloat64_AlwaysTraps") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-2147483649), + getFloat64(+2147483648), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int($0)) +} + +FixedPointConversion_Debug32_ToInt +.test("FromFloat64_AlwaysFails") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-2147483649), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-0.5), + getFloat64(+0.5), + getFloat64(+127.5), + getFloat64(+255.5), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(+2147483648), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectNil(Int(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float80: (-18446744073709551615)...(18446744073709551615) +// MARK: Float80: (-18446744073709551615)...(+18446744073709551615) //===----------------------------------------------------------------------===// #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) -FixedPointConversion_Debug32_ToInt.test("FromFloat80(-18446744073709551615)_AlwaysTraps") { - let input = getFloat80(-18446744073709551615) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(-18446744073709551615)_AlwaysFails") { - let input = getFloat80(-18446744073709551615) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(-2147483649)_AlwaysTraps") { - let input = getFloat80(-2147483649) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(-2147483649)_AlwaysFails") { - let input = getFloat80(-2147483649) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(-2147483648)_NeverTraps") { - let input = getFloat80(-2147483648) - let actual = Int(input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(-2147483648)_NeverFails") { - let input = getFloat80(-2147483648) - let actual = Int(exactly: input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(-32768.5)_NeverTraps") { - let input = getFloat80(-32768.5) - let actual = Int(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(-32768.5)_AlwaysFails") { - let input = getFloat80(-32768.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(-128.5)_NeverTraps") { - let input = getFloat80(-128.5) - let actual = Int(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(-128.5)_AlwaysFails") { - let input = getFloat80(-128.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(-0.5)_NeverTraps") { - let input = getFloat80(-0.5) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(-0.5)_AlwaysFails") { - let input = getFloat80(-0.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(-0.0)_NeverTraps") { - let input = getFloat80(-0.0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(-0.0)_NeverFails") { - let input = getFloat80(-0.0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(0.0)_NeverTraps") { - let input = getFloat80(0.0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(0.0)_NeverFails") { - let input = getFloat80(0.0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(0.5)_NeverTraps") { - let input = getFloat80(0.5) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(0.5)_AlwaysFails") { - let input = getFloat80(0.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(127.5)_NeverTraps") { - let input = getFloat80(127.5) - let actual = Int(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(127.5)_AlwaysFails") { - let input = getFloat80(127.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(255.5)_NeverTraps") { - let input = getFloat80(255.5) - let actual = Int(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(255.5)_AlwaysFails") { - let input = getFloat80(255.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(32767.5)_NeverTraps") { - let input = getFloat80(32767.5) - let actual = Int(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(32767.5)_AlwaysFails") { - let input = getFloat80(32767.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(65535.5)_NeverTraps") { - let input = getFloat80(65535.5) - let actual = Int(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(65535.5)_AlwaysFails") { - let input = getFloat80(65535.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(2147483647)_NeverTraps") { - let input = getFloat80(2147483647) - let actual = Int(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(2147483647)_NeverFails") { - let input = getFloat80(2147483647) - let actual = Int(exactly: input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(2147483648)_AlwaysTraps") { - let input = getFloat80(2147483648) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(2147483648)_AlwaysFails") { - let input = getFloat80(2147483648) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(18446744073709551615)_AlwaysTraps") { - let input = getFloat80(18446744073709551615) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(18446744073709551615)_AlwaysFails") { - let input = getFloat80(18446744073709551615) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(-.infinity)_AlwaysTraps") { - let input = getFloat80(-.infinity) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(-.infinity)_AlwaysFails") { - let input = getFloat80(-.infinity) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(+.infinity)_AlwaysTraps") { - let input = getFloat80(+.infinity) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(+.infinity)_AlwaysFails") { - let input = getFloat80(+.infinity) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(-.nan)_AlwaysTraps") { - let input = getFloat80(-.nan) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(-.nan)_AlwaysFails") { - let input = getFloat80(-.nan) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(+.nan)_AlwaysTraps") { - let input = getFloat80(+.nan) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(+.nan)_AlwaysFails") { - let input = getFloat80(+.nan) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(-.signalingNaN)_AlwaysTraps") { - let input = getFloat80(-.signalingNaN) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(-.signalingNaN)_AlwaysFails") { - let input = getFloat80(-.signalingNaN) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(+.signalingNaN)_AlwaysTraps") { - let input = getFloat80(+.signalingNaN) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt.test("FromFloat80(+.signalingNaN)_AlwaysFails") { - let input = getFloat80(+.signalingNaN) - let actual = Int(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt +.test("FromFloat80_NeverTraps") +.forEach(in: [ + (getInt(-2147483648), getFloat80(-2147483648)), + (getInt(-32768), getFloat80(-32768.5)), + (getInt(-128), getFloat80(-128.5)), + (getInt(+0), getFloat80(-0.5)), + (getInt(+0), getFloat80(-0)), + (getInt(+0), getFloat80(+0)), + (getInt(+0), getFloat80(+0.5)), + (getInt(+127), getFloat80(+127.5)), + (getInt(+255), getFloat80(+255.5)), + (getInt(+32767), getFloat80(+32767.5)), + (getInt(+65535), getFloat80(+65535.5)), + (getInt(+2147483647), getFloat80(+2147483647)), +]) { + expectEqual($0.0, Int($0.1)) +} + +FixedPointConversion_Debug32_ToInt +.test("FromFloat80_NeverFails") +.forEach(in: [ + (getInt(-2147483648), getFloat80(-2147483648)), + (getInt(+0), getFloat80(-0)), + (getInt(+0), getFloat80(+0)), + (getInt(+2147483647), getFloat80(+2147483647)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToInt +.test("FromFloat80_AlwaysTraps") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-2147483649), + getFloat80(+2147483648), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int($0)) +} + +FixedPointConversion_Debug32_ToInt +.test("FromFloat80_AlwaysFails") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-2147483649), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-0.5), + getFloat80(+0.5), + getFloat80(+127.5), + getFloat80(+255.5), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(+2147483648), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectNil(Int(exactly: $0)) } #endif // Float80 diff --git a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug32_ToInt16.swift b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug32_ToInt16.swift index b7d4b5cd9314e..c9d4e1814040d 100644 --- a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug32_ToInt16.swift +++ b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug32_ToInt16.swift @@ -14,1700 +14,685 @@ import StdlibUnittest -let FixedPointConversion_Debug32_ToInt16 = TestSuite("FixedPointConversion_Debug32_ToInt16") +let FixedPointConversion_Debug32_ToInt16 = TestSuite( + "FixedPointConversion_Debug32_ToInt16" +) //===----------------------------------------------------------------------===// -// MARK: UInt8: (0)...(255) +// MARK: UInt8: (+0)...(+255) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt16.test("FromUInt8(0)_NeverTraps") { - let input = getUInt8(0) - let actual = Int16(input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToInt16 +.test("FromUInt8_NeverTraps") +.forEach(in: [ + (getInt16(+0), getUInt8(+0)), + (getInt16(+255), getUInt8(+255)), +]) { + expectEqual($0.0, Int16($0.1)) } -FixedPointConversion_Debug32_ToInt16.test("FromUInt8(0)_NeverFails") { - let input = getUInt8(0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromUInt8(255)_NeverTraps") { - let input = getUInt8(255) - let actual = Int16(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromUInt8(255)_NeverFails") { - let input = getUInt8(255) - let actual = Int16(exactly: input) - expectEqual(255, actual) +FixedPointConversion_Debug32_ToInt16 +.test("FromUInt8_NeverFails") +.forEach(in: [ + (getInt16(+0), getUInt8(+0)), + (getInt16(+255), getUInt8(+255)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int8: (-128)...(127) +// MARK: Int8: (-128)...(+127) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt16.test("FromInt8(-128)_NeverTraps") { - let input = getInt8(-128) - let actual = Int16(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt8(-128)_NeverFails") { - let input = getInt8(-128) - let actual = Int16(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt8(0)_NeverTraps") { - let input = getInt8(0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt8(0)_NeverFails") { - let input = getInt8(0) - let actual = Int16(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToInt16 +.test("FromInt8_NeverTraps") +.forEach(in: [ + (getInt16(-128), getInt8(-128)), + (getInt16(+0), getInt8(+0)), + (getInt16(+127), getInt8(+127)), +]) { + expectEqual($0.0, Int16($0.1)) } -FixedPointConversion_Debug32_ToInt16.test("FromInt8(127)_NeverTraps") { - let input = getInt8(127) - let actual = Int16(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt8(127)_NeverFails") { - let input = getInt8(127) - let actual = Int16(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Debug32_ToInt16 +.test("FromInt8_NeverFails") +.forEach(in: [ + (getInt16(-128), getInt8(-128)), + (getInt16(+0), getInt8(+0)), + (getInt16(+127), getInt8(+127)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt16: (0)...(65535) +// MARK: UInt16: (+0)...(+65535) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt16.test("FromUInt16(0)_NeverTraps") { - let input = getUInt16(0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromUInt16(0)_NeverFails") { - let input = getUInt16(0) - let actual = Int16(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToInt16 +.test("FromUInt16_NeverTraps") +.forEach(in: [ + (getInt16(+0), getUInt16(+0)), + (getInt16(+32767), getUInt16(+32767)), +]) { + expectEqual($0.0, Int16($0.1)) } -FixedPointConversion_Debug32_ToInt16.test("FromUInt16(32767)_NeverTraps") { - let input = getUInt16(32767) - let actual = Int16(input) - expectEqual(32767, actual) +FixedPointConversion_Debug32_ToInt16 +.test("FromUInt16_NeverFails") +.forEach(in: [ + (getInt16(+0), getUInt16(+0)), + (getInt16(+32767), getUInt16(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) } -FixedPointConversion_Debug32_ToInt16.test("FromUInt16(32767)_NeverFails") { - let input = getUInt16(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) +FixedPointConversion_Debug32_ToInt16 +.test("FromUInt16_AlwaysTraps") +.forEach(in: [ + getUInt16(+32768), + getUInt16(+65535), +]) { + expectCrashLater() + _blackHole(Int16($0)) } -FixedPointConversion_Debug32_ToInt16.test("FromUInt16(32768)_AlwaysTraps") { - let input = getUInt16(32768) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromUInt16(32768)_AlwaysFails") { - let input = getUInt16(32768) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromUInt16(65535)_AlwaysTraps") { - let input = getUInt16(65535) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromUInt16(65535)_AlwaysFails") { - let input = getUInt16(65535) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt16 +.test("FromUInt16_AlwaysFails") +.forEach(in: [ + getUInt16(+32768), + getUInt16(+65535), +]) { + expectNil(Int16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int16: (-32768)...(32767) +// MARK: Int16: (-32768)...(+32767) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt16.test("FromInt16(-32768)_NeverTraps") { - let input = getInt16(-32768) - let actual = Int16(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt16(-32768)_NeverFails") { - let input = getInt16(-32768) - let actual = Int16(exactly: input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt16(0)_NeverTraps") { - let input = getInt16(0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt16(0)_NeverFails") { - let input = getInt16(0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt16(32767)_NeverTraps") { - let input = getInt16(32767) - let actual = Int16(input) - expectEqual(32767, actual) +FixedPointConversion_Debug32_ToInt16 +.test("FromInt16_NeverTraps") +.forEach(in: [ + (getInt16(-32768), getInt16(-32768)), + (getInt16(+0), getInt16(+0)), + (getInt16(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, Int16($0.1)) } -FixedPointConversion_Debug32_ToInt16.test("FromInt16(32767)_NeverFails") { - let input = getInt16(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) +FixedPointConversion_Debug32_ToInt16 +.test("FromInt16_NeverFails") +.forEach(in: [ + (getInt16(-32768), getInt16(-32768)), + (getInt16(+0), getInt16(+0)), + (getInt16(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt32: (0)...(4294967295) +// MARK: UInt32: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt16.test("FromUInt32(0)_NeverTraps") { - let input = getUInt32(0) - let actual = Int16(input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToInt16 +.test("FromUInt32_NeverTraps") +.forEach(in: [ + (getInt16(+0), getUInt32(+0)), + (getInt16(+32767), getUInt32(+32767)), +]) { + expectEqual($0.0, Int16($0.1)) } -FixedPointConversion_Debug32_ToInt16.test("FromUInt32(0)_NeverFails") { - let input = getUInt32(0) - let actual = Int16(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToInt16 +.test("FromUInt32_NeverFails") +.forEach(in: [ + (getInt16(+0), getUInt32(+0)), + (getInt16(+32767), getUInt32(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) } -FixedPointConversion_Debug32_ToInt16.test("FromUInt32(32767)_NeverTraps") { - let input = getUInt32(32767) - let actual = Int16(input) - expectEqual(32767, actual) +FixedPointConversion_Debug32_ToInt16 +.test("FromUInt32_AlwaysTraps") +.forEach(in: [ + getUInt32(+32768), + getUInt32(+4294967295), +]) { + expectCrashLater() + _blackHole(Int16($0)) } -FixedPointConversion_Debug32_ToInt16.test("FromUInt32(32767)_NeverFails") { - let input = getUInt32(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromUInt32(32768)_AlwaysTraps") { - let input = getUInt32(32768) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromUInt32(32768)_AlwaysFails") { - let input = getUInt32(32768) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromUInt32(4294967295)_AlwaysTraps") { - let input = getUInt32(4294967295) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromUInt32(4294967295)_AlwaysFails") { - let input = getUInt32(4294967295) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt16 +.test("FromUInt32_AlwaysFails") +.forEach(in: [ + getUInt32(+32768), + getUInt32(+4294967295), +]) { + expectNil(Int16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int32: (-2147483648)...(2147483647) +// MARK: Int32: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt16.test("FromInt32(-2147483648)_AlwaysTraps") { - let input = getInt32(-2147483648) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt32(-2147483648)_AlwaysFails") { - let input = getInt32(-2147483648) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt32(-32769)_AlwaysTraps") { - let input = getInt32(-32769) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt32(-32769)_AlwaysFails") { - let input = getInt32(-32769) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt32(-32768)_NeverTraps") { - let input = getInt32(-32768) - let actual = Int16(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt32(-32768)_NeverFails") { - let input = getInt32(-32768) - let actual = Int16(exactly: input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt32(0)_NeverTraps") { - let input = getInt32(0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt32(0)_NeverFails") { - let input = getInt32(0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt32(32767)_NeverTraps") { - let input = getInt32(32767) - let actual = Int16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt32(32767)_NeverFails") { - let input = getInt32(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt32(32768)_AlwaysTraps") { - let input = getInt32(32768) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt32(32768)_AlwaysFails") { - let input = getInt32(32768) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt32(2147483647)_AlwaysTraps") { - let input = getInt32(2147483647) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt32(2147483647)_AlwaysFails") { - let input = getInt32(2147483647) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt16 +.test("FromInt32_NeverTraps") +.forEach(in: [ + (getInt16(-32768), getInt32(-32768)), + (getInt16(+0), getInt32(+0)), + (getInt16(+32767), getInt32(+32767)), +]) { + expectEqual($0.0, Int16($0.1)) +} + +FixedPointConversion_Debug32_ToInt16 +.test("FromInt32_NeverFails") +.forEach(in: [ + (getInt16(-32768), getInt32(-32768)), + (getInt16(+0), getInt32(+0)), + (getInt16(+32767), getInt32(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToInt16 +.test("FromInt32_AlwaysTraps") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-32769), + getInt32(+32768), + getInt32(+2147483647), +]) { + expectCrashLater() + _blackHole(Int16($0)) +} + +FixedPointConversion_Debug32_ToInt16 +.test("FromInt32_AlwaysFails") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-32769), + getInt32(+32768), + getInt32(+2147483647), +]) { + expectNil(Int16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt64: (0)...(18446744073709551615) +// MARK: UInt64: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt16.test("FromUInt64(0)_NeverTraps") { - let input = getUInt64(0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromUInt64(0)_NeverFails") { - let input = getUInt64(0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromUInt64(32767)_NeverTraps") { - let input = getUInt64(32767) - let actual = Int16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromUInt64(32767)_NeverFails") { - let input = getUInt64(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromUInt64(32768)_AlwaysTraps") { - let input = getUInt64(32768) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } +FixedPointConversion_Debug32_ToInt16 +.test("FromUInt64_NeverTraps") +.forEach(in: [ + (getInt16(+0), getUInt64(+0)), + (getInt16(+32767), getUInt64(+32767)), +]) { + expectEqual($0.0, Int16($0.1)) } -FixedPointConversion_Debug32_ToInt16.test("FromUInt64(32768)_AlwaysFails") { - let input = getUInt64(32768) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt16 +.test("FromUInt64_NeverFails") +.forEach(in: [ + (getInt16(+0), getUInt64(+0)), + (getInt16(+32767), getUInt64(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) } -FixedPointConversion_Debug32_ToInt16.test("FromUInt64(18446744073709551615)_AlwaysTraps") { - let input = getUInt64(18446744073709551615) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } +FixedPointConversion_Debug32_ToInt16 +.test("FromUInt64_AlwaysTraps") +.forEach(in: [ + getUInt64(+32768), + getUInt64(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(Int16($0)) } -FixedPointConversion_Debug32_ToInt16.test("FromUInt64(18446744073709551615)_AlwaysFails") { - let input = getUInt64(18446744073709551615) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt16 +.test("FromUInt64_AlwaysFails") +.forEach(in: [ + getUInt64(+32768), + getUInt64(+18446744073709551615), +]) { + expectNil(Int16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int64: (-9223372036854775808)...(9223372036854775807) +// MARK: Int64: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt16.test("FromInt64(-9223372036854775808)_AlwaysTraps") { - let input = getInt64(-9223372036854775808) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt64(-9223372036854775808)_AlwaysFails") { - let input = getInt64(-9223372036854775808) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt64(-32769)_AlwaysTraps") { - let input = getInt64(-32769) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt64(-32769)_AlwaysFails") { - let input = getInt64(-32769) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt64(-32768)_NeverTraps") { - let input = getInt64(-32768) - let actual = Int16(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt64(-32768)_NeverFails") { - let input = getInt64(-32768) - let actual = Int16(exactly: input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt64(0)_NeverTraps") { - let input = getInt64(0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt64(0)_NeverFails") { - let input = getInt64(0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt64(32767)_NeverTraps") { - let input = getInt64(32767) - let actual = Int16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt64(32767)_NeverFails") { - let input = getInt64(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt64(32768)_AlwaysTraps") { - let input = getInt64(32768) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt64(32768)_AlwaysFails") { - let input = getInt64(32768) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt64(9223372036854775807)_AlwaysTraps") { - let input = getInt64(9223372036854775807) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt64(9223372036854775807)_AlwaysFails") { - let input = getInt64(9223372036854775807) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt16 +.test("FromInt64_NeverTraps") +.forEach(in: [ + (getInt16(-32768), getInt64(-32768)), + (getInt16(+0), getInt64(+0)), + (getInt16(+32767), getInt64(+32767)), +]) { + expectEqual($0.0, Int16($0.1)) +} + +FixedPointConversion_Debug32_ToInt16 +.test("FromInt64_NeverFails") +.forEach(in: [ + (getInt16(-32768), getInt64(-32768)), + (getInt16(+0), getInt64(+0)), + (getInt16(+32767), getInt64(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToInt16 +.test("FromInt64_AlwaysTraps") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-32769), + getInt64(+32768), + getInt64(+9223372036854775807), +]) { + expectCrashLater() + _blackHole(Int16($0)) +} + +FixedPointConversion_Debug32_ToInt16 +.test("FromInt64_AlwaysFails") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-32769), + getInt64(+32768), + getInt64(+9223372036854775807), +]) { + expectNil(Int16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt: (0)...(4294967295) +// MARK: UInt: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt16.test("FromUInt(0)_NeverTraps") { - let input = getUInt(0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromUInt(0)_NeverFails") { - let input = getUInt(0) - let actual = Int16(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToInt16 +.test("FromUInt_NeverTraps") +.forEach(in: [ + (getInt16(+0), getUInt(+0)), + (getInt16(+32767), getUInt(+32767)), +]) { + expectEqual($0.0, Int16($0.1)) } -FixedPointConversion_Debug32_ToInt16.test("FromUInt(32767)_NeverTraps") { - let input = getUInt(32767) - let actual = Int16(input) - expectEqual(32767, actual) +FixedPointConversion_Debug32_ToInt16 +.test("FromUInt_NeverFails") +.forEach(in: [ + (getInt16(+0), getUInt(+0)), + (getInt16(+32767), getUInt(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) } -FixedPointConversion_Debug32_ToInt16.test("FromUInt(32767)_NeverFails") { - let input = getUInt(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) +FixedPointConversion_Debug32_ToInt16 +.test("FromUInt_AlwaysTraps") +.forEach(in: [ + getUInt(+32768), + getUInt(+4294967295), +]) { + expectCrashLater() + _blackHole(Int16($0)) } -FixedPointConversion_Debug32_ToInt16.test("FromUInt(32768)_AlwaysTraps") { - let input = getUInt(32768) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromUInt(32768)_AlwaysFails") { - let input = getUInt(32768) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromUInt(4294967295)_AlwaysTraps") { - let input = getUInt(4294967295) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromUInt(4294967295)_AlwaysFails") { - let input = getUInt(4294967295) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt16 +.test("FromUInt_AlwaysFails") +.forEach(in: [ + getUInt(+32768), + getUInt(+4294967295), +]) { + expectNil(Int16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int: (-2147483648)...(2147483647) +// MARK: Int: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt16.test("FromInt(-2147483648)_AlwaysTraps") { - let input = getInt(-2147483648) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt(-2147483648)_AlwaysFails") { - let input = getInt(-2147483648) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt(-32769)_AlwaysTraps") { - let input = getInt(-32769) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt(-32769)_AlwaysFails") { - let input = getInt(-32769) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt(-32768)_NeverTraps") { - let input = getInt(-32768) - let actual = Int16(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt(-32768)_NeverFails") { - let input = getInt(-32768) - let actual = Int16(exactly: input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt(0)_NeverTraps") { - let input = getInt(0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt(0)_NeverFails") { - let input = getInt(0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt(32767)_NeverTraps") { - let input = getInt(32767) - let actual = Int16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt(32767)_NeverFails") { - let input = getInt(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt(32768)_AlwaysTraps") { - let input = getInt(32768) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt(32768)_AlwaysFails") { - let input = getInt(32768) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt(2147483647)_AlwaysTraps") { - let input = getInt(2147483647) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromInt(2147483647)_AlwaysFails") { - let input = getInt(2147483647) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt16 +.test("FromInt_NeverTraps") +.forEach(in: [ + (getInt16(-32768), getInt(-32768)), + (getInt16(+0), getInt(+0)), + (getInt16(+32767), getInt(+32767)), +]) { + expectEqual($0.0, Int16($0.1)) +} + +FixedPointConversion_Debug32_ToInt16 +.test("FromInt_NeverFails") +.forEach(in: [ + (getInt16(-32768), getInt(-32768)), + (getInt16(+0), getInt(+0)), + (getInt16(+32767), getInt(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToInt16 +.test("FromInt_AlwaysTraps") +.forEach(in: [ + getInt(-2147483648), + getInt(-32769), + getInt(+32768), + getInt(+2147483647), +]) { + expectCrashLater() + _blackHole(Int16($0)) +} + +FixedPointConversion_Debug32_ToInt16 +.test("FromInt_AlwaysFails") +.forEach(in: [ + getInt(-2147483648), + getInt(-32769), + getInt(+32768), + getInt(+2147483647), +]) { + expectNil(Int16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float16: (-2047)...(2047) +// MARK: Float16: (-2047)...(+2047) //===----------------------------------------------------------------------===// #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -FixedPointConversion_Debug32_ToInt16.test("FromFloat16(-2047)_NeverTraps") { - let input = getFloat16(-2047) - let actual = Int16(input) - expectEqual(-2047, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat16(-2047)_NeverFails") { - let input = getFloat16(-2047) - let actual = Int16(exactly: input) - expectEqual(-2047, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat16(-128.5)_NeverTraps") { - let input = getFloat16(-128.5) - let actual = Int16(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat16(-128.5)_AlwaysFails") { - let input = getFloat16(-128.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat16(-0.5)_NeverTraps") { - let input = getFloat16(-0.5) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat16(-0.5)_AlwaysFails") { - let input = getFloat16(-0.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat16(-0.0)_NeverTraps") { - let input = getFloat16(-0.0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat16(-0.0)_NeverFails") { - let input = getFloat16(-0.0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat16(0.0)_NeverTraps") { - let input = getFloat16(0.0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat16(0.0)_NeverFails") { - let input = getFloat16(0.0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat16(0.5)_NeverTraps") { - let input = getFloat16(0.5) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat16(0.5)_AlwaysFails") { - let input = getFloat16(0.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat16(127.5)_NeverTraps") { - let input = getFloat16(127.5) - let actual = Int16(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat16(127.5)_AlwaysFails") { - let input = getFloat16(127.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat16(255.5)_NeverTraps") { - let input = getFloat16(255.5) - let actual = Int16(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat16(255.5)_AlwaysFails") { - let input = getFloat16(255.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat16(2047)_NeverTraps") { - let input = getFloat16(2047) - let actual = Int16(input) - expectEqual(2047, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat16(2047)_NeverFails") { - let input = getFloat16(2047) - let actual = Int16(exactly: input) - expectEqual(2047, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat16(-.infinity)_AlwaysTraps") { - let input = getFloat16(-.infinity) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat16(-.infinity)_AlwaysFails") { - let input = getFloat16(-.infinity) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat16(+.infinity)_AlwaysTraps") { - let input = getFloat16(+.infinity) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat16(+.infinity)_AlwaysFails") { - let input = getFloat16(+.infinity) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat16(-.nan)_AlwaysTraps") { - let input = getFloat16(-.nan) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat16(-.nan)_AlwaysFails") { - let input = getFloat16(-.nan) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat16(+.nan)_AlwaysTraps") { - let input = getFloat16(+.nan) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat16(+.nan)_AlwaysFails") { - let input = getFloat16(+.nan) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat16(-.signalingNaN)_AlwaysTraps") { - let input = getFloat16(-.signalingNaN) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat16(-.signalingNaN)_AlwaysFails") { - let input = getFloat16(-.signalingNaN) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat16(+.signalingNaN)_AlwaysTraps") { - let input = getFloat16(+.signalingNaN) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat16(+.signalingNaN)_AlwaysFails") { - let input = getFloat16(+.signalingNaN) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt16 +.test("FromFloat16_NeverTraps") +.forEach(in: [ + (getInt16(-2047), getFloat16(-2047)), + (getInt16(-128), getFloat16(-128.5)), + (getInt16(+0), getFloat16(-0.5)), + (getInt16(+0), getFloat16(+0)), + (getInt16(+0), getFloat16(-0)), + (getInt16(+0), getFloat16(+0.5)), + (getInt16(+127), getFloat16(+127.5)), + (getInt16(+255), getFloat16(+255.5)), + (getInt16(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, Int16($0.1)) +} + +FixedPointConversion_Debug32_ToInt16 +.test("FromFloat16_NeverFails") +.forEach(in: [ + (getInt16(-2047), getFloat16(-2047)), + (getInt16(+0), getFloat16(+0)), + (getInt16(+0), getFloat16(-0)), + (getInt16(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToInt16 +.test("FromFloat16_AlwaysTraps") +.forEach(in: [ + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int16($0)) +} + +FixedPointConversion_Debug32_ToInt16 +.test("FromFloat16_AlwaysFails") +.forEach(in: [ + getFloat16(-128.5), + getFloat16(-0.5), + getFloat16(+0.5), + getFloat16(+127.5), + getFloat16(+255.5), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectNil(Int16(exactly: $0)) } } #endif // Float16 //===----------------------------------------------------------------------===// -// MARK: Float32: (-16777215)...(16777215) +// MARK: Float32: (-16777215)...(+16777215) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(-16777215)_AlwaysTraps") { - let input = getFloat32(-16777215) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(-16777215)_AlwaysFails") { - let input = getFloat32(-16777215) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(-32769)_AlwaysTraps") { - let input = getFloat32(-32769) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(-32769)_AlwaysFails") { - let input = getFloat32(-32769) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(-32768.5)_NeverTraps") { - let input = getFloat32(-32768.5) - let actual = Int16(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(-32768.5)_AlwaysFails") { - let input = getFloat32(-32768.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(-32768)_NeverTraps") { - let input = getFloat32(-32768) - let actual = Int16(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(-32768)_NeverFails") { - let input = getFloat32(-32768) - let actual = Int16(exactly: input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(-128.5)_NeverTraps") { - let input = getFloat32(-128.5) - let actual = Int16(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(-128.5)_AlwaysFails") { - let input = getFloat32(-128.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(-0.5)_NeverTraps") { - let input = getFloat32(-0.5) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(-0.5)_AlwaysFails") { - let input = getFloat32(-0.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(-0.0)_NeverTraps") { - let input = getFloat32(-0.0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(-0.0)_NeverFails") { - let input = getFloat32(-0.0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(0.0)_NeverTraps") { - let input = getFloat32(0.0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(0.0)_NeverFails") { - let input = getFloat32(0.0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(0.5)_NeverTraps") { - let input = getFloat32(0.5) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(0.5)_AlwaysFails") { - let input = getFloat32(0.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(127.5)_NeverTraps") { - let input = getFloat32(127.5) - let actual = Int16(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(127.5)_AlwaysFails") { - let input = getFloat32(127.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(255.5)_NeverTraps") { - let input = getFloat32(255.5) - let actual = Int16(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(255.5)_AlwaysFails") { - let input = getFloat32(255.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(32767)_NeverTraps") { - let input = getFloat32(32767) - let actual = Int16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(32767)_NeverFails") { - let input = getFloat32(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(32767.5)_NeverTraps") { - let input = getFloat32(32767.5) - let actual = Int16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(32767.5)_AlwaysFails") { - let input = getFloat32(32767.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(32768)_AlwaysTraps") { - let input = getFloat32(32768) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(32768)_AlwaysFails") { - let input = getFloat32(32768) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(65535.5)_AlwaysTraps") { - let input = getFloat32(65535.5) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(65535.5)_AlwaysFails") { - let input = getFloat32(65535.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(16777215)_AlwaysTraps") { - let input = getFloat32(16777215) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(16777215)_AlwaysFails") { - let input = getFloat32(16777215) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(-.infinity)_AlwaysTraps") { - let input = getFloat32(-.infinity) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(-.infinity)_AlwaysFails") { - let input = getFloat32(-.infinity) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(+.infinity)_AlwaysTraps") { - let input = getFloat32(+.infinity) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(+.infinity)_AlwaysFails") { - let input = getFloat32(+.infinity) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(-.nan)_AlwaysTraps") { - let input = getFloat32(-.nan) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(-.nan)_AlwaysFails") { - let input = getFloat32(-.nan) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(+.nan)_AlwaysTraps") { - let input = getFloat32(+.nan) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(+.nan)_AlwaysFails") { - let input = getFloat32(+.nan) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(-.signalingNaN)_AlwaysTraps") { - let input = getFloat32(-.signalingNaN) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(-.signalingNaN)_AlwaysFails") { - let input = getFloat32(-.signalingNaN) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(+.signalingNaN)_AlwaysTraps") { - let input = getFloat32(+.signalingNaN) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat32(+.signalingNaN)_AlwaysFails") { - let input = getFloat32(+.signalingNaN) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt16 +.test("FromFloat32_NeverTraps") +.forEach(in: [ + (getInt16(-32768), getFloat32(-32768.5)), + (getInt16(-32768), getFloat32(-32768)), + (getInt16(-128), getFloat32(-128.5)), + (getInt16(+0), getFloat32(-0.5)), + (getInt16(+0), getFloat32(+0)), + (getInt16(+0), getFloat32(-0)), + (getInt16(+0), getFloat32(+0.5)), + (getInt16(+127), getFloat32(+127.5)), + (getInt16(+255), getFloat32(+255.5)), + (getInt16(+32767), getFloat32(+32767)), + (getInt16(+32767), getFloat32(+32767.5)), +]) { + expectEqual($0.0, Int16($0.1)) +} + +FixedPointConversion_Debug32_ToInt16 +.test("FromFloat32_NeverFails") +.forEach(in: [ + (getInt16(-32768), getFloat32(-32768)), + (getInt16(+0), getFloat32(+0)), + (getInt16(+0), getFloat32(-0)), + (getInt16(+32767), getFloat32(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToInt16 +.test("FromFloat32_AlwaysTraps") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32769), + getFloat32(+32768), + getFloat32(+65535.5), + getFloat32(+16777215), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int16($0)) +} + +FixedPointConversion_Debug32_ToInt16 +.test("FromFloat32_AlwaysFails") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32769), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-0.5), + getFloat32(+0.5), + getFloat32(+127.5), + getFloat32(+255.5), + getFloat32(+32767.5), + getFloat32(+32768), + getFloat32(+65535.5), + getFloat32(+16777215), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectNil(Int16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float64: (-9007199254740991)...(9007199254740991) +// MARK: Float64: (-9007199254740991)...(+9007199254740991) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(-9007199254740991)_AlwaysTraps") { - let input = getFloat64(-9007199254740991) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(-9007199254740991)_AlwaysFails") { - let input = getFloat64(-9007199254740991) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(-32769)_AlwaysTraps") { - let input = getFloat64(-32769) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(-32769)_AlwaysFails") { - let input = getFloat64(-32769) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(-32768.5)_NeverTraps") { - let input = getFloat64(-32768.5) - let actual = Int16(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(-32768.5)_AlwaysFails") { - let input = getFloat64(-32768.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(-32768)_NeverTraps") { - let input = getFloat64(-32768) - let actual = Int16(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(-32768)_NeverFails") { - let input = getFloat64(-32768) - let actual = Int16(exactly: input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(-128.5)_NeverTraps") { - let input = getFloat64(-128.5) - let actual = Int16(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(-128.5)_AlwaysFails") { - let input = getFloat64(-128.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(-0.5)_NeverTraps") { - let input = getFloat64(-0.5) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(-0.5)_AlwaysFails") { - let input = getFloat64(-0.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(-0.0)_NeverTraps") { - let input = getFloat64(-0.0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(-0.0)_NeverFails") { - let input = getFloat64(-0.0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(0.0)_NeverTraps") { - let input = getFloat64(0.0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(0.0)_NeverFails") { - let input = getFloat64(0.0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(0.5)_NeverTraps") { - let input = getFloat64(0.5) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(0.5)_AlwaysFails") { - let input = getFloat64(0.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(127.5)_NeverTraps") { - let input = getFloat64(127.5) - let actual = Int16(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(127.5)_AlwaysFails") { - let input = getFloat64(127.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(255.5)_NeverTraps") { - let input = getFloat64(255.5) - let actual = Int16(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(255.5)_AlwaysFails") { - let input = getFloat64(255.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(32767)_NeverTraps") { - let input = getFloat64(32767) - let actual = Int16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(32767)_NeverFails") { - let input = getFloat64(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(32767.5)_NeverTraps") { - let input = getFloat64(32767.5) - let actual = Int16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(32767.5)_AlwaysFails") { - let input = getFloat64(32767.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(32768)_AlwaysTraps") { - let input = getFloat64(32768) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(32768)_AlwaysFails") { - let input = getFloat64(32768) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(65535.5)_AlwaysTraps") { - let input = getFloat64(65535.5) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(65535.5)_AlwaysFails") { - let input = getFloat64(65535.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(9007199254740991)_AlwaysTraps") { - let input = getFloat64(9007199254740991) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(9007199254740991)_AlwaysFails") { - let input = getFloat64(9007199254740991) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(-.infinity)_AlwaysTraps") { - let input = getFloat64(-.infinity) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(-.infinity)_AlwaysFails") { - let input = getFloat64(-.infinity) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(+.infinity)_AlwaysTraps") { - let input = getFloat64(+.infinity) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(+.infinity)_AlwaysFails") { - let input = getFloat64(+.infinity) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(-.nan)_AlwaysTraps") { - let input = getFloat64(-.nan) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(-.nan)_AlwaysFails") { - let input = getFloat64(-.nan) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(+.nan)_AlwaysTraps") { - let input = getFloat64(+.nan) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(+.nan)_AlwaysFails") { - let input = getFloat64(+.nan) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(-.signalingNaN)_AlwaysTraps") { - let input = getFloat64(-.signalingNaN) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(-.signalingNaN)_AlwaysFails") { - let input = getFloat64(-.signalingNaN) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(+.signalingNaN)_AlwaysTraps") { - let input = getFloat64(+.signalingNaN) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat64(+.signalingNaN)_AlwaysFails") { - let input = getFloat64(+.signalingNaN) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt16 +.test("FromFloat64_NeverTraps") +.forEach(in: [ + (getInt16(-32768), getFloat64(-32768.5)), + (getInt16(-32768), getFloat64(-32768)), + (getInt16(-128), getFloat64(-128.5)), + (getInt16(+0), getFloat64(-0.5)), + (getInt16(+0), getFloat64(+0)), + (getInt16(+0), getFloat64(-0)), + (getInt16(+0), getFloat64(+0.5)), + (getInt16(+127), getFloat64(+127.5)), + (getInt16(+255), getFloat64(+255.5)), + (getInt16(+32767), getFloat64(+32767)), + (getInt16(+32767), getFloat64(+32767.5)), +]) { + expectEqual($0.0, Int16($0.1)) +} + +FixedPointConversion_Debug32_ToInt16 +.test("FromFloat64_NeverFails") +.forEach(in: [ + (getInt16(-32768), getFloat64(-32768)), + (getInt16(+0), getFloat64(+0)), + (getInt16(+0), getFloat64(-0)), + (getInt16(+32767), getFloat64(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToInt16 +.test("FromFloat64_AlwaysTraps") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32769), + getFloat64(+32768), + getFloat64(+65535.5), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int16($0)) +} + +FixedPointConversion_Debug32_ToInt16 +.test("FromFloat64_AlwaysFails") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32769), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-0.5), + getFloat64(+0.5), + getFloat64(+127.5), + getFloat64(+255.5), + getFloat64(+32767.5), + getFloat64(+32768), + getFloat64(+65535.5), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectNil(Int16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float80: (-18446744073709551615)...(18446744073709551615) +// MARK: Float80: (-18446744073709551615)...(+18446744073709551615) //===----------------------------------------------------------------------===// #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(-18446744073709551615)_AlwaysTraps") { - let input = getFloat80(-18446744073709551615) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(-18446744073709551615)_AlwaysFails") { - let input = getFloat80(-18446744073709551615) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(-32769)_AlwaysTraps") { - let input = getFloat80(-32769) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(-32769)_AlwaysFails") { - let input = getFloat80(-32769) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(-32768.5)_NeverTraps") { - let input = getFloat80(-32768.5) - let actual = Int16(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(-32768.5)_AlwaysFails") { - let input = getFloat80(-32768.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(-32768)_NeverTraps") { - let input = getFloat80(-32768) - let actual = Int16(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(-32768)_NeverFails") { - let input = getFloat80(-32768) - let actual = Int16(exactly: input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(-128.5)_NeverTraps") { - let input = getFloat80(-128.5) - let actual = Int16(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(-128.5)_AlwaysFails") { - let input = getFloat80(-128.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(-0.5)_NeverTraps") { - let input = getFloat80(-0.5) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(-0.5)_AlwaysFails") { - let input = getFloat80(-0.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(-0.0)_NeverTraps") { - let input = getFloat80(-0.0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(-0.0)_NeverFails") { - let input = getFloat80(-0.0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(0.0)_NeverTraps") { - let input = getFloat80(0.0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(0.0)_NeverFails") { - let input = getFloat80(0.0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(0.5)_NeverTraps") { - let input = getFloat80(0.5) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(0.5)_AlwaysFails") { - let input = getFloat80(0.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(127.5)_NeverTraps") { - let input = getFloat80(127.5) - let actual = Int16(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(127.5)_AlwaysFails") { - let input = getFloat80(127.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(255.5)_NeverTraps") { - let input = getFloat80(255.5) - let actual = Int16(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(255.5)_AlwaysFails") { - let input = getFloat80(255.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(32767)_NeverTraps") { - let input = getFloat80(32767) - let actual = Int16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(32767)_NeverFails") { - let input = getFloat80(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(32767.5)_NeverTraps") { - let input = getFloat80(32767.5) - let actual = Int16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(32767.5)_AlwaysFails") { - let input = getFloat80(32767.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(32768)_AlwaysTraps") { - let input = getFloat80(32768) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(32768)_AlwaysFails") { - let input = getFloat80(32768) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(65535.5)_AlwaysTraps") { - let input = getFloat80(65535.5) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(65535.5)_AlwaysFails") { - let input = getFloat80(65535.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(18446744073709551615)_AlwaysTraps") { - let input = getFloat80(18446744073709551615) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(18446744073709551615)_AlwaysFails") { - let input = getFloat80(18446744073709551615) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(-.infinity)_AlwaysTraps") { - let input = getFloat80(-.infinity) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(-.infinity)_AlwaysFails") { - let input = getFloat80(-.infinity) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(+.infinity)_AlwaysTraps") { - let input = getFloat80(+.infinity) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(+.infinity)_AlwaysFails") { - let input = getFloat80(+.infinity) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(-.nan)_AlwaysTraps") { - let input = getFloat80(-.nan) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(-.nan)_AlwaysFails") { - let input = getFloat80(-.nan) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(+.nan)_AlwaysTraps") { - let input = getFloat80(+.nan) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(+.nan)_AlwaysFails") { - let input = getFloat80(+.nan) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(-.signalingNaN)_AlwaysTraps") { - let input = getFloat80(-.signalingNaN) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(-.signalingNaN)_AlwaysFails") { - let input = getFloat80(-.signalingNaN) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(+.signalingNaN)_AlwaysTraps") { - let input = getFloat80(+.signalingNaN) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt16.test("FromFloat80(+.signalingNaN)_AlwaysFails") { - let input = getFloat80(+.signalingNaN) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt16 +.test("FromFloat80_NeverTraps") +.forEach(in: [ + (getInt16(-32768), getFloat80(-32768.5)), + (getInt16(-32768), getFloat80(-32768)), + (getInt16(-128), getFloat80(-128.5)), + (getInt16(+0), getFloat80(-0.5)), + (getInt16(+0), getFloat80(+0)), + (getInt16(+0), getFloat80(-0)), + (getInt16(+0), getFloat80(+0.5)), + (getInt16(+127), getFloat80(+127.5)), + (getInt16(+255), getFloat80(+255.5)), + (getInt16(+32767), getFloat80(+32767)), + (getInt16(+32767), getFloat80(+32767.5)), +]) { + expectEqual($0.0, Int16($0.1)) +} + +FixedPointConversion_Debug32_ToInt16 +.test("FromFloat80_NeverFails") +.forEach(in: [ + (getInt16(-32768), getFloat80(-32768)), + (getInt16(+0), getFloat80(+0)), + (getInt16(+0), getFloat80(-0)), + (getInt16(+32767), getFloat80(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToInt16 +.test("FromFloat80_AlwaysTraps") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32769), + getFloat80(+32768), + getFloat80(+65535.5), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int16($0)) +} + +FixedPointConversion_Debug32_ToInt16 +.test("FromFloat80_AlwaysFails") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32769), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-0.5), + getFloat80(+0.5), + getFloat80(+127.5), + getFloat80(+255.5), + getFloat80(+32767.5), + getFloat80(+32768), + getFloat80(+65535.5), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectNil(Int16(exactly: $0)) } #endif // Float80 diff --git a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug32_ToInt32.swift b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug32_ToInt32.swift index f2ef223abf1dd..762d48baa43fc 100644 --- a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug32_ToInt32.swift +++ b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug32_ToInt32.swift @@ -14,1498 +14,612 @@ import StdlibUnittest -let FixedPointConversion_Debug32_ToInt32 = TestSuite("FixedPointConversion_Debug32_ToInt32") +let FixedPointConversion_Debug32_ToInt32 = TestSuite( + "FixedPointConversion_Debug32_ToInt32" +) //===----------------------------------------------------------------------===// -// MARK: UInt8: (0)...(255) +// MARK: UInt8: (+0)...(+255) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt32.test("FromUInt8(0)_NeverTraps") { - let input = getUInt8(0) - let actual = Int32(input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToInt32 +.test("FromUInt8_NeverTraps") +.forEach(in: [ + (getInt32(+0), getUInt8(+0)), + (getInt32(+255), getUInt8(+255)), +]) { + expectEqual($0.0, Int32($0.1)) } -FixedPointConversion_Debug32_ToInt32.test("FromUInt8(0)_NeverFails") { - let input = getUInt8(0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromUInt8(255)_NeverTraps") { - let input = getUInt8(255) - let actual = Int32(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromUInt8(255)_NeverFails") { - let input = getUInt8(255) - let actual = Int32(exactly: input) - expectEqual(255, actual) +FixedPointConversion_Debug32_ToInt32 +.test("FromUInt8_NeverFails") +.forEach(in: [ + (getInt32(+0), getUInt8(+0)), + (getInt32(+255), getUInt8(+255)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int8: (-128)...(127) +// MARK: Int8: (-128)...(+127) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt32.test("FromInt8(-128)_NeverTraps") { - let input = getInt8(-128) - let actual = Int32(input) - expectEqual(-128, actual) +FixedPointConversion_Debug32_ToInt32 +.test("FromInt8_NeverTraps") +.forEach(in: [ + (getInt32(-128), getInt8(-128)), + (getInt32(+0), getInt8(+0)), + (getInt32(+127), getInt8(+127)), +]) { + expectEqual($0.0, Int32($0.1)) } -FixedPointConversion_Debug32_ToInt32.test("FromInt8(-128)_NeverFails") { - let input = getInt8(-128) - let actual = Int32(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromInt8(0)_NeverTraps") { - let input = getInt8(0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromInt8(0)_NeverFails") { - let input = getInt8(0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromInt8(127)_NeverTraps") { - let input = getInt8(127) - let actual = Int32(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromInt8(127)_NeverFails") { - let input = getInt8(127) - let actual = Int32(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Debug32_ToInt32 +.test("FromInt8_NeverFails") +.forEach(in: [ + (getInt32(-128), getInt8(-128)), + (getInt32(+0), getInt8(+0)), + (getInt32(+127), getInt8(+127)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt16: (0)...(65535) +// MARK: UInt16: (+0)...(+65535) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt32.test("FromUInt16(0)_NeverTraps") { - let input = getUInt16(0) - let actual = Int32(input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToInt32 +.test("FromUInt16_NeverTraps") +.forEach(in: [ + (getInt32(+0), getUInt16(+0)), + (getInt32(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, Int32($0.1)) } -FixedPointConversion_Debug32_ToInt32.test("FromUInt16(0)_NeverFails") { - let input = getUInt16(0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromUInt16(65535)_NeverTraps") { - let input = getUInt16(65535) - let actual = Int32(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromUInt16(65535)_NeverFails") { - let input = getUInt16(65535) - let actual = Int32(exactly: input) - expectEqual(65535, actual) +FixedPointConversion_Debug32_ToInt32 +.test("FromUInt16_NeverFails") +.forEach(in: [ + (getInt32(+0), getUInt16(+0)), + (getInt32(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int16: (-32768)...(32767) +// MARK: Int16: (-32768)...(+32767) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt32.test("FromInt16(-32768)_NeverTraps") { - let input = getInt16(-32768) - let actual = Int32(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromInt16(-32768)_NeverFails") { - let input = getInt16(-32768) - let actual = Int32(exactly: input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromInt16(0)_NeverTraps") { - let input = getInt16(0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromInt16(0)_NeverFails") { - let input = getInt16(0) - let actual = Int32(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToInt32 +.test("FromInt16_NeverTraps") +.forEach(in: [ + (getInt32(-32768), getInt16(-32768)), + (getInt32(+0), getInt16(+0)), + (getInt32(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, Int32($0.1)) } -FixedPointConversion_Debug32_ToInt32.test("FromInt16(32767)_NeverTraps") { - let input = getInt16(32767) - let actual = Int32(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromInt16(32767)_NeverFails") { - let input = getInt16(32767) - let actual = Int32(exactly: input) - expectEqual(32767, actual) +FixedPointConversion_Debug32_ToInt32 +.test("FromInt16_NeverFails") +.forEach(in: [ + (getInt32(-32768), getInt16(-32768)), + (getInt32(+0), getInt16(+0)), + (getInt32(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt32: (0)...(4294967295) +// MARK: UInt32: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt32.test("FromUInt32(0)_NeverTraps") { - let input = getUInt32(0) - let actual = Int32(input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToInt32 +.test("FromUInt32_NeverTraps") +.forEach(in: [ + (getInt32(+0), getUInt32(+0)), + (getInt32(+2147483647), getUInt32(+2147483647)), +]) { + expectEqual($0.0, Int32($0.1)) } -FixedPointConversion_Debug32_ToInt32.test("FromUInt32(0)_NeverFails") { - let input = getUInt32(0) - let actual = Int32(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToInt32 +.test("FromUInt32_NeverFails") +.forEach(in: [ + (getInt32(+0), getUInt32(+0)), + (getInt32(+2147483647), getUInt32(+2147483647)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) } -FixedPointConversion_Debug32_ToInt32.test("FromUInt32(2147483647)_NeverTraps") { - let input = getUInt32(2147483647) - let actual = Int32(input) - expectEqual(2147483647, actual) +FixedPointConversion_Debug32_ToInt32 +.test("FromUInt32_AlwaysTraps") +.forEach(in: [ + getUInt32(+2147483648), + getUInt32(+4294967295), +]) { + expectCrashLater() + _blackHole(Int32($0)) } -FixedPointConversion_Debug32_ToInt32.test("FromUInt32(2147483647)_NeverFails") { - let input = getUInt32(2147483647) - let actual = Int32(exactly: input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromUInt32(2147483648)_AlwaysTraps") { - let input = getUInt32(2147483648) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromUInt32(2147483648)_AlwaysFails") { - let input = getUInt32(2147483648) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromUInt32(4294967295)_AlwaysTraps") { - let input = getUInt32(4294967295) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromUInt32(4294967295)_AlwaysFails") { - let input = getUInt32(4294967295) - let actual = Int32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt32 +.test("FromUInt32_AlwaysFails") +.forEach(in: [ + getUInt32(+2147483648), + getUInt32(+4294967295), +]) { + expectNil(Int32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int32: (-2147483648)...(2147483647) +// MARK: Int32: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt32.test("FromInt32(-2147483648)_NeverTraps") { - let input = getInt32(-2147483648) - let actual = Int32(input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromInt32(-2147483648)_NeverFails") { - let input = getInt32(-2147483648) - let actual = Int32(exactly: input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromInt32(0)_NeverTraps") { - let input = getInt32(0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromInt32(0)_NeverFails") { - let input = getInt32(0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromInt32(2147483647)_NeverTraps") { - let input = getInt32(2147483647) - let actual = Int32(input) - expectEqual(2147483647, actual) +FixedPointConversion_Debug32_ToInt32 +.test("FromInt32_NeverTraps") +.forEach(in: [ + (getInt32(-2147483648), getInt32(-2147483648)), + (getInt32(+0), getInt32(+0)), + (getInt32(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, Int32($0.1)) } -FixedPointConversion_Debug32_ToInt32.test("FromInt32(2147483647)_NeverFails") { - let input = getInt32(2147483647) - let actual = Int32(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Debug32_ToInt32 +.test("FromInt32_NeverFails") +.forEach(in: [ + (getInt32(-2147483648), getInt32(-2147483648)), + (getInt32(+0), getInt32(+0)), + (getInt32(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt64: (0)...(18446744073709551615) +// MARK: UInt64: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt32.test("FromUInt64(0)_NeverTraps") { - let input = getUInt64(0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromUInt64(0)_NeverFails") { - let input = getUInt64(0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromUInt64(2147483647)_NeverTraps") { - let input = getUInt64(2147483647) - let actual = Int32(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromUInt64(2147483647)_NeverFails") { - let input = getUInt64(2147483647) - let actual = Int32(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Debug32_ToInt32 +.test("FromUInt64_NeverTraps") +.forEach(in: [ + (getInt32(+0), getUInt64(+0)), + (getInt32(+2147483647), getUInt64(+2147483647)), +]) { + expectEqual($0.0, Int32($0.1)) } -FixedPointConversion_Debug32_ToInt32.test("FromUInt64(2147483648)_AlwaysTraps") { - let input = getUInt64(2147483648) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } +FixedPointConversion_Debug32_ToInt32 +.test("FromUInt64_NeverFails") +.forEach(in: [ + (getInt32(+0), getUInt64(+0)), + (getInt32(+2147483647), getUInt64(+2147483647)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) } -FixedPointConversion_Debug32_ToInt32.test("FromUInt64(2147483648)_AlwaysFails") { - let input = getUInt64(2147483648) - let actual = Int32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt32 +.test("FromUInt64_AlwaysTraps") +.forEach(in: [ + getUInt64(+2147483648), + getUInt64(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(Int32($0)) } -FixedPointConversion_Debug32_ToInt32.test("FromUInt64(18446744073709551615)_AlwaysTraps") { - let input = getUInt64(18446744073709551615) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromUInt64(18446744073709551615)_AlwaysFails") { - let input = getUInt64(18446744073709551615) - let actual = Int32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt32 +.test("FromUInt64_AlwaysFails") +.forEach(in: [ + getUInt64(+2147483648), + getUInt64(+18446744073709551615), +]) { + expectNil(Int32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int64: (-9223372036854775808)...(9223372036854775807) +// MARK: Int64: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt32.test("FromInt64(-9223372036854775808)_AlwaysTraps") { - let input = getInt64(-9223372036854775808) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromInt64(-9223372036854775808)_AlwaysFails") { - let input = getInt64(-9223372036854775808) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromInt64(-2147483649)_AlwaysTraps") { - let input = getInt64(-2147483649) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromInt64(-2147483649)_AlwaysFails") { - let input = getInt64(-2147483649) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromInt64(-2147483648)_NeverTraps") { - let input = getInt64(-2147483648) - let actual = Int32(input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromInt64(-2147483648)_NeverFails") { - let input = getInt64(-2147483648) - let actual = Int32(exactly: input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromInt64(0)_NeverTraps") { - let input = getInt64(0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromInt64(0)_NeverFails") { - let input = getInt64(0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromInt64(2147483647)_NeverTraps") { - let input = getInt64(2147483647) - let actual = Int32(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromInt64(2147483647)_NeverFails") { - let input = getInt64(2147483647) - let actual = Int32(exactly: input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromInt64(2147483648)_AlwaysTraps") { - let input = getInt64(2147483648) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromInt64(2147483648)_AlwaysFails") { - let input = getInt64(2147483648) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromInt64(9223372036854775807)_AlwaysTraps") { - let input = getInt64(9223372036854775807) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromInt64(9223372036854775807)_AlwaysFails") { - let input = getInt64(9223372036854775807) - let actual = Int32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt32 +.test("FromInt64_NeverTraps") +.forEach(in: [ + (getInt32(-2147483648), getInt64(-2147483648)), + (getInt32(+0), getInt64(+0)), + (getInt32(+2147483647), getInt64(+2147483647)), +]) { + expectEqual($0.0, Int32($0.1)) +} + +FixedPointConversion_Debug32_ToInt32 +.test("FromInt64_NeverFails") +.forEach(in: [ + (getInt32(-2147483648), getInt64(-2147483648)), + (getInt32(+0), getInt64(+0)), + (getInt32(+2147483647), getInt64(+2147483647)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToInt32 +.test("FromInt64_AlwaysTraps") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-2147483649), + getInt64(+2147483648), + getInt64(+9223372036854775807), +]) { + expectCrashLater() + _blackHole(Int32($0)) +} + +FixedPointConversion_Debug32_ToInt32 +.test("FromInt64_AlwaysFails") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-2147483649), + getInt64(+2147483648), + getInt64(+9223372036854775807), +]) { + expectNil(Int32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt: (0)...(4294967295) +// MARK: UInt: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt32.test("FromUInt(0)_NeverTraps") { - let input = getUInt(0) - let actual = Int32(input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToInt32 +.test("FromUInt_NeverTraps") +.forEach(in: [ + (getInt32(+0), getUInt(+0)), + (getInt32(+2147483647), getUInt(+2147483647)), +]) { + expectEqual($0.0, Int32($0.1)) } -FixedPointConversion_Debug32_ToInt32.test("FromUInt(0)_NeverFails") { - let input = getUInt(0) - let actual = Int32(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToInt32 +.test("FromUInt_NeverFails") +.forEach(in: [ + (getInt32(+0), getUInt(+0)), + (getInt32(+2147483647), getUInt(+2147483647)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) } -FixedPointConversion_Debug32_ToInt32.test("FromUInt(2147483647)_NeverTraps") { - let input = getUInt(2147483647) - let actual = Int32(input) - expectEqual(2147483647, actual) +FixedPointConversion_Debug32_ToInt32 +.test("FromUInt_AlwaysTraps") +.forEach(in: [ + getUInt(+2147483648), + getUInt(+4294967295), +]) { + expectCrashLater() + _blackHole(Int32($0)) } -FixedPointConversion_Debug32_ToInt32.test("FromUInt(2147483647)_NeverFails") { - let input = getUInt(2147483647) - let actual = Int32(exactly: input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromUInt(2147483648)_AlwaysTraps") { - let input = getUInt(2147483648) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromUInt(2147483648)_AlwaysFails") { - let input = getUInt(2147483648) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromUInt(4294967295)_AlwaysTraps") { - let input = getUInt(4294967295) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromUInt(4294967295)_AlwaysFails") { - let input = getUInt(4294967295) - let actual = Int32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt32 +.test("FromUInt_AlwaysFails") +.forEach(in: [ + getUInt(+2147483648), + getUInt(+4294967295), +]) { + expectNil(Int32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int: (-2147483648)...(2147483647) +// MARK: Int: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt32.test("FromInt(-2147483648)_NeverTraps") { - let input = getInt(-2147483648) - let actual = Int32(input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromInt(-2147483648)_NeverFails") { - let input = getInt(-2147483648) - let actual = Int32(exactly: input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromInt(0)_NeverTraps") { - let input = getInt(0) - let actual = Int32(input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToInt32 +.test("FromInt_NeverTraps") +.forEach(in: [ + (getInt32(-2147483648), getInt(-2147483648)), + (getInt32(+0), getInt(+0)), + (getInt32(+2147483647), getInt(+2147483647)), +]) { + expectEqual($0.0, Int32($0.1)) } -FixedPointConversion_Debug32_ToInt32.test("FromInt(0)_NeverFails") { - let input = getInt(0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromInt(2147483647)_NeverTraps") { - let input = getInt(2147483647) - let actual = Int32(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromInt(2147483647)_NeverFails") { - let input = getInt(2147483647) - let actual = Int32(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Debug32_ToInt32 +.test("FromInt_NeverFails") +.forEach(in: [ + (getInt32(-2147483648), getInt(-2147483648)), + (getInt32(+0), getInt(+0)), + (getInt32(+2147483647), getInt(+2147483647)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Float16: (-2047)...(2047) +// MARK: Float16: (-2047)...(+2047) //===----------------------------------------------------------------------===// #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -FixedPointConversion_Debug32_ToInt32.test("FromFloat16(-2047)_NeverTraps") { - let input = getFloat16(-2047) - let actual = Int32(input) - expectEqual(-2047, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat16(-2047)_NeverFails") { - let input = getFloat16(-2047) - let actual = Int32(exactly: input) - expectEqual(-2047, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat16(-128.5)_NeverTraps") { - let input = getFloat16(-128.5) - let actual = Int32(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat16(-128.5)_AlwaysFails") { - let input = getFloat16(-128.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat16(-0.5)_NeverTraps") { - let input = getFloat16(-0.5) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat16(-0.5)_AlwaysFails") { - let input = getFloat16(-0.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat16(-0.0)_NeverTraps") { - let input = getFloat16(-0.0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat16(-0.0)_NeverFails") { - let input = getFloat16(-0.0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat16(0.0)_NeverTraps") { - let input = getFloat16(0.0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat16(0.0)_NeverFails") { - let input = getFloat16(0.0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat16(0.5)_NeverTraps") { - let input = getFloat16(0.5) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat16(0.5)_AlwaysFails") { - let input = getFloat16(0.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat16(127.5)_NeverTraps") { - let input = getFloat16(127.5) - let actual = Int32(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat16(127.5)_AlwaysFails") { - let input = getFloat16(127.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat16(255.5)_NeverTraps") { - let input = getFloat16(255.5) - let actual = Int32(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat16(255.5)_AlwaysFails") { - let input = getFloat16(255.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat16(2047)_NeverTraps") { - let input = getFloat16(2047) - let actual = Int32(input) - expectEqual(2047, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat16(2047)_NeverFails") { - let input = getFloat16(2047) - let actual = Int32(exactly: input) - expectEqual(2047, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat16(-.infinity)_AlwaysTraps") { - let input = getFloat16(-.infinity) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat16(-.infinity)_AlwaysFails") { - let input = getFloat16(-.infinity) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat16(+.infinity)_AlwaysTraps") { - let input = getFloat16(+.infinity) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat16(+.infinity)_AlwaysFails") { - let input = getFloat16(+.infinity) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat16(-.nan)_AlwaysTraps") { - let input = getFloat16(-.nan) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat16(-.nan)_AlwaysFails") { - let input = getFloat16(-.nan) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat16(+.nan)_AlwaysTraps") { - let input = getFloat16(+.nan) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat16(+.nan)_AlwaysFails") { - let input = getFloat16(+.nan) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat16(-.signalingNaN)_AlwaysTraps") { - let input = getFloat16(-.signalingNaN) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat16(-.signalingNaN)_AlwaysFails") { - let input = getFloat16(-.signalingNaN) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat16(+.signalingNaN)_AlwaysTraps") { - let input = getFloat16(+.signalingNaN) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat16(+.signalingNaN)_AlwaysFails") { - let input = getFloat16(+.signalingNaN) - let actual = Int32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt32 +.test("FromFloat16_NeverTraps") +.forEach(in: [ + (getInt32(-2047), getFloat16(-2047)), + (getInt32(-128), getFloat16(-128.5)), + (getInt32(+0), getFloat16(-0.5)), + (getInt32(+0), getFloat16(+0)), + (getInt32(+0), getFloat16(-0)), + (getInt32(+0), getFloat16(+0.5)), + (getInt32(+127), getFloat16(+127.5)), + (getInt32(+255), getFloat16(+255.5)), + (getInt32(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, Int32($0.1)) +} + +FixedPointConversion_Debug32_ToInt32 +.test("FromFloat16_NeverFails") +.forEach(in: [ + (getInt32(-2047), getFloat16(-2047)), + (getInt32(+0), getFloat16(+0)), + (getInt32(+0), getFloat16(-0)), + (getInt32(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToInt32 +.test("FromFloat16_AlwaysTraps") +.forEach(in: [ + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int32($0)) +} + +FixedPointConversion_Debug32_ToInt32 +.test("FromFloat16_AlwaysFails") +.forEach(in: [ + getFloat16(-128.5), + getFloat16(-0.5), + getFloat16(+0.5), + getFloat16(+127.5), + getFloat16(+255.5), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectNil(Int32(exactly: $0)) } } #endif // Float16 //===----------------------------------------------------------------------===// -// MARK: Float32: (-16777215)...(16777215) +// MARK: Float32: (-16777215)...(+16777215) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt32.test("FromFloat32(-16777215)_NeverTraps") { - let input = getFloat32(-16777215) - let actual = Int32(input) - expectEqual(-16777215, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat32(-16777215)_NeverFails") { - let input = getFloat32(-16777215) - let actual = Int32(exactly: input) - expectEqual(-16777215, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat32(-32768.5)_NeverTraps") { - let input = getFloat32(-32768.5) - let actual = Int32(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat32(-32768.5)_AlwaysFails") { - let input = getFloat32(-32768.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat32(-128.5)_NeverTraps") { - let input = getFloat32(-128.5) - let actual = Int32(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat32(-128.5)_AlwaysFails") { - let input = getFloat32(-128.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat32(-0.5)_NeverTraps") { - let input = getFloat32(-0.5) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat32(-0.5)_AlwaysFails") { - let input = getFloat32(-0.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat32(-0.0)_NeverTraps") { - let input = getFloat32(-0.0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat32(-0.0)_NeverFails") { - let input = getFloat32(-0.0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat32(0.0)_NeverTraps") { - let input = getFloat32(0.0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat32(0.0)_NeverFails") { - let input = getFloat32(0.0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat32(0.5)_NeverTraps") { - let input = getFloat32(0.5) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat32(0.5)_AlwaysFails") { - let input = getFloat32(0.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat32(127.5)_NeverTraps") { - let input = getFloat32(127.5) - let actual = Int32(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat32(127.5)_AlwaysFails") { - let input = getFloat32(127.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat32(255.5)_NeverTraps") { - let input = getFloat32(255.5) - let actual = Int32(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat32(255.5)_AlwaysFails") { - let input = getFloat32(255.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat32(32767.5)_NeverTraps") { - let input = getFloat32(32767.5) - let actual = Int32(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat32(32767.5)_AlwaysFails") { - let input = getFloat32(32767.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat32(65535.5)_NeverTraps") { - let input = getFloat32(65535.5) - let actual = Int32(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat32(65535.5)_AlwaysFails") { - let input = getFloat32(65535.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat32(16777215)_NeverTraps") { - let input = getFloat32(16777215) - let actual = Int32(input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat32(16777215)_NeverFails") { - let input = getFloat32(16777215) - let actual = Int32(exactly: input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat32(-.infinity)_AlwaysTraps") { - let input = getFloat32(-.infinity) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat32(-.infinity)_AlwaysFails") { - let input = getFloat32(-.infinity) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat32(+.infinity)_AlwaysTraps") { - let input = getFloat32(+.infinity) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat32(+.infinity)_AlwaysFails") { - let input = getFloat32(+.infinity) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat32(-.nan)_AlwaysTraps") { - let input = getFloat32(-.nan) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat32(-.nan)_AlwaysFails") { - let input = getFloat32(-.nan) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat32(+.nan)_AlwaysTraps") { - let input = getFloat32(+.nan) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat32(+.nan)_AlwaysFails") { - let input = getFloat32(+.nan) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat32(-.signalingNaN)_AlwaysTraps") { - let input = getFloat32(-.signalingNaN) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat32(-.signalingNaN)_AlwaysFails") { - let input = getFloat32(-.signalingNaN) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat32(+.signalingNaN)_AlwaysTraps") { - let input = getFloat32(+.signalingNaN) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat32(+.signalingNaN)_AlwaysFails") { - let input = getFloat32(+.signalingNaN) - let actual = Int32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt32 +.test("FromFloat32_NeverTraps") +.forEach(in: [ + (getInt32(-16777215), getFloat32(-16777215)), + (getInt32(-32768), getFloat32(-32768.5)), + (getInt32(-128), getFloat32(-128.5)), + (getInt32(+0), getFloat32(-0.5)), + (getInt32(+0), getFloat32(+0)), + (getInt32(+0), getFloat32(-0)), + (getInt32(+0), getFloat32(+0.5)), + (getInt32(+127), getFloat32(+127.5)), + (getInt32(+255), getFloat32(+255.5)), + (getInt32(+32767), getFloat32(+32767.5)), + (getInt32(+65535), getFloat32(+65535.5)), + (getInt32(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, Int32($0.1)) +} + +FixedPointConversion_Debug32_ToInt32 +.test("FromFloat32_NeverFails") +.forEach(in: [ + (getInt32(-16777215), getFloat32(-16777215)), + (getInt32(+0), getFloat32(+0)), + (getInt32(+0), getFloat32(-0)), + (getInt32(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToInt32 +.test("FromFloat32_AlwaysTraps") +.forEach(in: [ + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int32($0)) +} + +FixedPointConversion_Debug32_ToInt32 +.test("FromFloat32_AlwaysFails") +.forEach(in: [ + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-0.5), + getFloat32(+0.5), + getFloat32(+127.5), + getFloat32(+255.5), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectNil(Int32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float64: (-9007199254740991)...(9007199254740991) +// MARK: Float64: (-9007199254740991)...(+9007199254740991) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(-9007199254740991)_AlwaysTraps") { - let input = getFloat64(-9007199254740991) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(-9007199254740991)_AlwaysFails") { - let input = getFloat64(-9007199254740991) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(-2147483649)_AlwaysTraps") { - let input = getFloat64(-2147483649) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(-2147483649)_AlwaysFails") { - let input = getFloat64(-2147483649) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(-2147483648)_NeverTraps") { - let input = getFloat64(-2147483648) - let actual = Int32(input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(-2147483648)_NeverFails") { - let input = getFloat64(-2147483648) - let actual = Int32(exactly: input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(-32768.5)_NeverTraps") { - let input = getFloat64(-32768.5) - let actual = Int32(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(-32768.5)_AlwaysFails") { - let input = getFloat64(-32768.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(-128.5)_NeverTraps") { - let input = getFloat64(-128.5) - let actual = Int32(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(-128.5)_AlwaysFails") { - let input = getFloat64(-128.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(-0.5)_NeverTraps") { - let input = getFloat64(-0.5) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(-0.5)_AlwaysFails") { - let input = getFloat64(-0.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(-0.0)_NeverTraps") { - let input = getFloat64(-0.0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(-0.0)_NeverFails") { - let input = getFloat64(-0.0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(0.0)_NeverTraps") { - let input = getFloat64(0.0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(0.0)_NeverFails") { - let input = getFloat64(0.0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(0.5)_NeverTraps") { - let input = getFloat64(0.5) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(0.5)_AlwaysFails") { - let input = getFloat64(0.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(127.5)_NeverTraps") { - let input = getFloat64(127.5) - let actual = Int32(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(127.5)_AlwaysFails") { - let input = getFloat64(127.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(255.5)_NeverTraps") { - let input = getFloat64(255.5) - let actual = Int32(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(255.5)_AlwaysFails") { - let input = getFloat64(255.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(32767.5)_NeverTraps") { - let input = getFloat64(32767.5) - let actual = Int32(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(32767.5)_AlwaysFails") { - let input = getFloat64(32767.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(65535.5)_NeverTraps") { - let input = getFloat64(65535.5) - let actual = Int32(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(65535.5)_AlwaysFails") { - let input = getFloat64(65535.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(2147483647)_NeverTraps") { - let input = getFloat64(2147483647) - let actual = Int32(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(2147483647)_NeverFails") { - let input = getFloat64(2147483647) - let actual = Int32(exactly: input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(2147483648)_AlwaysTraps") { - let input = getFloat64(2147483648) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(2147483648)_AlwaysFails") { - let input = getFloat64(2147483648) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(9007199254740991)_AlwaysTraps") { - let input = getFloat64(9007199254740991) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(9007199254740991)_AlwaysFails") { - let input = getFloat64(9007199254740991) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(-.infinity)_AlwaysTraps") { - let input = getFloat64(-.infinity) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(-.infinity)_AlwaysFails") { - let input = getFloat64(-.infinity) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(+.infinity)_AlwaysTraps") { - let input = getFloat64(+.infinity) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(+.infinity)_AlwaysFails") { - let input = getFloat64(+.infinity) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(-.nan)_AlwaysTraps") { - let input = getFloat64(-.nan) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(-.nan)_AlwaysFails") { - let input = getFloat64(-.nan) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(+.nan)_AlwaysTraps") { - let input = getFloat64(+.nan) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(+.nan)_AlwaysFails") { - let input = getFloat64(+.nan) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(-.signalingNaN)_AlwaysTraps") { - let input = getFloat64(-.signalingNaN) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(-.signalingNaN)_AlwaysFails") { - let input = getFloat64(-.signalingNaN) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(+.signalingNaN)_AlwaysTraps") { - let input = getFloat64(+.signalingNaN) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat64(+.signalingNaN)_AlwaysFails") { - let input = getFloat64(+.signalingNaN) - let actual = Int32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt32 +.test("FromFloat64_NeverTraps") +.forEach(in: [ + (getInt32(-2147483648), getFloat64(-2147483648)), + (getInt32(-32768), getFloat64(-32768.5)), + (getInt32(-128), getFloat64(-128.5)), + (getInt32(+0), getFloat64(-0.5)), + (getInt32(+0), getFloat64(-0)), + (getInt32(+0), getFloat64(+0)), + (getInt32(+0), getFloat64(+0.5)), + (getInt32(+127), getFloat64(+127.5)), + (getInt32(+255), getFloat64(+255.5)), + (getInt32(+32767), getFloat64(+32767.5)), + (getInt32(+65535), getFloat64(+65535.5)), + (getInt32(+2147483647), getFloat64(+2147483647)), +]) { + expectEqual($0.0, Int32($0.1)) +} + +FixedPointConversion_Debug32_ToInt32 +.test("FromFloat64_NeverFails") +.forEach(in: [ + (getInt32(-2147483648), getFloat64(-2147483648)), + (getInt32(+0), getFloat64(-0)), + (getInt32(+0), getFloat64(+0)), + (getInt32(+2147483647), getFloat64(+2147483647)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToInt32 +.test("FromFloat64_AlwaysTraps") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-2147483649), + getFloat64(+2147483648), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int32($0)) +} + +FixedPointConversion_Debug32_ToInt32 +.test("FromFloat64_AlwaysFails") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-2147483649), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-0.5), + getFloat64(+0.5), + getFloat64(+127.5), + getFloat64(+255.5), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(+2147483648), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectNil(Int32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float80: (-18446744073709551615)...(18446744073709551615) +// MARK: Float80: (-18446744073709551615)...(+18446744073709551615) //===----------------------------------------------------------------------===// #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(-18446744073709551615)_AlwaysTraps") { - let input = getFloat80(-18446744073709551615) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(-18446744073709551615)_AlwaysFails") { - let input = getFloat80(-18446744073709551615) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(-2147483649)_AlwaysTraps") { - let input = getFloat80(-2147483649) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(-2147483649)_AlwaysFails") { - let input = getFloat80(-2147483649) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(-2147483648)_NeverTraps") { - let input = getFloat80(-2147483648) - let actual = Int32(input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(-2147483648)_NeverFails") { - let input = getFloat80(-2147483648) - let actual = Int32(exactly: input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(-32768.5)_NeverTraps") { - let input = getFloat80(-32768.5) - let actual = Int32(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(-32768.5)_AlwaysFails") { - let input = getFloat80(-32768.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(-128.5)_NeverTraps") { - let input = getFloat80(-128.5) - let actual = Int32(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(-128.5)_AlwaysFails") { - let input = getFloat80(-128.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(-0.5)_NeverTraps") { - let input = getFloat80(-0.5) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(-0.5)_AlwaysFails") { - let input = getFloat80(-0.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(-0.0)_NeverTraps") { - let input = getFloat80(-0.0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(-0.0)_NeverFails") { - let input = getFloat80(-0.0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(0.0)_NeverTraps") { - let input = getFloat80(0.0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(0.0)_NeverFails") { - let input = getFloat80(0.0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(0.5)_NeverTraps") { - let input = getFloat80(0.5) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(0.5)_AlwaysFails") { - let input = getFloat80(0.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(127.5)_NeverTraps") { - let input = getFloat80(127.5) - let actual = Int32(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(127.5)_AlwaysFails") { - let input = getFloat80(127.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(255.5)_NeverTraps") { - let input = getFloat80(255.5) - let actual = Int32(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(255.5)_AlwaysFails") { - let input = getFloat80(255.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(32767.5)_NeverTraps") { - let input = getFloat80(32767.5) - let actual = Int32(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(32767.5)_AlwaysFails") { - let input = getFloat80(32767.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(65535.5)_NeverTraps") { - let input = getFloat80(65535.5) - let actual = Int32(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(65535.5)_AlwaysFails") { - let input = getFloat80(65535.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(2147483647)_NeverTraps") { - let input = getFloat80(2147483647) - let actual = Int32(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(2147483647)_NeverFails") { - let input = getFloat80(2147483647) - let actual = Int32(exactly: input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(2147483648)_AlwaysTraps") { - let input = getFloat80(2147483648) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(2147483648)_AlwaysFails") { - let input = getFloat80(2147483648) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(18446744073709551615)_AlwaysTraps") { - let input = getFloat80(18446744073709551615) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(18446744073709551615)_AlwaysFails") { - let input = getFloat80(18446744073709551615) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(-.infinity)_AlwaysTraps") { - let input = getFloat80(-.infinity) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(-.infinity)_AlwaysFails") { - let input = getFloat80(-.infinity) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(+.infinity)_AlwaysTraps") { - let input = getFloat80(+.infinity) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(+.infinity)_AlwaysFails") { - let input = getFloat80(+.infinity) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(-.nan)_AlwaysTraps") { - let input = getFloat80(-.nan) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(-.nan)_AlwaysFails") { - let input = getFloat80(-.nan) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(+.nan)_AlwaysTraps") { - let input = getFloat80(+.nan) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(+.nan)_AlwaysFails") { - let input = getFloat80(+.nan) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(-.signalingNaN)_AlwaysTraps") { - let input = getFloat80(-.signalingNaN) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(-.signalingNaN)_AlwaysFails") { - let input = getFloat80(-.signalingNaN) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(+.signalingNaN)_AlwaysTraps") { - let input = getFloat80(+.signalingNaN) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt32.test("FromFloat80(+.signalingNaN)_AlwaysFails") { - let input = getFloat80(+.signalingNaN) - let actual = Int32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt32 +.test("FromFloat80_NeverTraps") +.forEach(in: [ + (getInt32(-2147483648), getFloat80(-2147483648)), + (getInt32(-32768), getFloat80(-32768.5)), + (getInt32(-128), getFloat80(-128.5)), + (getInt32(+0), getFloat80(-0.5)), + (getInt32(+0), getFloat80(-0)), + (getInt32(+0), getFloat80(+0)), + (getInt32(+0), getFloat80(+0.5)), + (getInt32(+127), getFloat80(+127.5)), + (getInt32(+255), getFloat80(+255.5)), + (getInt32(+32767), getFloat80(+32767.5)), + (getInt32(+65535), getFloat80(+65535.5)), + (getInt32(+2147483647), getFloat80(+2147483647)), +]) { + expectEqual($0.0, Int32($0.1)) +} + +FixedPointConversion_Debug32_ToInt32 +.test("FromFloat80_NeverFails") +.forEach(in: [ + (getInt32(-2147483648), getFloat80(-2147483648)), + (getInt32(+0), getFloat80(-0)), + (getInt32(+0), getFloat80(+0)), + (getInt32(+2147483647), getFloat80(+2147483647)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToInt32 +.test("FromFloat80_AlwaysTraps") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-2147483649), + getFloat80(+2147483648), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int32($0)) +} + +FixedPointConversion_Debug32_ToInt32 +.test("FromFloat80_AlwaysFails") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-2147483649), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-0.5), + getFloat80(+0.5), + getFloat80(+127.5), + getFloat80(+255.5), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(+2147483648), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectNil(Int32(exactly: $0)) } #endif // Float80 diff --git a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug32_ToInt64.swift b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug32_ToInt64.swift index 25dacf456573c..c67ca833f4e72 100644 --- a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug32_ToInt64.swift +++ b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug32_ToInt64.swift @@ -14,1330 +14,543 @@ import StdlibUnittest -let FixedPointConversion_Debug32_ToInt64 = TestSuite("FixedPointConversion_Debug32_ToInt64") +let FixedPointConversion_Debug32_ToInt64 = TestSuite( + "FixedPointConversion_Debug32_ToInt64" +) //===----------------------------------------------------------------------===// -// MARK: UInt8: (0)...(255) +// MARK: UInt8: (+0)...(+255) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt64.test("FromUInt8(0)_NeverTraps") { - let input = getUInt8(0) - let actual = Int64(input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToInt64 +.test("FromUInt8_NeverTraps") +.forEach(in: [ + (getInt64(+0), getUInt8(+0)), + (getInt64(+255), getUInt8(+255)), +]) { + expectEqual($0.0, Int64($0.1)) } -FixedPointConversion_Debug32_ToInt64.test("FromUInt8(0)_NeverFails") { - let input = getUInt8(0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromUInt8(255)_NeverTraps") { - let input = getUInt8(255) - let actual = Int64(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromUInt8(255)_NeverFails") { - let input = getUInt8(255) - let actual = Int64(exactly: input) - expectEqual(255, actual) +FixedPointConversion_Debug32_ToInt64 +.test("FromUInt8_NeverFails") +.forEach(in: [ + (getInt64(+0), getUInt8(+0)), + (getInt64(+255), getUInt8(+255)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int8: (-128)...(127) +// MARK: Int8: (-128)...(+127) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt64.test("FromInt8(-128)_NeverTraps") { - let input = getInt8(-128) - let actual = Int64(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromInt8(-128)_NeverFails") { - let input = getInt8(-128) - let actual = Int64(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromInt8(0)_NeverTraps") { - let input = getInt8(0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromInt8(0)_NeverFails") { - let input = getInt8(0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromInt8(127)_NeverTraps") { - let input = getInt8(127) - let actual = Int64(input) - expectEqual(127, actual) +FixedPointConversion_Debug32_ToInt64 +.test("FromInt8_NeverTraps") +.forEach(in: [ + (getInt64(-128), getInt8(-128)), + (getInt64(+0), getInt8(+0)), + (getInt64(+127), getInt8(+127)), +]) { + expectEqual($0.0, Int64($0.1)) } -FixedPointConversion_Debug32_ToInt64.test("FromInt8(127)_NeverFails") { - let input = getInt8(127) - let actual = Int64(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Debug32_ToInt64 +.test("FromInt8_NeverFails") +.forEach(in: [ + (getInt64(-128), getInt8(-128)), + (getInt64(+0), getInt8(+0)), + (getInt64(+127), getInt8(+127)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt16: (0)...(65535) +// MARK: UInt16: (+0)...(+65535) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt64.test("FromUInt16(0)_NeverTraps") { - let input = getUInt16(0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromUInt16(0)_NeverFails") { - let input = getUInt16(0) - let actual = Int64(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToInt64 +.test("FromUInt16_NeverTraps") +.forEach(in: [ + (getInt64(+0), getUInt16(+0)), + (getInt64(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, Int64($0.1)) } -FixedPointConversion_Debug32_ToInt64.test("FromUInt16(65535)_NeverTraps") { - let input = getUInt16(65535) - let actual = Int64(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromUInt16(65535)_NeverFails") { - let input = getUInt16(65535) - let actual = Int64(exactly: input) - expectEqual(65535, actual) +FixedPointConversion_Debug32_ToInt64 +.test("FromUInt16_NeverFails") +.forEach(in: [ + (getInt64(+0), getUInt16(+0)), + (getInt64(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int16: (-32768)...(32767) +// MARK: Int16: (-32768)...(+32767) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt64.test("FromInt16(-32768)_NeverTraps") { - let input = getInt16(-32768) - let actual = Int64(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromInt16(-32768)_NeverFails") { - let input = getInt16(-32768) - let actual = Int64(exactly: input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromInt16(0)_NeverTraps") { - let input = getInt16(0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromInt16(0)_NeverFails") { - let input = getInt16(0) - let actual = Int64(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToInt64 +.test("FromInt16_NeverTraps") +.forEach(in: [ + (getInt64(-32768), getInt16(-32768)), + (getInt64(+0), getInt16(+0)), + (getInt64(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, Int64($0.1)) } -FixedPointConversion_Debug32_ToInt64.test("FromInt16(32767)_NeverTraps") { - let input = getInt16(32767) - let actual = Int64(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromInt16(32767)_NeverFails") { - let input = getInt16(32767) - let actual = Int64(exactly: input) - expectEqual(32767, actual) +FixedPointConversion_Debug32_ToInt64 +.test("FromInt16_NeverFails") +.forEach(in: [ + (getInt64(-32768), getInt16(-32768)), + (getInt64(+0), getInt16(+0)), + (getInt64(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt32: (0)...(4294967295) +// MARK: UInt32: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt64.test("FromUInt32(0)_NeverTraps") { - let input = getUInt32(0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromUInt32(0)_NeverFails") { - let input = getUInt32(0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromUInt32(4294967295)_NeverTraps") { - let input = getUInt32(4294967295) - let actual = Int64(input) - expectEqual(4294967295, actual) +FixedPointConversion_Debug32_ToInt64 +.test("FromUInt32_NeverTraps") +.forEach(in: [ + (getInt64(+0), getUInt32(+0)), + (getInt64(+4294967295), getUInt32(+4294967295)), +]) { + expectEqual($0.0, Int64($0.1)) } -FixedPointConversion_Debug32_ToInt64.test("FromUInt32(4294967295)_NeverFails") { - let input = getUInt32(4294967295) - let actual = Int64(exactly: input) - expectEqual(4294967295, actual) +FixedPointConversion_Debug32_ToInt64 +.test("FromUInt32_NeverFails") +.forEach(in: [ + (getInt64(+0), getUInt32(+0)), + (getInt64(+4294967295), getUInt32(+4294967295)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int32: (-2147483648)...(2147483647) +// MARK: Int32: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt64.test("FromInt32(-2147483648)_NeverTraps") { - let input = getInt32(-2147483648) - let actual = Int64(input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromInt32(-2147483648)_NeverFails") { - let input = getInt32(-2147483648) - let actual = Int64(exactly: input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromInt32(0)_NeverTraps") { - let input = getInt32(0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromInt32(0)_NeverFails") { - let input = getInt32(0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromInt32(2147483647)_NeverTraps") { - let input = getInt32(2147483647) - let actual = Int64(input) - expectEqual(2147483647, actual) +FixedPointConversion_Debug32_ToInt64 +.test("FromInt32_NeverTraps") +.forEach(in: [ + (getInt64(-2147483648), getInt32(-2147483648)), + (getInt64(+0), getInt32(+0)), + (getInt64(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, Int64($0.1)) } -FixedPointConversion_Debug32_ToInt64.test("FromInt32(2147483647)_NeverFails") { - let input = getInt32(2147483647) - let actual = Int64(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Debug32_ToInt64 +.test("FromInt32_NeverFails") +.forEach(in: [ + (getInt64(-2147483648), getInt32(-2147483648)), + (getInt64(+0), getInt32(+0)), + (getInt64(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt64: (0)...(18446744073709551615) +// MARK: UInt64: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt64.test("FromUInt64(0)_NeverTraps") { - let input = getUInt64(0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromUInt64(0)_NeverFails") { - let input = getUInt64(0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromUInt64(9223372036854775807)_NeverTraps") { - let input = getUInt64(9223372036854775807) - let actual = Int64(input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromUInt64(9223372036854775807)_NeverFails") { - let input = getUInt64(9223372036854775807) - let actual = Int64(exactly: input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromUInt64(9223372036854775808)_AlwaysTraps") { - let input = getUInt64(9223372036854775808) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } +FixedPointConversion_Debug32_ToInt64 +.test("FromUInt64_NeverTraps") +.forEach(in: [ + (getInt64(+0), getUInt64(+0)), + (getInt64(+9223372036854775807), getUInt64(+9223372036854775807)), +]) { + expectEqual($0.0, Int64($0.1)) } -FixedPointConversion_Debug32_ToInt64.test("FromUInt64(9223372036854775808)_AlwaysFails") { - let input = getUInt64(9223372036854775808) - let actual = Int64(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt64 +.test("FromUInt64_NeverFails") +.forEach(in: [ + (getInt64(+0), getUInt64(+0)), + (getInt64(+9223372036854775807), getUInt64(+9223372036854775807)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) } -FixedPointConversion_Debug32_ToInt64.test("FromUInt64(18446744073709551615)_AlwaysTraps") { - let input = getUInt64(18446744073709551615) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } +FixedPointConversion_Debug32_ToInt64 +.test("FromUInt64_AlwaysTraps") +.forEach(in: [ + getUInt64(+9223372036854775808), + getUInt64(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(Int64($0)) } -FixedPointConversion_Debug32_ToInt64.test("FromUInt64(18446744073709551615)_AlwaysFails") { - let input = getUInt64(18446744073709551615) - let actual = Int64(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt64 +.test("FromUInt64_AlwaysFails") +.forEach(in: [ + getUInt64(+9223372036854775808), + getUInt64(+18446744073709551615), +]) { + expectNil(Int64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int64: (-9223372036854775808)...(9223372036854775807) +// MARK: Int64: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt64.test("FromInt64(-9223372036854775808)_NeverTraps") { - let input = getInt64(-9223372036854775808) - let actual = Int64(input) - expectEqual(-9223372036854775808, actual) +FixedPointConversion_Debug32_ToInt64 +.test("FromInt64_NeverTraps") +.forEach(in: [ + (getInt64(-9223372036854775808), getInt64(-9223372036854775808)), + (getInt64(+0), getInt64(+0)), + (getInt64(+9223372036854775807), getInt64(+9223372036854775807)), +]) { + expectEqual($0.0, Int64($0.1)) } -FixedPointConversion_Debug32_ToInt64.test("FromInt64(-9223372036854775808)_NeverFails") { - let input = getInt64(-9223372036854775808) - let actual = Int64(exactly: input) - expectEqual(-9223372036854775808, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromInt64(0)_NeverTraps") { - let input = getInt64(0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromInt64(0)_NeverFails") { - let input = getInt64(0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromInt64(9223372036854775807)_NeverTraps") { - let input = getInt64(9223372036854775807) - let actual = Int64(input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromInt64(9223372036854775807)_NeverFails") { - let input = getInt64(9223372036854775807) - let actual = Int64(exactly: input) - expectEqual(9223372036854775807, actual) +FixedPointConversion_Debug32_ToInt64 +.test("FromInt64_NeverFails") +.forEach(in: [ + (getInt64(-9223372036854775808), getInt64(-9223372036854775808)), + (getInt64(+0), getInt64(+0)), + (getInt64(+9223372036854775807), getInt64(+9223372036854775807)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt: (0)...(4294967295) +// MARK: UInt: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt64.test("FromUInt(0)_NeverTraps") { - let input = getUInt(0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromUInt(0)_NeverFails") { - let input = getUInt(0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromUInt(4294967295)_NeverTraps") { - let input = getUInt(4294967295) - let actual = Int64(input) - expectEqual(4294967295, actual) +FixedPointConversion_Debug32_ToInt64 +.test("FromUInt_NeverTraps") +.forEach(in: [ + (getInt64(+0), getUInt(+0)), + (getInt64(+4294967295), getUInt(+4294967295)), +]) { + expectEqual($0.0, Int64($0.1)) } -FixedPointConversion_Debug32_ToInt64.test("FromUInt(4294967295)_NeverFails") { - let input = getUInt(4294967295) - let actual = Int64(exactly: input) - expectEqual(4294967295, actual) +FixedPointConversion_Debug32_ToInt64 +.test("FromUInt_NeverFails") +.forEach(in: [ + (getInt64(+0), getUInt(+0)), + (getInt64(+4294967295), getUInt(+4294967295)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int: (-2147483648)...(2147483647) +// MARK: Int: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt64.test("FromInt(-2147483648)_NeverTraps") { - let input = getInt(-2147483648) - let actual = Int64(input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromInt(-2147483648)_NeverFails") { - let input = getInt(-2147483648) - let actual = Int64(exactly: input) - expectEqual(-2147483648, actual) +FixedPointConversion_Debug32_ToInt64 +.test("FromInt_NeverTraps") +.forEach(in: [ + (getInt64(-2147483648), getInt(-2147483648)), + (getInt64(+0), getInt(+0)), + (getInt64(+2147483647), getInt(+2147483647)), +]) { + expectEqual($0.0, Int64($0.1)) } -FixedPointConversion_Debug32_ToInt64.test("FromInt(0)_NeverTraps") { - let input = getInt(0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromInt(0)_NeverFails") { - let input = getInt(0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromInt(2147483647)_NeverTraps") { - let input = getInt(2147483647) - let actual = Int64(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromInt(2147483647)_NeverFails") { - let input = getInt(2147483647) - let actual = Int64(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Debug32_ToInt64 +.test("FromInt_NeverFails") +.forEach(in: [ + (getInt64(-2147483648), getInt(-2147483648)), + (getInt64(+0), getInt(+0)), + (getInt64(+2147483647), getInt(+2147483647)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Float16: (-2047)...(2047) +// MARK: Float16: (-2047)...(+2047) //===----------------------------------------------------------------------===// #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -FixedPointConversion_Debug32_ToInt64.test("FromFloat16(-2047)_NeverTraps") { - let input = getFloat16(-2047) - let actual = Int64(input) - expectEqual(-2047, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat16(-2047)_NeverFails") { - let input = getFloat16(-2047) - let actual = Int64(exactly: input) - expectEqual(-2047, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat16(-128.5)_NeverTraps") { - let input = getFloat16(-128.5) - let actual = Int64(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat16(-128.5)_AlwaysFails") { - let input = getFloat16(-128.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat16(-0.5)_NeverTraps") { - let input = getFloat16(-0.5) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat16(-0.5)_AlwaysFails") { - let input = getFloat16(-0.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat16(-0.0)_NeverTraps") { - let input = getFloat16(-0.0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat16(-0.0)_NeverFails") { - let input = getFloat16(-0.0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat16(0.0)_NeverTraps") { - let input = getFloat16(0.0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat16(0.0)_NeverFails") { - let input = getFloat16(0.0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat16(0.5)_NeverTraps") { - let input = getFloat16(0.5) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat16(0.5)_AlwaysFails") { - let input = getFloat16(0.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat16(127.5)_NeverTraps") { - let input = getFloat16(127.5) - let actual = Int64(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat16(127.5)_AlwaysFails") { - let input = getFloat16(127.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat16(255.5)_NeverTraps") { - let input = getFloat16(255.5) - let actual = Int64(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat16(255.5)_AlwaysFails") { - let input = getFloat16(255.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat16(2047)_NeverTraps") { - let input = getFloat16(2047) - let actual = Int64(input) - expectEqual(2047, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat16(2047)_NeverFails") { - let input = getFloat16(2047) - let actual = Int64(exactly: input) - expectEqual(2047, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat16(-.infinity)_AlwaysTraps") { - let input = getFloat16(-.infinity) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat16(-.infinity)_AlwaysFails") { - let input = getFloat16(-.infinity) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat16(+.infinity)_AlwaysTraps") { - let input = getFloat16(+.infinity) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat16(+.infinity)_AlwaysFails") { - let input = getFloat16(+.infinity) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat16(-.nan)_AlwaysTraps") { - let input = getFloat16(-.nan) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat16(-.nan)_AlwaysFails") { - let input = getFloat16(-.nan) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat16(+.nan)_AlwaysTraps") { - let input = getFloat16(+.nan) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat16(+.nan)_AlwaysFails") { - let input = getFloat16(+.nan) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat16(-.signalingNaN)_AlwaysTraps") { - let input = getFloat16(-.signalingNaN) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat16(-.signalingNaN)_AlwaysFails") { - let input = getFloat16(-.signalingNaN) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat16(+.signalingNaN)_AlwaysTraps") { - let input = getFloat16(+.signalingNaN) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat16(+.signalingNaN)_AlwaysFails") { - let input = getFloat16(+.signalingNaN) - let actual = Int64(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt64 +.test("FromFloat16_NeverTraps") +.forEach(in: [ + (getInt64(-2047), getFloat16(-2047)), + (getInt64(-128), getFloat16(-128.5)), + (getInt64(+0), getFloat16(-0.5)), + (getInt64(+0), getFloat16(+0)), + (getInt64(+0), getFloat16(-0)), + (getInt64(+0), getFloat16(+0.5)), + (getInt64(+127), getFloat16(+127.5)), + (getInt64(+255), getFloat16(+255.5)), + (getInt64(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, Int64($0.1)) +} + +FixedPointConversion_Debug32_ToInt64 +.test("FromFloat16_NeverFails") +.forEach(in: [ + (getInt64(-2047), getFloat16(-2047)), + (getInt64(+0), getFloat16(+0)), + (getInt64(+0), getFloat16(-0)), + (getInt64(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToInt64 +.test("FromFloat16_AlwaysTraps") +.forEach(in: [ + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int64($0)) +} + +FixedPointConversion_Debug32_ToInt64 +.test("FromFloat16_AlwaysFails") +.forEach(in: [ + getFloat16(-128.5), + getFloat16(-0.5), + getFloat16(+0.5), + getFloat16(+127.5), + getFloat16(+255.5), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectNil(Int64(exactly: $0)) } } #endif // Float16 //===----------------------------------------------------------------------===// -// MARK: Float32: (-16777215)...(16777215) +// MARK: Float32: (-16777215)...(+16777215) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt64.test("FromFloat32(-16777215)_NeverTraps") { - let input = getFloat32(-16777215) - let actual = Int64(input) - expectEqual(-16777215, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat32(-16777215)_NeverFails") { - let input = getFloat32(-16777215) - let actual = Int64(exactly: input) - expectEqual(-16777215, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat32(-32768.5)_NeverTraps") { - let input = getFloat32(-32768.5) - let actual = Int64(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat32(-32768.5)_AlwaysFails") { - let input = getFloat32(-32768.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat32(-128.5)_NeverTraps") { - let input = getFloat32(-128.5) - let actual = Int64(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat32(-128.5)_AlwaysFails") { - let input = getFloat32(-128.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat32(-0.5)_NeverTraps") { - let input = getFloat32(-0.5) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat32(-0.5)_AlwaysFails") { - let input = getFloat32(-0.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat32(-0.0)_NeverTraps") { - let input = getFloat32(-0.0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat32(-0.0)_NeverFails") { - let input = getFloat32(-0.0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat32(0.0)_NeverTraps") { - let input = getFloat32(0.0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat32(0.0)_NeverFails") { - let input = getFloat32(0.0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat32(0.5)_NeverTraps") { - let input = getFloat32(0.5) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat32(0.5)_AlwaysFails") { - let input = getFloat32(0.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat32(127.5)_NeverTraps") { - let input = getFloat32(127.5) - let actual = Int64(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat32(127.5)_AlwaysFails") { - let input = getFloat32(127.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat32(255.5)_NeverTraps") { - let input = getFloat32(255.5) - let actual = Int64(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat32(255.5)_AlwaysFails") { - let input = getFloat32(255.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat32(32767.5)_NeverTraps") { - let input = getFloat32(32767.5) - let actual = Int64(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat32(32767.5)_AlwaysFails") { - let input = getFloat32(32767.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat32(65535.5)_NeverTraps") { - let input = getFloat32(65535.5) - let actual = Int64(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat32(65535.5)_AlwaysFails") { - let input = getFloat32(65535.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat32(16777215)_NeverTraps") { - let input = getFloat32(16777215) - let actual = Int64(input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat32(16777215)_NeverFails") { - let input = getFloat32(16777215) - let actual = Int64(exactly: input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat32(-.infinity)_AlwaysTraps") { - let input = getFloat32(-.infinity) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat32(-.infinity)_AlwaysFails") { - let input = getFloat32(-.infinity) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat32(+.infinity)_AlwaysTraps") { - let input = getFloat32(+.infinity) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat32(+.infinity)_AlwaysFails") { - let input = getFloat32(+.infinity) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat32(-.nan)_AlwaysTraps") { - let input = getFloat32(-.nan) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat32(-.nan)_AlwaysFails") { - let input = getFloat32(-.nan) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat32(+.nan)_AlwaysTraps") { - let input = getFloat32(+.nan) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat32(+.nan)_AlwaysFails") { - let input = getFloat32(+.nan) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat32(-.signalingNaN)_AlwaysTraps") { - let input = getFloat32(-.signalingNaN) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat32(-.signalingNaN)_AlwaysFails") { - let input = getFloat32(-.signalingNaN) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat32(+.signalingNaN)_AlwaysTraps") { - let input = getFloat32(+.signalingNaN) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat32(+.signalingNaN)_AlwaysFails") { - let input = getFloat32(+.signalingNaN) - let actual = Int64(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt64 +.test("FromFloat32_NeverTraps") +.forEach(in: [ + (getInt64(-16777215), getFloat32(-16777215)), + (getInt64(-32768), getFloat32(-32768.5)), + (getInt64(-128), getFloat32(-128.5)), + (getInt64(+0), getFloat32(-0.5)), + (getInt64(+0), getFloat32(+0)), + (getInt64(+0), getFloat32(-0)), + (getInt64(+0), getFloat32(+0.5)), + (getInt64(+127), getFloat32(+127.5)), + (getInt64(+255), getFloat32(+255.5)), + (getInt64(+32767), getFloat32(+32767.5)), + (getInt64(+65535), getFloat32(+65535.5)), + (getInt64(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, Int64($0.1)) +} + +FixedPointConversion_Debug32_ToInt64 +.test("FromFloat32_NeverFails") +.forEach(in: [ + (getInt64(-16777215), getFloat32(-16777215)), + (getInt64(+0), getFloat32(+0)), + (getInt64(+0), getFloat32(-0)), + (getInt64(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToInt64 +.test("FromFloat32_AlwaysTraps") +.forEach(in: [ + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int64($0)) +} + +FixedPointConversion_Debug32_ToInt64 +.test("FromFloat32_AlwaysFails") +.forEach(in: [ + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-0.5), + getFloat32(+0.5), + getFloat32(+127.5), + getFloat32(+255.5), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectNil(Int64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float64: (-9007199254740991)...(9007199254740991) +// MARK: Float64: (-9007199254740991)...(+9007199254740991) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt64.test("FromFloat64(-9007199254740991)_NeverTraps") { - let input = getFloat64(-9007199254740991) - let actual = Int64(input) - expectEqual(-9007199254740991, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat64(-9007199254740991)_NeverFails") { - let input = getFloat64(-9007199254740991) - let actual = Int64(exactly: input) - expectEqual(-9007199254740991, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat64(-32768.5)_NeverTraps") { - let input = getFloat64(-32768.5) - let actual = Int64(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat64(-32768.5)_AlwaysFails") { - let input = getFloat64(-32768.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat64(-128.5)_NeverTraps") { - let input = getFloat64(-128.5) - let actual = Int64(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat64(-128.5)_AlwaysFails") { - let input = getFloat64(-128.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat64(-0.5)_NeverTraps") { - let input = getFloat64(-0.5) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat64(-0.5)_AlwaysFails") { - let input = getFloat64(-0.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat64(-0.0)_NeverTraps") { - let input = getFloat64(-0.0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat64(-0.0)_NeverFails") { - let input = getFloat64(-0.0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat64(0.0)_NeverTraps") { - let input = getFloat64(0.0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat64(0.0)_NeverFails") { - let input = getFloat64(0.0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat64(0.5)_NeverTraps") { - let input = getFloat64(0.5) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat64(0.5)_AlwaysFails") { - let input = getFloat64(0.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat64(127.5)_NeverTraps") { - let input = getFloat64(127.5) - let actual = Int64(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat64(127.5)_AlwaysFails") { - let input = getFloat64(127.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat64(255.5)_NeverTraps") { - let input = getFloat64(255.5) - let actual = Int64(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat64(255.5)_AlwaysFails") { - let input = getFloat64(255.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat64(32767.5)_NeverTraps") { - let input = getFloat64(32767.5) - let actual = Int64(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat64(32767.5)_AlwaysFails") { - let input = getFloat64(32767.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat64(65535.5)_NeverTraps") { - let input = getFloat64(65535.5) - let actual = Int64(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat64(65535.5)_AlwaysFails") { - let input = getFloat64(65535.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat64(9007199254740991)_NeverTraps") { - let input = getFloat64(9007199254740991) - let actual = Int64(input) - expectEqual(9007199254740991, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat64(9007199254740991)_NeverFails") { - let input = getFloat64(9007199254740991) - let actual = Int64(exactly: input) - expectEqual(9007199254740991, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat64(-.infinity)_AlwaysTraps") { - let input = getFloat64(-.infinity) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat64(-.infinity)_AlwaysFails") { - let input = getFloat64(-.infinity) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat64(+.infinity)_AlwaysTraps") { - let input = getFloat64(+.infinity) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat64(+.infinity)_AlwaysFails") { - let input = getFloat64(+.infinity) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat64(-.nan)_AlwaysTraps") { - let input = getFloat64(-.nan) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat64(-.nan)_AlwaysFails") { - let input = getFloat64(-.nan) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat64(+.nan)_AlwaysTraps") { - let input = getFloat64(+.nan) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat64(+.nan)_AlwaysFails") { - let input = getFloat64(+.nan) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat64(-.signalingNaN)_AlwaysTraps") { - let input = getFloat64(-.signalingNaN) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat64(-.signalingNaN)_AlwaysFails") { - let input = getFloat64(-.signalingNaN) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat64(+.signalingNaN)_AlwaysTraps") { - let input = getFloat64(+.signalingNaN) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat64(+.signalingNaN)_AlwaysFails") { - let input = getFloat64(+.signalingNaN) - let actual = Int64(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt64 +.test("FromFloat64_NeverTraps") +.forEach(in: [ + (getInt64(-9007199254740991), getFloat64(-9007199254740991)), + (getInt64(-32768), getFloat64(-32768.5)), + (getInt64(-128), getFloat64(-128.5)), + (getInt64(+0), getFloat64(-0.5)), + (getInt64(+0), getFloat64(+0)), + (getInt64(+0), getFloat64(-0)), + (getInt64(+0), getFloat64(+0.5)), + (getInt64(+127), getFloat64(+127.5)), + (getInt64(+255), getFloat64(+255.5)), + (getInt64(+32767), getFloat64(+32767.5)), + (getInt64(+65535), getFloat64(+65535.5)), + (getInt64(+9007199254740991), getFloat64(+9007199254740991)), +]) { + expectEqual($0.0, Int64($0.1)) +} + +FixedPointConversion_Debug32_ToInt64 +.test("FromFloat64_NeverFails") +.forEach(in: [ + (getInt64(-9007199254740991), getFloat64(-9007199254740991)), + (getInt64(+0), getFloat64(+0)), + (getInt64(+0), getFloat64(-0)), + (getInt64(+9007199254740991), getFloat64(+9007199254740991)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToInt64 +.test("FromFloat64_AlwaysTraps") +.forEach(in: [ + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int64($0)) +} + +FixedPointConversion_Debug32_ToInt64 +.test("FromFloat64_AlwaysFails") +.forEach(in: [ + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-0.5), + getFloat64(+0.5), + getFloat64(+127.5), + getFloat64(+255.5), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectNil(Int64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float80: (-18446744073709551615)...(18446744073709551615) +// MARK: Float80: (-18446744073709551615)...(+18446744073709551615) //===----------------------------------------------------------------------===// #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(-18446744073709551615)_AlwaysTraps") { - let input = getFloat80(-18446744073709551615) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(-18446744073709551615)_AlwaysFails") { - let input = getFloat80(-18446744073709551615) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(-9223372036854775809)_AlwaysTraps") { - let input = getFloat80(-9223372036854775809) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(-9223372036854775809)_AlwaysFails") { - let input = getFloat80(-9223372036854775809) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(-9223372036854775808)_NeverTraps") { - let input = getFloat80(-9223372036854775808) - let actual = Int64(input) - expectEqual(-9223372036854775808, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(-9223372036854775808)_NeverFails") { - let input = getFloat80(-9223372036854775808) - let actual = Int64(exactly: input) - expectEqual(-9223372036854775808, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(-32768.5)_NeverTraps") { - let input = getFloat80(-32768.5) - let actual = Int64(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(-32768.5)_AlwaysFails") { - let input = getFloat80(-32768.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(-128.5)_NeverTraps") { - let input = getFloat80(-128.5) - let actual = Int64(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(-128.5)_AlwaysFails") { - let input = getFloat80(-128.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(-0.5)_NeverTraps") { - let input = getFloat80(-0.5) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(-0.5)_AlwaysFails") { - let input = getFloat80(-0.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(-0.0)_NeverTraps") { - let input = getFloat80(-0.0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(-0.0)_NeverFails") { - let input = getFloat80(-0.0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(0.0)_NeverTraps") { - let input = getFloat80(0.0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(0.0)_NeverFails") { - let input = getFloat80(0.0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(0.5)_NeverTraps") { - let input = getFloat80(0.5) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(0.5)_AlwaysFails") { - let input = getFloat80(0.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(127.5)_NeverTraps") { - let input = getFloat80(127.5) - let actual = Int64(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(127.5)_AlwaysFails") { - let input = getFloat80(127.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(255.5)_NeverTraps") { - let input = getFloat80(255.5) - let actual = Int64(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(255.5)_AlwaysFails") { - let input = getFloat80(255.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(32767.5)_NeverTraps") { - let input = getFloat80(32767.5) - let actual = Int64(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(32767.5)_AlwaysFails") { - let input = getFloat80(32767.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(65535.5)_NeverTraps") { - let input = getFloat80(65535.5) - let actual = Int64(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(65535.5)_AlwaysFails") { - let input = getFloat80(65535.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(9223372036854775807)_NeverTraps") { - let input = getFloat80(9223372036854775807) - let actual = Int64(input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(9223372036854775807)_NeverFails") { - let input = getFloat80(9223372036854775807) - let actual = Int64(exactly: input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(9223372036854775808)_AlwaysTraps") { - let input = getFloat80(9223372036854775808) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(9223372036854775808)_AlwaysFails") { - let input = getFloat80(9223372036854775808) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(18446744073709551615)_AlwaysTraps") { - let input = getFloat80(18446744073709551615) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(18446744073709551615)_AlwaysFails") { - let input = getFloat80(18446744073709551615) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(-.infinity)_AlwaysTraps") { - let input = getFloat80(-.infinity) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(-.infinity)_AlwaysFails") { - let input = getFloat80(-.infinity) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(+.infinity)_AlwaysTraps") { - let input = getFloat80(+.infinity) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(+.infinity)_AlwaysFails") { - let input = getFloat80(+.infinity) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(-.nan)_AlwaysTraps") { - let input = getFloat80(-.nan) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(-.nan)_AlwaysFails") { - let input = getFloat80(-.nan) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(+.nan)_AlwaysTraps") { - let input = getFloat80(+.nan) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(+.nan)_AlwaysFails") { - let input = getFloat80(+.nan) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(-.signalingNaN)_AlwaysTraps") { - let input = getFloat80(-.signalingNaN) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(-.signalingNaN)_AlwaysFails") { - let input = getFloat80(-.signalingNaN) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(+.signalingNaN)_AlwaysTraps") { - let input = getFloat80(+.signalingNaN) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt64.test("FromFloat80(+.signalingNaN)_AlwaysFails") { - let input = getFloat80(+.signalingNaN) - let actual = Int64(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt64 +.test("FromFloat80_NeverTraps") +.forEach(in: [ + (getInt64(-9223372036854775808), getFloat80(-9223372036854775808)), + (getInt64(-32768), getFloat80(-32768.5)), + (getInt64(-128), getFloat80(-128.5)), + (getInt64(+0), getFloat80(-0.5)), + (getInt64(+0), getFloat80(-0)), + (getInt64(+0), getFloat80(+0)), + (getInt64(+0), getFloat80(+0.5)), + (getInt64(+127), getFloat80(+127.5)), + (getInt64(+255), getFloat80(+255.5)), + (getInt64(+32767), getFloat80(+32767.5)), + (getInt64(+65535), getFloat80(+65535.5)), + (getInt64(+9223372036854775807), getFloat80(+9223372036854775807)), +]) { + expectEqual($0.0, Int64($0.1)) +} + +FixedPointConversion_Debug32_ToInt64 +.test("FromFloat80_NeverFails") +.forEach(in: [ + (getInt64(-9223372036854775808), getFloat80(-9223372036854775808)), + (getInt64(+0), getFloat80(-0)), + (getInt64(+0), getFloat80(+0)), + (getInt64(+9223372036854775807), getFloat80(+9223372036854775807)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToInt64 +.test("FromFloat80_AlwaysTraps") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-9223372036854775809), + getFloat80(+9223372036854775808), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int64($0)) +} + +FixedPointConversion_Debug32_ToInt64 +.test("FromFloat80_AlwaysFails") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-9223372036854775809), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-0.5), + getFloat80(+0.5), + getFloat80(+127.5), + getFloat80(+255.5), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(+9223372036854775808), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectNil(Int64(exactly: $0)) } #endif // Float80 diff --git a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug32_ToInt8.swift b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug32_ToInt8.swift index 3f1294235841b..1efa82aa5b3a7 100644 --- a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug32_ToInt8.swift +++ b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug32_ToInt8.swift @@ -14,1860 +14,735 @@ import StdlibUnittest -let FixedPointConversion_Debug32_ToInt8 = TestSuite("FixedPointConversion_Debug32_ToInt8") +let FixedPointConversion_Debug32_ToInt8 = TestSuite( + "FixedPointConversion_Debug32_ToInt8" +) //===----------------------------------------------------------------------===// -// MARK: UInt8: (0)...(255) +// MARK: UInt8: (+0)...(+255) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt8.test("FromUInt8(0)_NeverTraps") { - let input = getUInt8(0) - let actual = Int8(input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToInt8 +.test("FromUInt8_NeverTraps") +.forEach(in: [ + (getInt8(+0), getUInt8(+0)), + (getInt8(+127), getUInt8(+127)), +]) { + expectEqual($0.0, Int8($0.1)) } -FixedPointConversion_Debug32_ToInt8.test("FromUInt8(0)_NeverFails") { - let input = getUInt8(0) - let actual = Int8(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToInt8 +.test("FromUInt8_NeverFails") +.forEach(in: [ + (getInt8(+0), getUInt8(+0)), + (getInt8(+127), getUInt8(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) } -FixedPointConversion_Debug32_ToInt8.test("FromUInt8(127)_NeverTraps") { - let input = getUInt8(127) - let actual = Int8(input) - expectEqual(127, actual) +FixedPointConversion_Debug32_ToInt8 +.test("FromUInt8_AlwaysTraps") +.forEach(in: [ + getUInt8(+128), + getUInt8(+255), +]) { + expectCrashLater() + _blackHole(Int8($0)) } -FixedPointConversion_Debug32_ToInt8.test("FromUInt8(127)_NeverFails") { - let input = getUInt8(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromUInt8(128)_AlwaysTraps") { - let input = getUInt8(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromUInt8(128)_AlwaysFails") { - let input = getUInt8(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromUInt8(255)_AlwaysTraps") { - let input = getUInt8(255) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromUInt8(255)_AlwaysFails") { - let input = getUInt8(255) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt8 +.test("FromUInt8_AlwaysFails") +.forEach(in: [ + getUInt8(+128), + getUInt8(+255), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int8: (-128)...(127) +// MARK: Int8: (-128)...(+127) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt8.test("FromInt8(-128)_NeverTraps") { - let input = getInt8(-128) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt8(-128)_NeverFails") { - let input = getInt8(-128) - let actual = Int8(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt8(0)_NeverTraps") { - let input = getInt8(0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt8(0)_NeverFails") { - let input = getInt8(0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt8(127)_NeverTraps") { - let input = getInt8(127) - let actual = Int8(input) - expectEqual(127, actual) +FixedPointConversion_Debug32_ToInt8 +.test("FromInt8_NeverTraps") +.forEach(in: [ + (getInt8(-128), getInt8(-128)), + (getInt8(+0), getInt8(+0)), + (getInt8(+127), getInt8(+127)), +]) { + expectEqual($0.0, Int8($0.1)) } -FixedPointConversion_Debug32_ToInt8.test("FromInt8(127)_NeverFails") { - let input = getInt8(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Debug32_ToInt8 +.test("FromInt8_NeverFails") +.forEach(in: [ + (getInt8(-128), getInt8(-128)), + (getInt8(+0), getInt8(+0)), + (getInt8(+127), getInt8(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt16: (0)...(65535) +// MARK: UInt16: (+0)...(+65535) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt8.test("FromUInt16(0)_NeverTraps") { - let input = getUInt16(0) - let actual = Int8(input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToInt8 +.test("FromUInt16_NeverTraps") +.forEach(in: [ + (getInt8(+0), getUInt16(+0)), + (getInt8(+127), getUInt16(+127)), +]) { + expectEqual($0.0, Int8($0.1)) } -FixedPointConversion_Debug32_ToInt8.test("FromUInt16(0)_NeverFails") { - let input = getUInt16(0) - let actual = Int8(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToInt8 +.test("FromUInt16_NeverFails") +.forEach(in: [ + (getInt8(+0), getUInt16(+0)), + (getInt8(+127), getUInt16(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) } -FixedPointConversion_Debug32_ToInt8.test("FromUInt16(127)_NeverTraps") { - let input = getUInt16(127) - let actual = Int8(input) - expectEqual(127, actual) +FixedPointConversion_Debug32_ToInt8 +.test("FromUInt16_AlwaysTraps") +.forEach(in: [ + getUInt16(+128), + getUInt16(+65535), +]) { + expectCrashLater() + _blackHole(Int8($0)) } -FixedPointConversion_Debug32_ToInt8.test("FromUInt16(127)_NeverFails") { - let input = getUInt16(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromUInt16(128)_AlwaysTraps") { - let input = getUInt16(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromUInt16(128)_AlwaysFails") { - let input = getUInt16(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromUInt16(65535)_AlwaysTraps") { - let input = getUInt16(65535) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromUInt16(65535)_AlwaysFails") { - let input = getUInt16(65535) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt8 +.test("FromUInt16_AlwaysFails") +.forEach(in: [ + getUInt16(+128), + getUInt16(+65535), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int16: (-32768)...(32767) +// MARK: Int16: (-32768)...(+32767) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt8.test("FromInt16(-32768)_AlwaysTraps") { - let input = getInt16(-32768) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt16(-32768)_AlwaysFails") { - let input = getInt16(-32768) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt16(-129)_AlwaysTraps") { - let input = getInt16(-129) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt16(-129)_AlwaysFails") { - let input = getInt16(-129) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt16(-128)_NeverTraps") { - let input = getInt16(-128) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt16(-128)_NeverFails") { - let input = getInt16(-128) - let actual = Int8(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt16(0)_NeverTraps") { - let input = getInt16(0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt16(0)_NeverFails") { - let input = getInt16(0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt16(127)_NeverTraps") { - let input = getInt16(127) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt16(127)_NeverFails") { - let input = getInt16(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt16(128)_AlwaysTraps") { - let input = getInt16(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt16(128)_AlwaysFails") { - let input = getInt16(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt16(32767)_AlwaysTraps") { - let input = getInt16(32767) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt16(32767)_AlwaysFails") { - let input = getInt16(32767) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt8 +.test("FromInt16_NeverTraps") +.forEach(in: [ + (getInt8(-128), getInt16(-128)), + (getInt8(+0), getInt16(+0)), + (getInt8(+127), getInt16(+127)), +]) { + expectEqual($0.0, Int8($0.1)) +} + +FixedPointConversion_Debug32_ToInt8 +.test("FromInt16_NeverFails") +.forEach(in: [ + (getInt8(-128), getInt16(-128)), + (getInt8(+0), getInt16(+0)), + (getInt8(+127), getInt16(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToInt8 +.test("FromInt16_AlwaysTraps") +.forEach(in: [ + getInt16(-32768), + getInt16(-129), + getInt16(+128), + getInt16(+32767), +]) { + expectCrashLater() + _blackHole(Int8($0)) +} + +FixedPointConversion_Debug32_ToInt8 +.test("FromInt16_AlwaysFails") +.forEach(in: [ + getInt16(-32768), + getInt16(-129), + getInt16(+128), + getInt16(+32767), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt32: (0)...(4294967295) +// MARK: UInt32: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt8.test("FromUInt32(0)_NeverTraps") { - let input = getUInt32(0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromUInt32(0)_NeverFails") { - let input = getUInt32(0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromUInt32(127)_NeverTraps") { - let input = getUInt32(127) - let actual = Int8(input) - expectEqual(127, actual) +FixedPointConversion_Debug32_ToInt8 +.test("FromUInt32_NeverTraps") +.forEach(in: [ + (getInt8(+0), getUInt32(+0)), + (getInt8(+127), getUInt32(+127)), +]) { + expectEqual($0.0, Int8($0.1)) } -FixedPointConversion_Debug32_ToInt8.test("FromUInt32(127)_NeverFails") { - let input = getUInt32(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Debug32_ToInt8 +.test("FromUInt32_NeverFails") +.forEach(in: [ + (getInt8(+0), getUInt32(+0)), + (getInt8(+127), getUInt32(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) } -FixedPointConversion_Debug32_ToInt8.test("FromUInt32(128)_AlwaysTraps") { - let input = getUInt32(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } +FixedPointConversion_Debug32_ToInt8 +.test("FromUInt32_AlwaysTraps") +.forEach(in: [ + getUInt32(+128), + getUInt32(+4294967295), +]) { + expectCrashLater() + _blackHole(Int8($0)) } -FixedPointConversion_Debug32_ToInt8.test("FromUInt32(128)_AlwaysFails") { - let input = getUInt32(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromUInt32(4294967295)_AlwaysTraps") { - let input = getUInt32(4294967295) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromUInt32(4294967295)_AlwaysFails") { - let input = getUInt32(4294967295) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt8 +.test("FromUInt32_AlwaysFails") +.forEach(in: [ + getUInt32(+128), + getUInt32(+4294967295), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int32: (-2147483648)...(2147483647) +// MARK: Int32: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt8.test("FromInt32(-2147483648)_AlwaysTraps") { - let input = getInt32(-2147483648) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt32(-2147483648)_AlwaysFails") { - let input = getInt32(-2147483648) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt32(-129)_AlwaysTraps") { - let input = getInt32(-129) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt32(-129)_AlwaysFails") { - let input = getInt32(-129) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt32(-128)_NeverTraps") { - let input = getInt32(-128) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt32(-128)_NeverFails") { - let input = getInt32(-128) - let actual = Int8(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt32(0)_NeverTraps") { - let input = getInt32(0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt32(0)_NeverFails") { - let input = getInt32(0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt32(127)_NeverTraps") { - let input = getInt32(127) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt32(127)_NeverFails") { - let input = getInt32(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt32(128)_AlwaysTraps") { - let input = getInt32(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt32(128)_AlwaysFails") { - let input = getInt32(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt32(2147483647)_AlwaysTraps") { - let input = getInt32(2147483647) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt32(2147483647)_AlwaysFails") { - let input = getInt32(2147483647) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt8 +.test("FromInt32_NeverTraps") +.forEach(in: [ + (getInt8(-128), getInt32(-128)), + (getInt8(+0), getInt32(+0)), + (getInt8(+127), getInt32(+127)), +]) { + expectEqual($0.0, Int8($0.1)) +} + +FixedPointConversion_Debug32_ToInt8 +.test("FromInt32_NeverFails") +.forEach(in: [ + (getInt8(-128), getInt32(-128)), + (getInt8(+0), getInt32(+0)), + (getInt8(+127), getInt32(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToInt8 +.test("FromInt32_AlwaysTraps") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-129), + getInt32(+128), + getInt32(+2147483647), +]) { + expectCrashLater() + _blackHole(Int8($0)) +} + +FixedPointConversion_Debug32_ToInt8 +.test("FromInt32_AlwaysFails") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-129), + getInt32(+128), + getInt32(+2147483647), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt64: (0)...(18446744073709551615) +// MARK: UInt64: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt8.test("FromUInt64(0)_NeverTraps") { - let input = getUInt64(0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromUInt64(0)_NeverFails") { - let input = getUInt64(0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromUInt64(127)_NeverTraps") { - let input = getUInt64(127) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromUInt64(127)_NeverFails") { - let input = getUInt64(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromUInt64(128)_AlwaysTraps") { - let input = getUInt64(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } +FixedPointConversion_Debug32_ToInt8 +.test("FromUInt64_NeverTraps") +.forEach(in: [ + (getInt8(+0), getUInt64(+0)), + (getInt8(+127), getUInt64(+127)), +]) { + expectEqual($0.0, Int8($0.1)) } -FixedPointConversion_Debug32_ToInt8.test("FromUInt64(128)_AlwaysFails") { - let input = getUInt64(128) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt8 +.test("FromUInt64_NeverFails") +.forEach(in: [ + (getInt8(+0), getUInt64(+0)), + (getInt8(+127), getUInt64(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) } -FixedPointConversion_Debug32_ToInt8.test("FromUInt64(18446744073709551615)_AlwaysTraps") { - let input = getUInt64(18446744073709551615) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } +FixedPointConversion_Debug32_ToInt8 +.test("FromUInt64_AlwaysTraps") +.forEach(in: [ + getUInt64(+128), + getUInt64(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(Int8($0)) } -FixedPointConversion_Debug32_ToInt8.test("FromUInt64(18446744073709551615)_AlwaysFails") { - let input = getUInt64(18446744073709551615) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt8 +.test("FromUInt64_AlwaysFails") +.forEach(in: [ + getUInt64(+128), + getUInt64(+18446744073709551615), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int64: (-9223372036854775808)...(9223372036854775807) +// MARK: Int64: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt8.test("FromInt64(-9223372036854775808)_AlwaysTraps") { - let input = getInt64(-9223372036854775808) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt64(-9223372036854775808)_AlwaysFails") { - let input = getInt64(-9223372036854775808) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt64(-129)_AlwaysTraps") { - let input = getInt64(-129) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt64(-129)_AlwaysFails") { - let input = getInt64(-129) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt64(-128)_NeverTraps") { - let input = getInt64(-128) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt64(-128)_NeverFails") { - let input = getInt64(-128) - let actual = Int8(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt64(0)_NeverTraps") { - let input = getInt64(0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt64(0)_NeverFails") { - let input = getInt64(0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt64(127)_NeverTraps") { - let input = getInt64(127) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt64(127)_NeverFails") { - let input = getInt64(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt64(128)_AlwaysTraps") { - let input = getInt64(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt64(128)_AlwaysFails") { - let input = getInt64(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt64(9223372036854775807)_AlwaysTraps") { - let input = getInt64(9223372036854775807) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt64(9223372036854775807)_AlwaysFails") { - let input = getInt64(9223372036854775807) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt8 +.test("FromInt64_NeverTraps") +.forEach(in: [ + (getInt8(-128), getInt64(-128)), + (getInt8(+0), getInt64(+0)), + (getInt8(+127), getInt64(+127)), +]) { + expectEqual($0.0, Int8($0.1)) +} + +FixedPointConversion_Debug32_ToInt8 +.test("FromInt64_NeverFails") +.forEach(in: [ + (getInt8(-128), getInt64(-128)), + (getInt8(+0), getInt64(+0)), + (getInt8(+127), getInt64(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToInt8 +.test("FromInt64_AlwaysTraps") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-129), + getInt64(+128), + getInt64(+9223372036854775807), +]) { + expectCrashLater() + _blackHole(Int8($0)) +} + +FixedPointConversion_Debug32_ToInt8 +.test("FromInt64_AlwaysFails") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-129), + getInt64(+128), + getInt64(+9223372036854775807), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt: (0)...(4294967295) +// MARK: UInt: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt8.test("FromUInt(0)_NeverTraps") { - let input = getUInt(0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromUInt(0)_NeverFails") { - let input = getUInt(0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromUInt(127)_NeverTraps") { - let input = getUInt(127) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromUInt(127)_NeverFails") { - let input = getUInt(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromUInt(128)_AlwaysTraps") { - let input = getUInt(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } +FixedPointConversion_Debug32_ToInt8 +.test("FromUInt_NeverTraps") +.forEach(in: [ + (getInt8(+0), getUInt(+0)), + (getInt8(+127), getUInt(+127)), +]) { + expectEqual($0.0, Int8($0.1)) } -FixedPointConversion_Debug32_ToInt8.test("FromUInt(128)_AlwaysFails") { - let input = getUInt(128) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt8 +.test("FromUInt_NeverFails") +.forEach(in: [ + (getInt8(+0), getUInt(+0)), + (getInt8(+127), getUInt(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) } -FixedPointConversion_Debug32_ToInt8.test("FromUInt(4294967295)_AlwaysTraps") { - let input = getUInt(4294967295) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } +FixedPointConversion_Debug32_ToInt8 +.test("FromUInt_AlwaysTraps") +.forEach(in: [ + getUInt(+128), + getUInt(+4294967295), +]) { + expectCrashLater() + _blackHole(Int8($0)) } -FixedPointConversion_Debug32_ToInt8.test("FromUInt(4294967295)_AlwaysFails") { - let input = getUInt(4294967295) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt8 +.test("FromUInt_AlwaysFails") +.forEach(in: [ + getUInt(+128), + getUInt(+4294967295), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int: (-2147483648)...(2147483647) +// MARK: Int: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt8.test("FromInt(-2147483648)_AlwaysTraps") { - let input = getInt(-2147483648) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt(-2147483648)_AlwaysFails") { - let input = getInt(-2147483648) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt(-129)_AlwaysTraps") { - let input = getInt(-129) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt(-129)_AlwaysFails") { - let input = getInt(-129) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt(-128)_NeverTraps") { - let input = getInt(-128) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt(-128)_NeverFails") { - let input = getInt(-128) - let actual = Int8(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt(0)_NeverTraps") { - let input = getInt(0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt(0)_NeverFails") { - let input = getInt(0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt(127)_NeverTraps") { - let input = getInt(127) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt(127)_NeverFails") { - let input = getInt(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt(128)_AlwaysTraps") { - let input = getInt(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt(128)_AlwaysFails") { - let input = getInt(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt(2147483647)_AlwaysTraps") { - let input = getInt(2147483647) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromInt(2147483647)_AlwaysFails") { - let input = getInt(2147483647) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt8 +.test("FromInt_NeverTraps") +.forEach(in: [ + (getInt8(-128), getInt(-128)), + (getInt8(+0), getInt(+0)), + (getInt8(+127), getInt(+127)), +]) { + expectEqual($0.0, Int8($0.1)) +} + +FixedPointConversion_Debug32_ToInt8 +.test("FromInt_NeverFails") +.forEach(in: [ + (getInt8(-128), getInt(-128)), + (getInt8(+0), getInt(+0)), + (getInt8(+127), getInt(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToInt8 +.test("FromInt_AlwaysTraps") +.forEach(in: [ + getInt(-2147483648), + getInt(-129), + getInt(+128), + getInt(+2147483647), +]) { + expectCrashLater() + _blackHole(Int8($0)) +} + +FixedPointConversion_Debug32_ToInt8 +.test("FromInt_AlwaysFails") +.forEach(in: [ + getInt(-2147483648), + getInt(-129), + getInt(+128), + getInt(+2147483647), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float16: (-2047)...(2047) +// MARK: Float16: (-2047)...(+2047) //===----------------------------------------------------------------------===// #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -FixedPointConversion_Debug32_ToInt8.test("FromFloat16(-2047)_AlwaysTraps") { - let input = getFloat16(-2047) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat16(-2047)_AlwaysFails") { - let input = getFloat16(-2047) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat16(-129)_AlwaysTraps") { - let input = getFloat16(-129) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat16(-129)_AlwaysFails") { - let input = getFloat16(-129) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat16(-128.5)_NeverTraps") { - let input = getFloat16(-128.5) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat16(-128.5)_AlwaysFails") { - let input = getFloat16(-128.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat16(-128)_NeverTraps") { - let input = getFloat16(-128) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat16(-128)_NeverFails") { - let input = getFloat16(-128) - let actual = Int8(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat16(-0.5)_NeverTraps") { - let input = getFloat16(-0.5) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat16(-0.5)_AlwaysFails") { - let input = getFloat16(-0.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat16(-0.0)_NeverTraps") { - let input = getFloat16(-0.0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat16(-0.0)_NeverFails") { - let input = getFloat16(-0.0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat16(0.0)_NeverTraps") { - let input = getFloat16(0.0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat16(0.0)_NeverFails") { - let input = getFloat16(0.0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat16(0.5)_NeverTraps") { - let input = getFloat16(0.5) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat16(0.5)_AlwaysFails") { - let input = getFloat16(0.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat16(127)_NeverTraps") { - let input = getFloat16(127) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat16(127)_NeverFails") { - let input = getFloat16(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat16(127.5)_NeverTraps") { - let input = getFloat16(127.5) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat16(127.5)_AlwaysFails") { - let input = getFloat16(127.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat16(128)_AlwaysTraps") { - let input = getFloat16(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat16(128)_AlwaysFails") { - let input = getFloat16(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat16(255.5)_AlwaysTraps") { - let input = getFloat16(255.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat16(255.5)_AlwaysFails") { - let input = getFloat16(255.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat16(2047)_AlwaysTraps") { - let input = getFloat16(2047) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat16(2047)_AlwaysFails") { - let input = getFloat16(2047) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat16(-.infinity)_AlwaysTraps") { - let input = getFloat16(-.infinity) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat16(-.infinity)_AlwaysFails") { - let input = getFloat16(-.infinity) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat16(+.infinity)_AlwaysTraps") { - let input = getFloat16(+.infinity) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat16(+.infinity)_AlwaysFails") { - let input = getFloat16(+.infinity) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat16(-.nan)_AlwaysTraps") { - let input = getFloat16(-.nan) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat16(-.nan)_AlwaysFails") { - let input = getFloat16(-.nan) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat16(+.nan)_AlwaysTraps") { - let input = getFloat16(+.nan) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat16(+.nan)_AlwaysFails") { - let input = getFloat16(+.nan) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat16(-.signalingNaN)_AlwaysTraps") { - let input = getFloat16(-.signalingNaN) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat16(-.signalingNaN)_AlwaysFails") { - let input = getFloat16(-.signalingNaN) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat16(+.signalingNaN)_AlwaysTraps") { - let input = getFloat16(+.signalingNaN) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat16(+.signalingNaN)_AlwaysFails") { - let input = getFloat16(+.signalingNaN) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt8 +.test("FromFloat16_NeverTraps") +.forEach(in: [ + (getInt8(-128), getFloat16(-128.5)), + (getInt8(-128), getFloat16(-128)), + (getInt8(+0), getFloat16(-0.5)), + (getInt8(+0), getFloat16(-0)), + (getInt8(+0), getFloat16(+0)), + (getInt8(+0), getFloat16(+0.5)), + (getInt8(+127), getFloat16(+127)), + (getInt8(+127), getFloat16(+127.5)), +]) { + expectEqual($0.0, Int8($0.1)) +} + +FixedPointConversion_Debug32_ToInt8 +.test("FromFloat16_NeverFails") +.forEach(in: [ + (getInt8(-128), getFloat16(-128)), + (getInt8(+0), getFloat16(-0)), + (getInt8(+0), getFloat16(+0)), + (getInt8(+127), getFloat16(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToInt8 +.test("FromFloat16_AlwaysTraps") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-129), + getFloat16(+128), + getFloat16(+255.5), + getFloat16(+2047), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int8($0)) +} + +FixedPointConversion_Debug32_ToInt8 +.test("FromFloat16_AlwaysFails") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-129), + getFloat16(-128.5), + getFloat16(-0.5), + getFloat16(+0.5), + getFloat16(+127.5), + getFloat16(+128), + getFloat16(+255.5), + getFloat16(+2047), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectNil(Int8(exactly: $0)) } } #endif // Float16 //===----------------------------------------------------------------------===// -// MARK: Float32: (-16777215)...(16777215) +// MARK: Float32: (-16777215)...(+16777215) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(-16777215)_AlwaysTraps") { - let input = getFloat32(-16777215) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(-16777215)_AlwaysFails") { - let input = getFloat32(-16777215) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(-32768.5)_AlwaysTraps") { - let input = getFloat32(-32768.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(-32768.5)_AlwaysFails") { - let input = getFloat32(-32768.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(-129)_AlwaysTraps") { - let input = getFloat32(-129) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(-129)_AlwaysFails") { - let input = getFloat32(-129) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(-128.5)_NeverTraps") { - let input = getFloat32(-128.5) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(-128.5)_AlwaysFails") { - let input = getFloat32(-128.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(-128)_NeverTraps") { - let input = getFloat32(-128) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(-128)_NeverFails") { - let input = getFloat32(-128) - let actual = Int8(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(-0.5)_NeverTraps") { - let input = getFloat32(-0.5) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(-0.5)_AlwaysFails") { - let input = getFloat32(-0.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(-0.0)_NeverTraps") { - let input = getFloat32(-0.0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(-0.0)_NeverFails") { - let input = getFloat32(-0.0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(0.0)_NeverTraps") { - let input = getFloat32(0.0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(0.0)_NeverFails") { - let input = getFloat32(0.0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(0.5)_NeverTraps") { - let input = getFloat32(0.5) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(0.5)_AlwaysFails") { - let input = getFloat32(0.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(127)_NeverTraps") { - let input = getFloat32(127) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(127)_NeverFails") { - let input = getFloat32(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(127.5)_NeverTraps") { - let input = getFloat32(127.5) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(127.5)_AlwaysFails") { - let input = getFloat32(127.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(128)_AlwaysTraps") { - let input = getFloat32(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(128)_AlwaysFails") { - let input = getFloat32(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(255.5)_AlwaysTraps") { - let input = getFloat32(255.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(255.5)_AlwaysFails") { - let input = getFloat32(255.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(32767.5)_AlwaysTraps") { - let input = getFloat32(32767.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(32767.5)_AlwaysFails") { - let input = getFloat32(32767.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(65535.5)_AlwaysTraps") { - let input = getFloat32(65535.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(65535.5)_AlwaysFails") { - let input = getFloat32(65535.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(16777215)_AlwaysTraps") { - let input = getFloat32(16777215) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(16777215)_AlwaysFails") { - let input = getFloat32(16777215) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(-.infinity)_AlwaysTraps") { - let input = getFloat32(-.infinity) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(-.infinity)_AlwaysFails") { - let input = getFloat32(-.infinity) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(+.infinity)_AlwaysTraps") { - let input = getFloat32(+.infinity) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(+.infinity)_AlwaysFails") { - let input = getFloat32(+.infinity) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(-.nan)_AlwaysTraps") { - let input = getFloat32(-.nan) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(-.nan)_AlwaysFails") { - let input = getFloat32(-.nan) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(+.nan)_AlwaysTraps") { - let input = getFloat32(+.nan) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(+.nan)_AlwaysFails") { - let input = getFloat32(+.nan) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(-.signalingNaN)_AlwaysTraps") { - let input = getFloat32(-.signalingNaN) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(-.signalingNaN)_AlwaysFails") { - let input = getFloat32(-.signalingNaN) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(+.signalingNaN)_AlwaysTraps") { - let input = getFloat32(+.signalingNaN) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat32(+.signalingNaN)_AlwaysFails") { - let input = getFloat32(+.signalingNaN) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt8 +.test("FromFloat32_NeverTraps") +.forEach(in: [ + (getInt8(-128), getFloat32(-128.5)), + (getInt8(-128), getFloat32(-128)), + (getInt8(+0), getFloat32(-0.5)), + (getInt8(+0), getFloat32(+0)), + (getInt8(+0), getFloat32(-0)), + (getInt8(+0), getFloat32(+0.5)), + (getInt8(+127), getFloat32(+127)), + (getInt8(+127), getFloat32(+127.5)), +]) { + expectEqual($0.0, Int8($0.1)) +} + +FixedPointConversion_Debug32_ToInt8 +.test("FromFloat32_NeverFails") +.forEach(in: [ + (getInt8(-128), getFloat32(-128)), + (getInt8(+0), getFloat32(+0)), + (getInt8(+0), getFloat32(-0)), + (getInt8(+127), getFloat32(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToInt8 +.test("FromFloat32_AlwaysTraps") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-129), + getFloat32(+128), + getFloat32(+255.5), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(+16777215), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int8($0)) +} + +FixedPointConversion_Debug32_ToInt8 +.test("FromFloat32_AlwaysFails") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-129), + getFloat32(-128.5), + getFloat32(-0.5), + getFloat32(+0.5), + getFloat32(+127.5), + getFloat32(+128), + getFloat32(+255.5), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(+16777215), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float64: (-9007199254740991)...(9007199254740991) +// MARK: Float64: (-9007199254740991)...(+9007199254740991) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(-9007199254740991)_AlwaysTraps") { - let input = getFloat64(-9007199254740991) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(-9007199254740991)_AlwaysFails") { - let input = getFloat64(-9007199254740991) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(-32768.5)_AlwaysTraps") { - let input = getFloat64(-32768.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(-32768.5)_AlwaysFails") { - let input = getFloat64(-32768.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(-129)_AlwaysTraps") { - let input = getFloat64(-129) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(-129)_AlwaysFails") { - let input = getFloat64(-129) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(-128.5)_NeverTraps") { - let input = getFloat64(-128.5) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(-128.5)_AlwaysFails") { - let input = getFloat64(-128.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(-128)_NeverTraps") { - let input = getFloat64(-128) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(-128)_NeverFails") { - let input = getFloat64(-128) - let actual = Int8(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(-0.5)_NeverTraps") { - let input = getFloat64(-0.5) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(-0.5)_AlwaysFails") { - let input = getFloat64(-0.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(-0.0)_NeverTraps") { - let input = getFloat64(-0.0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(-0.0)_NeverFails") { - let input = getFloat64(-0.0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(0.0)_NeverTraps") { - let input = getFloat64(0.0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(0.0)_NeverFails") { - let input = getFloat64(0.0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(0.5)_NeverTraps") { - let input = getFloat64(0.5) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(0.5)_AlwaysFails") { - let input = getFloat64(0.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(127)_NeverTraps") { - let input = getFloat64(127) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(127)_NeverFails") { - let input = getFloat64(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(127.5)_NeverTraps") { - let input = getFloat64(127.5) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(127.5)_AlwaysFails") { - let input = getFloat64(127.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(128)_AlwaysTraps") { - let input = getFloat64(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(128)_AlwaysFails") { - let input = getFloat64(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(255.5)_AlwaysTraps") { - let input = getFloat64(255.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(255.5)_AlwaysFails") { - let input = getFloat64(255.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(32767.5)_AlwaysTraps") { - let input = getFloat64(32767.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(32767.5)_AlwaysFails") { - let input = getFloat64(32767.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(65535.5)_AlwaysTraps") { - let input = getFloat64(65535.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(65535.5)_AlwaysFails") { - let input = getFloat64(65535.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(9007199254740991)_AlwaysTraps") { - let input = getFloat64(9007199254740991) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(9007199254740991)_AlwaysFails") { - let input = getFloat64(9007199254740991) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(-.infinity)_AlwaysTraps") { - let input = getFloat64(-.infinity) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(-.infinity)_AlwaysFails") { - let input = getFloat64(-.infinity) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(+.infinity)_AlwaysTraps") { - let input = getFloat64(+.infinity) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(+.infinity)_AlwaysFails") { - let input = getFloat64(+.infinity) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(-.nan)_AlwaysTraps") { - let input = getFloat64(-.nan) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(-.nan)_AlwaysFails") { - let input = getFloat64(-.nan) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(+.nan)_AlwaysTraps") { - let input = getFloat64(+.nan) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(+.nan)_AlwaysFails") { - let input = getFloat64(+.nan) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(-.signalingNaN)_AlwaysTraps") { - let input = getFloat64(-.signalingNaN) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(-.signalingNaN)_AlwaysFails") { - let input = getFloat64(-.signalingNaN) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(+.signalingNaN)_AlwaysTraps") { - let input = getFloat64(+.signalingNaN) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat64(+.signalingNaN)_AlwaysFails") { - let input = getFloat64(+.signalingNaN) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt8 +.test("FromFloat64_NeverTraps") +.forEach(in: [ + (getInt8(-128), getFloat64(-128.5)), + (getInt8(-128), getFloat64(-128)), + (getInt8(+0), getFloat64(-0.5)), + (getInt8(+0), getFloat64(+0)), + (getInt8(+0), getFloat64(-0)), + (getInt8(+0), getFloat64(+0.5)), + (getInt8(+127), getFloat64(+127)), + (getInt8(+127), getFloat64(+127.5)), +]) { + expectEqual($0.0, Int8($0.1)) +} + +FixedPointConversion_Debug32_ToInt8 +.test("FromFloat64_NeverFails") +.forEach(in: [ + (getInt8(-128), getFloat64(-128)), + (getInt8(+0), getFloat64(+0)), + (getInt8(+0), getFloat64(-0)), + (getInt8(+127), getFloat64(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToInt8 +.test("FromFloat64_AlwaysTraps") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-129), + getFloat64(+128), + getFloat64(+255.5), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int8($0)) +} + +FixedPointConversion_Debug32_ToInt8 +.test("FromFloat64_AlwaysFails") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-129), + getFloat64(-128.5), + getFloat64(-0.5), + getFloat64(+0.5), + getFloat64(+127.5), + getFloat64(+128), + getFloat64(+255.5), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float80: (-18446744073709551615)...(18446744073709551615) +// MARK: Float80: (-18446744073709551615)...(+18446744073709551615) //===----------------------------------------------------------------------===// #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(-18446744073709551615)_AlwaysTraps") { - let input = getFloat80(-18446744073709551615) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(-18446744073709551615)_AlwaysFails") { - let input = getFloat80(-18446744073709551615) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(-32768.5)_AlwaysTraps") { - let input = getFloat80(-32768.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(-32768.5)_AlwaysFails") { - let input = getFloat80(-32768.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(-129)_AlwaysTraps") { - let input = getFloat80(-129) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(-129)_AlwaysFails") { - let input = getFloat80(-129) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(-128.5)_NeverTraps") { - let input = getFloat80(-128.5) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(-128.5)_AlwaysFails") { - let input = getFloat80(-128.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(-128)_NeverTraps") { - let input = getFloat80(-128) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(-128)_NeverFails") { - let input = getFloat80(-128) - let actual = Int8(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(-0.5)_NeverTraps") { - let input = getFloat80(-0.5) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(-0.5)_AlwaysFails") { - let input = getFloat80(-0.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(-0.0)_NeverTraps") { - let input = getFloat80(-0.0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(-0.0)_NeverFails") { - let input = getFloat80(-0.0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(0.0)_NeverTraps") { - let input = getFloat80(0.0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(0.0)_NeverFails") { - let input = getFloat80(0.0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(0.5)_NeverTraps") { - let input = getFloat80(0.5) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(0.5)_AlwaysFails") { - let input = getFloat80(0.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(127)_NeverTraps") { - let input = getFloat80(127) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(127)_NeverFails") { - let input = getFloat80(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(127.5)_NeverTraps") { - let input = getFloat80(127.5) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(127.5)_AlwaysFails") { - let input = getFloat80(127.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(128)_AlwaysTraps") { - let input = getFloat80(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(128)_AlwaysFails") { - let input = getFloat80(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(255.5)_AlwaysTraps") { - let input = getFloat80(255.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(255.5)_AlwaysFails") { - let input = getFloat80(255.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(32767.5)_AlwaysTraps") { - let input = getFloat80(32767.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(32767.5)_AlwaysFails") { - let input = getFloat80(32767.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(65535.5)_AlwaysTraps") { - let input = getFloat80(65535.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(65535.5)_AlwaysFails") { - let input = getFloat80(65535.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(18446744073709551615)_AlwaysTraps") { - let input = getFloat80(18446744073709551615) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(18446744073709551615)_AlwaysFails") { - let input = getFloat80(18446744073709551615) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(-.infinity)_AlwaysTraps") { - let input = getFloat80(-.infinity) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(-.infinity)_AlwaysFails") { - let input = getFloat80(-.infinity) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(+.infinity)_AlwaysTraps") { - let input = getFloat80(+.infinity) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(+.infinity)_AlwaysFails") { - let input = getFloat80(+.infinity) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(-.nan)_AlwaysTraps") { - let input = getFloat80(-.nan) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(-.nan)_AlwaysFails") { - let input = getFloat80(-.nan) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(+.nan)_AlwaysTraps") { - let input = getFloat80(+.nan) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(+.nan)_AlwaysFails") { - let input = getFloat80(+.nan) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(-.signalingNaN)_AlwaysTraps") { - let input = getFloat80(-.signalingNaN) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(-.signalingNaN)_AlwaysFails") { - let input = getFloat80(-.signalingNaN) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(+.signalingNaN)_AlwaysTraps") { - let input = getFloat80(+.signalingNaN) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToInt8.test("FromFloat80(+.signalingNaN)_AlwaysFails") { - let input = getFloat80(+.signalingNaN) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToInt8 +.test("FromFloat80_NeverTraps") +.forEach(in: [ + (getInt8(-128), getFloat80(-128.5)), + (getInt8(-128), getFloat80(-128)), + (getInt8(+0), getFloat80(-0.5)), + (getInt8(+0), getFloat80(-0)), + (getInt8(+0), getFloat80(+0)), + (getInt8(+0), getFloat80(+0.5)), + (getInt8(+127), getFloat80(+127)), + (getInt8(+127), getFloat80(+127.5)), +]) { + expectEqual($0.0, Int8($0.1)) +} + +FixedPointConversion_Debug32_ToInt8 +.test("FromFloat80_NeverFails") +.forEach(in: [ + (getInt8(-128), getFloat80(-128)), + (getInt8(+0), getFloat80(-0)), + (getInt8(+0), getFloat80(+0)), + (getInt8(+127), getFloat80(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToInt8 +.test("FromFloat80_AlwaysTraps") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-129), + getFloat80(+128), + getFloat80(+255.5), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int8($0)) +} + +FixedPointConversion_Debug32_ToInt8 +.test("FromFloat80_AlwaysFails") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-129), + getFloat80(-128.5), + getFloat80(-0.5), + getFloat80(+0.5), + getFloat80(+127.5), + getFloat80(+128), + getFloat80(+255.5), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectNil(Int8(exactly: $0)) } #endif // Float80 diff --git a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug32_ToUInt.swift b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug32_ToUInt.swift index 61968eb90b505..1044effe42bfd 100644 --- a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug32_ToUInt.swift +++ b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug32_ToUInt.swift @@ -14,1564 +14,640 @@ import StdlibUnittest -let FixedPointConversion_Debug32_ToUInt = TestSuite("FixedPointConversion_Debug32_ToUInt") +let FixedPointConversion_Debug32_ToUInt = TestSuite( + "FixedPointConversion_Debug32_ToUInt" +) //===----------------------------------------------------------------------===// -// MARK: UInt8: (0)...(255) +// MARK: UInt8: (+0)...(+255) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt.test("FromUInt8(0)_NeverTraps") { - let input = getUInt8(0) - let actual = UInt(input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToUInt +.test("FromUInt8_NeverTraps") +.forEach(in: [ + (getUInt(+0), getUInt8(+0)), + (getUInt(+255), getUInt8(+255)), +]) { + expectEqual($0.0, UInt($0.1)) } -FixedPointConversion_Debug32_ToUInt.test("FromUInt8(0)_NeverFails") { - let input = getUInt8(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromUInt8(255)_NeverTraps") { - let input = getUInt8(255) - let actual = UInt(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromUInt8(255)_NeverFails") { - let input = getUInt8(255) - let actual = UInt(exactly: input) - expectEqual(255, actual) +FixedPointConversion_Debug32_ToUInt +.test("FromUInt8_NeverFails") +.forEach(in: [ + (getUInt(+0), getUInt8(+0)), + (getUInt(+255), getUInt8(+255)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int8: (-128)...(127) +// MARK: Int8: (-128)...(+127) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt.test("FromInt8(-128)_AlwaysTraps") { - let input = getInt8(-128) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } +FixedPointConversion_Debug32_ToUInt +.test("FromInt8_NeverTraps") +.forEach(in: [ + (getUInt(+0), getInt8(+0)), + (getUInt(+127), getInt8(+127)), +]) { + expectEqual($0.0, UInt($0.1)) } -FixedPointConversion_Debug32_ToUInt.test("FromInt8(-128)_AlwaysFails") { - let input = getInt8(-128) - let actual = UInt(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt +.test("FromInt8_NeverFails") +.forEach(in: [ + (getUInt(+0), getInt8(+0)), + (getUInt(+127), getInt8(+127)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) } -FixedPointConversion_Debug32_ToUInt.test("FromInt8(-1)_AlwaysTraps") { - let input = getInt8(-1) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } +FixedPointConversion_Debug32_ToUInt +.test("FromInt8_AlwaysTraps") +.forEach(in: [ + getInt8(-128), + getInt8(-1), +]) { + expectCrashLater() + _blackHole(UInt($0)) } -FixedPointConversion_Debug32_ToUInt.test("FromInt8(-1)_AlwaysFails") { - let input = getInt8(-1) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromInt8(0)_NeverTraps") { - let input = getInt8(0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromInt8(0)_NeverFails") { - let input = getInt8(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromInt8(127)_NeverTraps") { - let input = getInt8(127) - let actual = UInt(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromInt8(127)_NeverFails") { - let input = getInt8(127) - let actual = UInt(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Debug32_ToUInt +.test("FromInt8_AlwaysFails") +.forEach(in: [ + getInt8(-128), + getInt8(-1), +]) { + expectNil(UInt(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt16: (0)...(65535) +// MARK: UInt16: (+0)...(+65535) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt.test("FromUInt16(0)_NeverTraps") { - let input = getUInt16(0) - let actual = UInt(input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToUInt +.test("FromUInt16_NeverTraps") +.forEach(in: [ + (getUInt(+0), getUInt16(+0)), + (getUInt(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, UInt($0.1)) } -FixedPointConversion_Debug32_ToUInt.test("FromUInt16(0)_NeverFails") { - let input = getUInt16(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromUInt16(65535)_NeverTraps") { - let input = getUInt16(65535) - let actual = UInt(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromUInt16(65535)_NeverFails") { - let input = getUInt16(65535) - let actual = UInt(exactly: input) - expectEqual(65535, actual) +FixedPointConversion_Debug32_ToUInt +.test("FromUInt16_NeverFails") +.forEach(in: [ + (getUInt(+0), getUInt16(+0)), + (getUInt(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int16: (-32768)...(32767) +// MARK: Int16: (-32768)...(+32767) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt.test("FromInt16(-32768)_AlwaysTraps") { - let input = getInt16(-32768) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromInt16(-32768)_AlwaysFails") { - let input = getInt16(-32768) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromInt16(-1)_AlwaysTraps") { - let input = getInt16(-1) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromInt16(-1)_AlwaysFails") { - let input = getInt16(-1) - let actual = UInt(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt +.test("FromInt16_NeverTraps") +.forEach(in: [ + (getUInt(+0), getInt16(+0)), + (getUInt(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, UInt($0.1)) } -FixedPointConversion_Debug32_ToUInt.test("FromInt16(0)_NeverTraps") { - let input = getInt16(0) - let actual = UInt(input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToUInt +.test("FromInt16_NeverFails") +.forEach(in: [ + (getUInt(+0), getInt16(+0)), + (getUInt(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) } -FixedPointConversion_Debug32_ToUInt.test("FromInt16(0)_NeverFails") { - let input = getInt16(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToUInt +.test("FromInt16_AlwaysTraps") +.forEach(in: [ + getInt16(-32768), + getInt16(-1), +]) { + expectCrashLater() + _blackHole(UInt($0)) } -FixedPointConversion_Debug32_ToUInt.test("FromInt16(32767)_NeverTraps") { - let input = getInt16(32767) - let actual = UInt(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromInt16(32767)_NeverFails") { - let input = getInt16(32767) - let actual = UInt(exactly: input) - expectEqual(32767, actual) +FixedPointConversion_Debug32_ToUInt +.test("FromInt16_AlwaysFails") +.forEach(in: [ + getInt16(-32768), + getInt16(-1), +]) { + expectNil(UInt(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt32: (0)...(4294967295) +// MARK: UInt32: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt.test("FromUInt32(0)_NeverTraps") { - let input = getUInt32(0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromUInt32(0)_NeverFails") { - let input = getUInt32(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromUInt32(4294967295)_NeverTraps") { - let input = getUInt32(4294967295) - let actual = UInt(input) - expectEqual(4294967295, actual) +FixedPointConversion_Debug32_ToUInt +.test("FromUInt32_NeverTraps") +.forEach(in: [ + (getUInt(+0), getUInt32(+0)), + (getUInt(+4294967295), getUInt32(+4294967295)), +]) { + expectEqual($0.0, UInt($0.1)) } -FixedPointConversion_Debug32_ToUInt.test("FromUInt32(4294967295)_NeverFails") { - let input = getUInt32(4294967295) - let actual = UInt(exactly: input) - expectEqual(4294967295, actual) +FixedPointConversion_Debug32_ToUInt +.test("FromUInt32_NeverFails") +.forEach(in: [ + (getUInt(+0), getUInt32(+0)), + (getUInt(+4294967295), getUInt32(+4294967295)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int32: (-2147483648)...(2147483647) +// MARK: Int32: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt.test("FromInt32(-2147483648)_AlwaysTraps") { - let input = getInt32(-2147483648) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromInt32(-2147483648)_AlwaysFails") { - let input = getInt32(-2147483648) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromInt32(-1)_AlwaysTraps") { - let input = getInt32(-1) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } +FixedPointConversion_Debug32_ToUInt +.test("FromInt32_NeverTraps") +.forEach(in: [ + (getUInt(+0), getInt32(+0)), + (getUInt(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, UInt($0.1)) } -FixedPointConversion_Debug32_ToUInt.test("FromInt32(-1)_AlwaysFails") { - let input = getInt32(-1) - let actual = UInt(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt +.test("FromInt32_NeverFails") +.forEach(in: [ + (getUInt(+0), getInt32(+0)), + (getUInt(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) } -FixedPointConversion_Debug32_ToUInt.test("FromInt32(0)_NeverTraps") { - let input = getInt32(0) - let actual = UInt(input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToUInt +.test("FromInt32_AlwaysTraps") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-1), +]) { + expectCrashLater() + _blackHole(UInt($0)) } -FixedPointConversion_Debug32_ToUInt.test("FromInt32(0)_NeverFails") { - let input = getInt32(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromInt32(2147483647)_NeverTraps") { - let input = getInt32(2147483647) - let actual = UInt(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromInt32(2147483647)_NeverFails") { - let input = getInt32(2147483647) - let actual = UInt(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Debug32_ToUInt +.test("FromInt32_AlwaysFails") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-1), +]) { + expectNil(UInt(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt64: (0)...(18446744073709551615) +// MARK: UInt64: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt.test("FromUInt64(0)_NeverTraps") { - let input = getUInt64(0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromUInt64(0)_NeverFails") { - let input = getUInt64(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToUInt +.test("FromUInt64_NeverTraps") +.forEach(in: [ + (getUInt(+0), getUInt64(+0)), + (getUInt(+4294967295), getUInt64(+4294967295)), +]) { + expectEqual($0.0, UInt($0.1)) } -FixedPointConversion_Debug32_ToUInt.test("FromUInt64(4294967295)_NeverTraps") { - let input = getUInt64(4294967295) - let actual = UInt(input) - expectEqual(4294967295, actual) +FixedPointConversion_Debug32_ToUInt +.test("FromUInt64_NeverFails") +.forEach(in: [ + (getUInt(+0), getUInt64(+0)), + (getUInt(+4294967295), getUInt64(+4294967295)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) } -FixedPointConversion_Debug32_ToUInt.test("FromUInt64(4294967295)_NeverFails") { - let input = getUInt64(4294967295) - let actual = UInt(exactly: input) - expectEqual(4294967295, actual) +FixedPointConversion_Debug32_ToUInt +.test("FromUInt64_AlwaysTraps") +.forEach(in: [ + getUInt64(+4294967296), + getUInt64(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(UInt($0)) } -FixedPointConversion_Debug32_ToUInt.test("FromUInt64(4294967296)_AlwaysTraps") { - let input = getUInt64(4294967296) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromUInt64(4294967296)_AlwaysFails") { - let input = getUInt64(4294967296) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromUInt64(18446744073709551615)_AlwaysTraps") { - let input = getUInt64(18446744073709551615) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromUInt64(18446744073709551615)_AlwaysFails") { - let input = getUInt64(18446744073709551615) - let actual = UInt(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt +.test("FromUInt64_AlwaysFails") +.forEach(in: [ + getUInt64(+4294967296), + getUInt64(+18446744073709551615), +]) { + expectNil(UInt(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int64: (-9223372036854775808)...(9223372036854775807) +// MARK: Int64: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt.test("FromInt64(-9223372036854775808)_AlwaysTraps") { - let input = getInt64(-9223372036854775808) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromInt64(-9223372036854775808)_AlwaysFails") { - let input = getInt64(-9223372036854775808) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromInt64(-1)_AlwaysTraps") { - let input = getInt64(-1) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromInt64(-1)_AlwaysFails") { - let input = getInt64(-1) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromInt64(0)_NeverTraps") { - let input = getInt64(0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromInt64(0)_NeverFails") { - let input = getInt64(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromInt64(4294967295)_NeverTraps") { - let input = getInt64(4294967295) - let actual = UInt(input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromInt64(4294967295)_NeverFails") { - let input = getInt64(4294967295) - let actual = UInt(exactly: input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromInt64(4294967296)_AlwaysTraps") { - let input = getInt64(4294967296) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromInt64(4294967296)_AlwaysFails") { - let input = getInt64(4294967296) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromInt64(9223372036854775807)_AlwaysTraps") { - let input = getInt64(9223372036854775807) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromInt64(9223372036854775807)_AlwaysFails") { - let input = getInt64(9223372036854775807) - let actual = UInt(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt +.test("FromInt64_NeverTraps") +.forEach(in: [ + (getUInt(+0), getInt64(+0)), + (getUInt(+4294967295), getInt64(+4294967295)), +]) { + expectEqual($0.0, UInt($0.1)) +} + +FixedPointConversion_Debug32_ToUInt +.test("FromInt64_NeverFails") +.forEach(in: [ + (getUInt(+0), getInt64(+0)), + (getUInt(+4294967295), getInt64(+4294967295)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToUInt +.test("FromInt64_AlwaysTraps") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-1), + getInt64(+4294967296), + getInt64(+9223372036854775807), +]) { + expectCrashLater() + _blackHole(UInt($0)) +} + +FixedPointConversion_Debug32_ToUInt +.test("FromInt64_AlwaysFails") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-1), + getInt64(+4294967296), + getInt64(+9223372036854775807), +]) { + expectNil(UInt(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt: (0)...(4294967295) +// MARK: UInt: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt.test("FromUInt(0)_NeverTraps") { - let input = getUInt(0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromUInt(0)_NeverFails") { - let input = getUInt(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromUInt(4294967295)_NeverTraps") { - let input = getUInt(4294967295) - let actual = UInt(input) - expectEqual(4294967295, actual) +FixedPointConversion_Debug32_ToUInt +.test("FromUInt_NeverTraps") +.forEach(in: [ + (getUInt(+0), getUInt(+0)), + (getUInt(+4294967295), getUInt(+4294967295)), +]) { + expectEqual($0.0, UInt($0.1)) } -FixedPointConversion_Debug32_ToUInt.test("FromUInt(4294967295)_NeverFails") { - let input = getUInt(4294967295) - let actual = UInt(exactly: input) - expectEqual(4294967295, actual) +FixedPointConversion_Debug32_ToUInt +.test("FromUInt_NeverFails") +.forEach(in: [ + (getUInt(+0), getUInt(+0)), + (getUInt(+4294967295), getUInt(+4294967295)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int: (-2147483648)...(2147483647) +// MARK: Int: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt.test("FromInt(-2147483648)_AlwaysTraps") { - let input = getInt(-2147483648) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromInt(-2147483648)_AlwaysFails") { - let input = getInt(-2147483648) - let actual = UInt(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt +.test("FromInt_NeverTraps") +.forEach(in: [ + (getUInt(+0), getInt(+0)), + (getUInt(+2147483647), getInt(+2147483647)), +]) { + expectEqual($0.0, UInt($0.1)) } -FixedPointConversion_Debug32_ToUInt.test("FromInt(-1)_AlwaysTraps") { - let input = getInt(-1) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } +FixedPointConversion_Debug32_ToUInt +.test("FromInt_NeverFails") +.forEach(in: [ + (getUInt(+0), getInt(+0)), + (getUInt(+2147483647), getInt(+2147483647)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) } -FixedPointConversion_Debug32_ToUInt.test("FromInt(-1)_AlwaysFails") { - let input = getInt(-1) - let actual = UInt(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt +.test("FromInt_AlwaysTraps") +.forEach(in: [ + getInt(-2147483648), + getInt(-1), +]) { + expectCrashLater() + _blackHole(UInt($0)) } -FixedPointConversion_Debug32_ToUInt.test("FromInt(0)_NeverTraps") { - let input = getInt(0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromInt(0)_NeverFails") { - let input = getInt(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromInt(2147483647)_NeverTraps") { - let input = getInt(2147483647) - let actual = UInt(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromInt(2147483647)_NeverFails") { - let input = getInt(2147483647) - let actual = UInt(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Debug32_ToUInt +.test("FromInt_AlwaysFails") +.forEach(in: [ + getInt(-2147483648), + getInt(-1), +]) { + expectNil(UInt(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float16: (-2047)...(2047) +// MARK: Float16: (-2047)...(+2047) //===----------------------------------------------------------------------===// #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -FixedPointConversion_Debug32_ToUInt.test("FromFloat16(-2047)_AlwaysTraps") { - let input = getFloat16(-2047) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat16(-2047)_AlwaysFails") { - let input = getFloat16(-2047) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat16(-128.5)_AlwaysTraps") { - let input = getFloat16(-128.5) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat16(-128.5)_AlwaysFails") { - let input = getFloat16(-128.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat16(-1)_AlwaysTraps") { - let input = getFloat16(-1) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat16(-1)_AlwaysFails") { - let input = getFloat16(-1) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat16(-0.5)_NeverTraps") { - let input = getFloat16(-0.5) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat16(-0.5)_AlwaysFails") { - let input = getFloat16(-0.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat16(0)_NeverTraps") { - let input = getFloat16(0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat16(0)_NeverFails") { - let input = getFloat16(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat16(-0.0)_NeverTraps") { - let input = getFloat16(-0.0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat16(-0.0)_NeverFails") { - let input = getFloat16(-0.0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat16(0.0)_NeverTraps") { - let input = getFloat16(0.0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat16(0.0)_NeverFails") { - let input = getFloat16(0.0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat16(0.5)_NeverTraps") { - let input = getFloat16(0.5) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat16(0.5)_AlwaysFails") { - let input = getFloat16(0.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat16(127.5)_NeverTraps") { - let input = getFloat16(127.5) - let actual = UInt(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat16(127.5)_AlwaysFails") { - let input = getFloat16(127.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat16(255.5)_NeverTraps") { - let input = getFloat16(255.5) - let actual = UInt(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat16(255.5)_AlwaysFails") { - let input = getFloat16(255.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat16(2047)_NeverTraps") { - let input = getFloat16(2047) - let actual = UInt(input) - expectEqual(2047, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat16(2047)_NeverFails") { - let input = getFloat16(2047) - let actual = UInt(exactly: input) - expectEqual(2047, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat16(-.infinity)_AlwaysTraps") { - let input = getFloat16(-.infinity) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat16(-.infinity)_AlwaysFails") { - let input = getFloat16(-.infinity) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat16(+.infinity)_AlwaysTraps") { - let input = getFloat16(+.infinity) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat16(+.infinity)_AlwaysFails") { - let input = getFloat16(+.infinity) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat16(-.nan)_AlwaysTraps") { - let input = getFloat16(-.nan) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat16(-.nan)_AlwaysFails") { - let input = getFloat16(-.nan) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat16(+.nan)_AlwaysTraps") { - let input = getFloat16(+.nan) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat16(+.nan)_AlwaysFails") { - let input = getFloat16(+.nan) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat16(-.signalingNaN)_AlwaysTraps") { - let input = getFloat16(-.signalingNaN) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat16(-.signalingNaN)_AlwaysFails") { - let input = getFloat16(-.signalingNaN) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat16(+.signalingNaN)_AlwaysTraps") { - let input = getFloat16(+.signalingNaN) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat16(+.signalingNaN)_AlwaysFails") { - let input = getFloat16(+.signalingNaN) - let actual = UInt(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt +.test("FromFloat16_NeverTraps") +.forEach(in: [ + (getUInt(+0), getFloat16(-0.5)), + (getUInt(+0), getFloat16(+0)), + (getUInt(+0), getFloat16(-0)), + (getUInt(+0), getFloat16(+0.5)), + (getUInt(+127), getFloat16(+127.5)), + (getUInt(+255), getFloat16(+255.5)), + (getUInt(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, UInt($0.1)) +} + +FixedPointConversion_Debug32_ToUInt +.test("FromFloat16_NeverFails") +.forEach(in: [ + (getUInt(+0), getFloat16(+0)), + (getUInt(+0), getFloat16(-0)), + (getUInt(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToUInt +.test("FromFloat16_AlwaysTraps") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-128.5), + getFloat16(-1), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt($0)) +} + +FixedPointConversion_Debug32_ToUInt +.test("FromFloat16_AlwaysFails") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-128.5), + getFloat16(-1), + getFloat16(-0.5), + getFloat16(+0.5), + getFloat16(+127.5), + getFloat16(+255.5), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectNil(UInt(exactly: $0)) } } #endif // Float16 //===----------------------------------------------------------------------===// -// MARK: Float32: (-16777215)...(16777215) +// MARK: Float32: (-16777215)...(+16777215) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt.test("FromFloat32(-16777215)_AlwaysTraps") { - let input = getFloat32(-16777215) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat32(-16777215)_AlwaysFails") { - let input = getFloat32(-16777215) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat32(-32768.5)_AlwaysTraps") { - let input = getFloat32(-32768.5) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat32(-32768.5)_AlwaysFails") { - let input = getFloat32(-32768.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat32(-128.5)_AlwaysTraps") { - let input = getFloat32(-128.5) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat32(-128.5)_AlwaysFails") { - let input = getFloat32(-128.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat32(-1)_AlwaysTraps") { - let input = getFloat32(-1) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat32(-1)_AlwaysFails") { - let input = getFloat32(-1) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat32(-0.5)_NeverTraps") { - let input = getFloat32(-0.5) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat32(-0.5)_AlwaysFails") { - let input = getFloat32(-0.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat32(0)_NeverTraps") { - let input = getFloat32(0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat32(0)_NeverFails") { - let input = getFloat32(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat32(-0.0)_NeverTraps") { - let input = getFloat32(-0.0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat32(-0.0)_NeverFails") { - let input = getFloat32(-0.0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat32(0.0)_NeverTraps") { - let input = getFloat32(0.0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat32(0.0)_NeverFails") { - let input = getFloat32(0.0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat32(0.5)_NeverTraps") { - let input = getFloat32(0.5) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat32(0.5)_AlwaysFails") { - let input = getFloat32(0.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat32(127.5)_NeverTraps") { - let input = getFloat32(127.5) - let actual = UInt(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat32(127.5)_AlwaysFails") { - let input = getFloat32(127.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat32(255.5)_NeverTraps") { - let input = getFloat32(255.5) - let actual = UInt(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat32(255.5)_AlwaysFails") { - let input = getFloat32(255.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat32(32767.5)_NeverTraps") { - let input = getFloat32(32767.5) - let actual = UInt(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat32(32767.5)_AlwaysFails") { - let input = getFloat32(32767.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat32(65535.5)_NeverTraps") { - let input = getFloat32(65535.5) - let actual = UInt(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat32(65535.5)_AlwaysFails") { - let input = getFloat32(65535.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat32(16777215)_NeverTraps") { - let input = getFloat32(16777215) - let actual = UInt(input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat32(16777215)_NeverFails") { - let input = getFloat32(16777215) - let actual = UInt(exactly: input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat32(-.infinity)_AlwaysTraps") { - let input = getFloat32(-.infinity) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat32(-.infinity)_AlwaysFails") { - let input = getFloat32(-.infinity) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat32(+.infinity)_AlwaysTraps") { - let input = getFloat32(+.infinity) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat32(+.infinity)_AlwaysFails") { - let input = getFloat32(+.infinity) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat32(-.nan)_AlwaysTraps") { - let input = getFloat32(-.nan) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat32(-.nan)_AlwaysFails") { - let input = getFloat32(-.nan) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat32(+.nan)_AlwaysTraps") { - let input = getFloat32(+.nan) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat32(+.nan)_AlwaysFails") { - let input = getFloat32(+.nan) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat32(-.signalingNaN)_AlwaysTraps") { - let input = getFloat32(-.signalingNaN) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat32(-.signalingNaN)_AlwaysFails") { - let input = getFloat32(-.signalingNaN) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat32(+.signalingNaN)_AlwaysTraps") { - let input = getFloat32(+.signalingNaN) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat32(+.signalingNaN)_AlwaysFails") { - let input = getFloat32(+.signalingNaN) - let actual = UInt(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt +.test("FromFloat32_NeverTraps") +.forEach(in: [ + (getUInt(+0), getFloat32(-0.5)), + (getUInt(+0), getFloat32(+0)), + (getUInt(+0), getFloat32(-0)), + (getUInt(+0), getFloat32(+0.5)), + (getUInt(+127), getFloat32(+127.5)), + (getUInt(+255), getFloat32(+255.5)), + (getUInt(+32767), getFloat32(+32767.5)), + (getUInt(+65535), getFloat32(+65535.5)), + (getUInt(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, UInt($0.1)) +} + +FixedPointConversion_Debug32_ToUInt +.test("FromFloat32_NeverFails") +.forEach(in: [ + (getUInt(+0), getFloat32(+0)), + (getUInt(+0), getFloat32(-0)), + (getUInt(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToUInt +.test("FromFloat32_AlwaysTraps") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-1), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt($0)) +} + +FixedPointConversion_Debug32_ToUInt +.test("FromFloat32_AlwaysFails") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-1), + getFloat32(-0.5), + getFloat32(+0.5), + getFloat32(+127.5), + getFloat32(+255.5), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectNil(UInt(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float64: (-9007199254740991)...(9007199254740991) +// MARK: Float64: (-9007199254740991)...(+9007199254740991) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(-9007199254740991)_AlwaysTraps") { - let input = getFloat64(-9007199254740991) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(-9007199254740991)_AlwaysFails") { - let input = getFloat64(-9007199254740991) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(-32768.5)_AlwaysTraps") { - let input = getFloat64(-32768.5) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(-32768.5)_AlwaysFails") { - let input = getFloat64(-32768.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(-128.5)_AlwaysTraps") { - let input = getFloat64(-128.5) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(-128.5)_AlwaysFails") { - let input = getFloat64(-128.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(-1)_AlwaysTraps") { - let input = getFloat64(-1) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(-1)_AlwaysFails") { - let input = getFloat64(-1) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(-0.5)_NeverTraps") { - let input = getFloat64(-0.5) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(-0.5)_AlwaysFails") { - let input = getFloat64(-0.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(0)_NeverTraps") { - let input = getFloat64(0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(0)_NeverFails") { - let input = getFloat64(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(-0.0)_NeverTraps") { - let input = getFloat64(-0.0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(-0.0)_NeverFails") { - let input = getFloat64(-0.0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(0.0)_NeverTraps") { - let input = getFloat64(0.0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(0.0)_NeverFails") { - let input = getFloat64(0.0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(0.5)_NeverTraps") { - let input = getFloat64(0.5) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(0.5)_AlwaysFails") { - let input = getFloat64(0.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(127.5)_NeverTraps") { - let input = getFloat64(127.5) - let actual = UInt(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(127.5)_AlwaysFails") { - let input = getFloat64(127.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(255.5)_NeverTraps") { - let input = getFloat64(255.5) - let actual = UInt(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(255.5)_AlwaysFails") { - let input = getFloat64(255.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(32767.5)_NeverTraps") { - let input = getFloat64(32767.5) - let actual = UInt(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(32767.5)_AlwaysFails") { - let input = getFloat64(32767.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(65535.5)_NeverTraps") { - let input = getFloat64(65535.5) - let actual = UInt(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(65535.5)_AlwaysFails") { - let input = getFloat64(65535.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(4294967295)_NeverTraps") { - let input = getFloat64(4294967295) - let actual = UInt(input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(4294967295)_NeverFails") { - let input = getFloat64(4294967295) - let actual = UInt(exactly: input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(4294967296)_AlwaysTraps") { - let input = getFloat64(4294967296) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(4294967296)_AlwaysFails") { - let input = getFloat64(4294967296) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(9007199254740991)_AlwaysTraps") { - let input = getFloat64(9007199254740991) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(9007199254740991)_AlwaysFails") { - let input = getFloat64(9007199254740991) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(-.infinity)_AlwaysTraps") { - let input = getFloat64(-.infinity) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(-.infinity)_AlwaysFails") { - let input = getFloat64(-.infinity) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(+.infinity)_AlwaysTraps") { - let input = getFloat64(+.infinity) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(+.infinity)_AlwaysFails") { - let input = getFloat64(+.infinity) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(-.nan)_AlwaysTraps") { - let input = getFloat64(-.nan) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(-.nan)_AlwaysFails") { - let input = getFloat64(-.nan) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(+.nan)_AlwaysTraps") { - let input = getFloat64(+.nan) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(+.nan)_AlwaysFails") { - let input = getFloat64(+.nan) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(-.signalingNaN)_AlwaysTraps") { - let input = getFloat64(-.signalingNaN) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(-.signalingNaN)_AlwaysFails") { - let input = getFloat64(-.signalingNaN) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(+.signalingNaN)_AlwaysTraps") { - let input = getFloat64(+.signalingNaN) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat64(+.signalingNaN)_AlwaysFails") { - let input = getFloat64(+.signalingNaN) - let actual = UInt(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt +.test("FromFloat64_NeverTraps") +.forEach(in: [ + (getUInt(+0), getFloat64(-0.5)), + (getUInt(+0), getFloat64(+0)), + (getUInt(+0), getFloat64(-0)), + (getUInt(+0), getFloat64(+0.5)), + (getUInt(+127), getFloat64(+127.5)), + (getUInt(+255), getFloat64(+255.5)), + (getUInt(+32767), getFloat64(+32767.5)), + (getUInt(+65535), getFloat64(+65535.5)), + (getUInt(+4294967295), getFloat64(+4294967295)), +]) { + expectEqual($0.0, UInt($0.1)) +} + +FixedPointConversion_Debug32_ToUInt +.test("FromFloat64_NeverFails") +.forEach(in: [ + (getUInt(+0), getFloat64(+0)), + (getUInt(+0), getFloat64(-0)), + (getUInt(+4294967295), getFloat64(+4294967295)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToUInt +.test("FromFloat64_AlwaysTraps") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-1), + getFloat64(+4294967296), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt($0)) +} + +FixedPointConversion_Debug32_ToUInt +.test("FromFloat64_AlwaysFails") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-1), + getFloat64(-0.5), + getFloat64(+0.5), + getFloat64(+127.5), + getFloat64(+255.5), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(+4294967296), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectNil(UInt(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float80: (-18446744073709551615)...(18446744073709551615) +// MARK: Float80: (-18446744073709551615)...(+18446744073709551615) //===----------------------------------------------------------------------===// #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(-18446744073709551615)_AlwaysTraps") { - let input = getFloat80(-18446744073709551615) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(-18446744073709551615)_AlwaysFails") { - let input = getFloat80(-18446744073709551615) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(-32768.5)_AlwaysTraps") { - let input = getFloat80(-32768.5) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(-32768.5)_AlwaysFails") { - let input = getFloat80(-32768.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(-128.5)_AlwaysTraps") { - let input = getFloat80(-128.5) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(-128.5)_AlwaysFails") { - let input = getFloat80(-128.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(-1)_AlwaysTraps") { - let input = getFloat80(-1) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(-1)_AlwaysFails") { - let input = getFloat80(-1) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(-0.5)_NeverTraps") { - let input = getFloat80(-0.5) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(-0.5)_AlwaysFails") { - let input = getFloat80(-0.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(0)_NeverTraps") { - let input = getFloat80(0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(0)_NeverFails") { - let input = getFloat80(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(-0.0)_NeverTraps") { - let input = getFloat80(-0.0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(-0.0)_NeverFails") { - let input = getFloat80(-0.0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(0.0)_NeverTraps") { - let input = getFloat80(0.0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(0.0)_NeverFails") { - let input = getFloat80(0.0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(0.5)_NeverTraps") { - let input = getFloat80(0.5) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(0.5)_AlwaysFails") { - let input = getFloat80(0.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(127.5)_NeverTraps") { - let input = getFloat80(127.5) - let actual = UInt(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(127.5)_AlwaysFails") { - let input = getFloat80(127.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(255.5)_NeverTraps") { - let input = getFloat80(255.5) - let actual = UInt(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(255.5)_AlwaysFails") { - let input = getFloat80(255.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(32767.5)_NeverTraps") { - let input = getFloat80(32767.5) - let actual = UInt(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(32767.5)_AlwaysFails") { - let input = getFloat80(32767.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(65535.5)_NeverTraps") { - let input = getFloat80(65535.5) - let actual = UInt(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(65535.5)_AlwaysFails") { - let input = getFloat80(65535.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(4294967295)_NeverTraps") { - let input = getFloat80(4294967295) - let actual = UInt(input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(4294967295)_NeverFails") { - let input = getFloat80(4294967295) - let actual = UInt(exactly: input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(4294967296)_AlwaysTraps") { - let input = getFloat80(4294967296) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(4294967296)_AlwaysFails") { - let input = getFloat80(4294967296) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(18446744073709551615)_AlwaysTraps") { - let input = getFloat80(18446744073709551615) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(18446744073709551615)_AlwaysFails") { - let input = getFloat80(18446744073709551615) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(-.infinity)_AlwaysTraps") { - let input = getFloat80(-.infinity) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(-.infinity)_AlwaysFails") { - let input = getFloat80(-.infinity) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(+.infinity)_AlwaysTraps") { - let input = getFloat80(+.infinity) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(+.infinity)_AlwaysFails") { - let input = getFloat80(+.infinity) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(-.nan)_AlwaysTraps") { - let input = getFloat80(-.nan) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(-.nan)_AlwaysFails") { - let input = getFloat80(-.nan) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(+.nan)_AlwaysTraps") { - let input = getFloat80(+.nan) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(+.nan)_AlwaysFails") { - let input = getFloat80(+.nan) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(-.signalingNaN)_AlwaysTraps") { - let input = getFloat80(-.signalingNaN) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(-.signalingNaN)_AlwaysFails") { - let input = getFloat80(-.signalingNaN) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(+.signalingNaN)_AlwaysTraps") { - let input = getFloat80(+.signalingNaN) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt.test("FromFloat80(+.signalingNaN)_AlwaysFails") { - let input = getFloat80(+.signalingNaN) - let actual = UInt(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt +.test("FromFloat80_NeverTraps") +.forEach(in: [ + (getUInt(+0), getFloat80(-0.5)), + (getUInt(+0), getFloat80(+0)), + (getUInt(+0), getFloat80(-0)), + (getUInt(+0), getFloat80(+0.5)), + (getUInt(+127), getFloat80(+127.5)), + (getUInt(+255), getFloat80(+255.5)), + (getUInt(+32767), getFloat80(+32767.5)), + (getUInt(+65535), getFloat80(+65535.5)), + (getUInt(+4294967295), getFloat80(+4294967295)), +]) { + expectEqual($0.0, UInt($0.1)) +} + +FixedPointConversion_Debug32_ToUInt +.test("FromFloat80_NeverFails") +.forEach(in: [ + (getUInt(+0), getFloat80(+0)), + (getUInt(+0), getFloat80(-0)), + (getUInt(+4294967295), getFloat80(+4294967295)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToUInt +.test("FromFloat80_AlwaysTraps") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-1), + getFloat80(+4294967296), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt($0)) +} + +FixedPointConversion_Debug32_ToUInt +.test("FromFloat80_AlwaysFails") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-1), + getFloat80(-0.5), + getFloat80(+0.5), + getFloat80(+127.5), + getFloat80(+255.5), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(+4294967296), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectNil(UInt(exactly: $0)) } #endif // Float80 diff --git a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug32_ToUInt16.swift b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug32_ToUInt16.swift index 154a00402ec25..320d5d2f01ede 100644 --- a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug32_ToUInt16.swift +++ b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug32_ToUInt16.swift @@ -14,1704 +14,690 @@ import StdlibUnittest -let FixedPointConversion_Debug32_ToUInt16 = TestSuite("FixedPointConversion_Debug32_ToUInt16") +let FixedPointConversion_Debug32_ToUInt16 = TestSuite( + "FixedPointConversion_Debug32_ToUInt16" +) //===----------------------------------------------------------------------===// -// MARK: UInt8: (0)...(255) +// MARK: UInt8: (+0)...(+255) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt16.test("FromUInt8(0)_NeverTraps") { - let input = getUInt8(0) - let actual = UInt16(input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToUInt16 +.test("FromUInt8_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getUInt8(+0)), + (getUInt16(+255), getUInt8(+255)), +]) { + expectEqual($0.0, UInt16($0.1)) } -FixedPointConversion_Debug32_ToUInt16.test("FromUInt8(0)_NeverFails") { - let input = getUInt8(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromUInt8(255)_NeverTraps") { - let input = getUInt8(255) - let actual = UInt16(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromUInt8(255)_NeverFails") { - let input = getUInt8(255) - let actual = UInt16(exactly: input) - expectEqual(255, actual) +FixedPointConversion_Debug32_ToUInt16 +.test("FromUInt8_NeverFails") +.forEach(in: [ + (getUInt16(+0), getUInt8(+0)), + (getUInt16(+255), getUInt8(+255)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int8: (-128)...(127) +// MARK: Int8: (-128)...(+127) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt16.test("FromInt8(-128)_AlwaysTraps") { - let input = getInt8(-128) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt8(-128)_AlwaysFails") { - let input = getInt8(-128) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt8(-1)_AlwaysTraps") { - let input = getInt8(-1) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt8(-1)_AlwaysFails") { - let input = getInt8(-1) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt16 +.test("FromInt8_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getInt8(+0)), + (getUInt16(+127), getInt8(+127)), +]) { + expectEqual($0.0, UInt16($0.1)) } -FixedPointConversion_Debug32_ToUInt16.test("FromInt8(0)_NeverTraps") { - let input = getInt8(0) - let actual = UInt16(input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToUInt16 +.test("FromInt8_NeverFails") +.forEach(in: [ + (getUInt16(+0), getInt8(+0)), + (getUInt16(+127), getInt8(+127)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) } -FixedPointConversion_Debug32_ToUInt16.test("FromInt8(0)_NeverFails") { - let input = getInt8(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToUInt16 +.test("FromInt8_AlwaysTraps") +.forEach(in: [ + getInt8(-128), + getInt8(-1), +]) { + expectCrashLater() + _blackHole(UInt16($0)) } -FixedPointConversion_Debug32_ToUInt16.test("FromInt8(127)_NeverTraps") { - let input = getInt8(127) - let actual = UInt16(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt8(127)_NeverFails") { - let input = getInt8(127) - let actual = UInt16(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Debug32_ToUInt16 +.test("FromInt8_AlwaysFails") +.forEach(in: [ + getInt8(-128), + getInt8(-1), +]) { + expectNil(UInt16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt16: (0)...(65535) +// MARK: UInt16: (+0)...(+65535) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt16.test("FromUInt16(0)_NeverTraps") { - let input = getUInt16(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromUInt16(0)_NeverFails") { - let input = getUInt16(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToUInt16 +.test("FromUInt16_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getUInt16(+0)), + (getUInt16(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, UInt16($0.1)) } -FixedPointConversion_Debug32_ToUInt16.test("FromUInt16(65535)_NeverTraps") { - let input = getUInt16(65535) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromUInt16(65535)_NeverFails") { - let input = getUInt16(65535) - let actual = UInt16(exactly: input) - expectEqual(65535, actual) +FixedPointConversion_Debug32_ToUInt16 +.test("FromUInt16_NeverFails") +.forEach(in: [ + (getUInt16(+0), getUInt16(+0)), + (getUInt16(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int16: (-32768)...(32767) +// MARK: Int16: (-32768)...(+32767) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt16.test("FromInt16(-32768)_AlwaysTraps") { - let input = getInt16(-32768) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt16(-32768)_AlwaysFails") { - let input = getInt16(-32768) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt16(-1)_AlwaysTraps") { - let input = getInt16(-1) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt16(-1)_AlwaysFails") { - let input = getInt16(-1) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt16(0)_NeverTraps") { - let input = getInt16(0) - let actual = UInt16(input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToUInt16 +.test("FromInt16_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getInt16(+0)), + (getUInt16(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, UInt16($0.1)) } -FixedPointConversion_Debug32_ToUInt16.test("FromInt16(0)_NeverFails") { - let input = getInt16(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToUInt16 +.test("FromInt16_NeverFails") +.forEach(in: [ + (getUInt16(+0), getInt16(+0)), + (getUInt16(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) } -FixedPointConversion_Debug32_ToUInt16.test("FromInt16(32767)_NeverTraps") { - let input = getInt16(32767) - let actual = UInt16(input) - expectEqual(32767, actual) +FixedPointConversion_Debug32_ToUInt16 +.test("FromInt16_AlwaysTraps") +.forEach(in: [ + getInt16(-32768), + getInt16(-1), +]) { + expectCrashLater() + _blackHole(UInt16($0)) } -FixedPointConversion_Debug32_ToUInt16.test("FromInt16(32767)_NeverFails") { - let input = getInt16(32767) - let actual = UInt16(exactly: input) - expectEqual(32767, actual) +FixedPointConversion_Debug32_ToUInt16 +.test("FromInt16_AlwaysFails") +.forEach(in: [ + getInt16(-32768), + getInt16(-1), +]) { + expectNil(UInt16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt32: (0)...(4294967295) +// MARK: UInt32: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt16.test("FromUInt32(0)_NeverTraps") { - let input = getUInt32(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromUInt32(0)_NeverFails") { - let input = getUInt32(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromUInt32(65535)_NeverTraps") { - let input = getUInt32(65535) - let actual = UInt16(input) - expectEqual(65535, actual) +FixedPointConversion_Debug32_ToUInt16 +.test("FromUInt32_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getUInt32(+0)), + (getUInt16(+65535), getUInt32(+65535)), +]) { + expectEqual($0.0, UInt16($0.1)) } -FixedPointConversion_Debug32_ToUInt16.test("FromUInt32(65535)_NeverFails") { - let input = getUInt32(65535) - let actual = UInt16(exactly: input) - expectEqual(65535, actual) +FixedPointConversion_Debug32_ToUInt16 +.test("FromUInt32_NeverFails") +.forEach(in: [ + (getUInt16(+0), getUInt32(+0)), + (getUInt16(+65535), getUInt32(+65535)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) } -FixedPointConversion_Debug32_ToUInt16.test("FromUInt32(65536)_AlwaysTraps") { - let input = getUInt32(65536) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } +FixedPointConversion_Debug32_ToUInt16 +.test("FromUInt32_AlwaysTraps") +.forEach(in: [ + getUInt32(+65536), + getUInt32(+4294967295), +]) { + expectCrashLater() + _blackHole(UInt16($0)) } -FixedPointConversion_Debug32_ToUInt16.test("FromUInt32(65536)_AlwaysFails") { - let input = getUInt32(65536) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromUInt32(4294967295)_AlwaysTraps") { - let input = getUInt32(4294967295) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromUInt32(4294967295)_AlwaysFails") { - let input = getUInt32(4294967295) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt16 +.test("FromUInt32_AlwaysFails") +.forEach(in: [ + getUInt32(+65536), + getUInt32(+4294967295), +]) { + expectNil(UInt16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int32: (-2147483648)...(2147483647) +// MARK: Int32: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt16.test("FromInt32(-2147483648)_AlwaysTraps") { - let input = getInt32(-2147483648) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt32(-2147483648)_AlwaysFails") { - let input = getInt32(-2147483648) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt32(-1)_AlwaysTraps") { - let input = getInt32(-1) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt32(-1)_AlwaysFails") { - let input = getInt32(-1) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt32(0)_NeverTraps") { - let input = getInt32(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt32(0)_NeverFails") { - let input = getInt32(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt32(65535)_NeverTraps") { - let input = getInt32(65535) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt32(65535)_NeverFails") { - let input = getInt32(65535) - let actual = UInt16(exactly: input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt32(65536)_AlwaysTraps") { - let input = getInt32(65536) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt32(65536)_AlwaysFails") { - let input = getInt32(65536) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt32(2147483647)_AlwaysTraps") { - let input = getInt32(2147483647) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt32(2147483647)_AlwaysFails") { - let input = getInt32(2147483647) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt16 +.test("FromInt32_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getInt32(+0)), + (getUInt16(+65535), getInt32(+65535)), +]) { + expectEqual($0.0, UInt16($0.1)) +} + +FixedPointConversion_Debug32_ToUInt16 +.test("FromInt32_NeverFails") +.forEach(in: [ + (getUInt16(+0), getInt32(+0)), + (getUInt16(+65535), getInt32(+65535)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToUInt16 +.test("FromInt32_AlwaysTraps") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-1), + getInt32(+65536), + getInt32(+2147483647), +]) { + expectCrashLater() + _blackHole(UInt16($0)) +} + +FixedPointConversion_Debug32_ToUInt16 +.test("FromInt32_AlwaysFails") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-1), + getInt32(+65536), + getInt32(+2147483647), +]) { + expectNil(UInt16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt64: (0)...(18446744073709551615) +// MARK: UInt64: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt16.test("FromUInt64(0)_NeverTraps") { - let input = getUInt64(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromUInt64(0)_NeverFails") { - let input = getUInt64(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromUInt64(65535)_NeverTraps") { - let input = getUInt64(65535) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromUInt64(65535)_NeverFails") { - let input = getUInt64(65535) - let actual = UInt16(exactly: input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromUInt64(65536)_AlwaysTraps") { - let input = getUInt64(65536) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } +FixedPointConversion_Debug32_ToUInt16 +.test("FromUInt64_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getUInt64(+0)), + (getUInt16(+65535), getUInt64(+65535)), +]) { + expectEqual($0.0, UInt16($0.1)) } -FixedPointConversion_Debug32_ToUInt16.test("FromUInt64(65536)_AlwaysFails") { - let input = getUInt64(65536) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt16 +.test("FromUInt64_NeverFails") +.forEach(in: [ + (getUInt16(+0), getUInt64(+0)), + (getUInt16(+65535), getUInt64(+65535)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) } -FixedPointConversion_Debug32_ToUInt16.test("FromUInt64(18446744073709551615)_AlwaysTraps") { - let input = getUInt64(18446744073709551615) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } +FixedPointConversion_Debug32_ToUInt16 +.test("FromUInt64_AlwaysTraps") +.forEach(in: [ + getUInt64(+65536), + getUInt64(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(UInt16($0)) } -FixedPointConversion_Debug32_ToUInt16.test("FromUInt64(18446744073709551615)_AlwaysFails") { - let input = getUInt64(18446744073709551615) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt16 +.test("FromUInt64_AlwaysFails") +.forEach(in: [ + getUInt64(+65536), + getUInt64(+18446744073709551615), +]) { + expectNil(UInt16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int64: (-9223372036854775808)...(9223372036854775807) +// MARK: Int64: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt16.test("FromInt64(-9223372036854775808)_AlwaysTraps") { - let input = getInt64(-9223372036854775808) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt64(-9223372036854775808)_AlwaysFails") { - let input = getInt64(-9223372036854775808) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt64(-1)_AlwaysTraps") { - let input = getInt64(-1) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt64(-1)_AlwaysFails") { - let input = getInt64(-1) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt64(0)_NeverTraps") { - let input = getInt64(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt64(0)_NeverFails") { - let input = getInt64(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt64(65535)_NeverTraps") { - let input = getInt64(65535) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt64(65535)_NeverFails") { - let input = getInt64(65535) - let actual = UInt16(exactly: input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt64(65536)_AlwaysTraps") { - let input = getInt64(65536) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt64(65536)_AlwaysFails") { - let input = getInt64(65536) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt64(9223372036854775807)_AlwaysTraps") { - let input = getInt64(9223372036854775807) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt64(9223372036854775807)_AlwaysFails") { - let input = getInt64(9223372036854775807) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt16 +.test("FromInt64_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getInt64(+0)), + (getUInt16(+65535), getInt64(+65535)), +]) { + expectEqual($0.0, UInt16($0.1)) +} + +FixedPointConversion_Debug32_ToUInt16 +.test("FromInt64_NeverFails") +.forEach(in: [ + (getUInt16(+0), getInt64(+0)), + (getUInt16(+65535), getInt64(+65535)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToUInt16 +.test("FromInt64_AlwaysTraps") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-1), + getInt64(+65536), + getInt64(+9223372036854775807), +]) { + expectCrashLater() + _blackHole(UInt16($0)) +} + +FixedPointConversion_Debug32_ToUInt16 +.test("FromInt64_AlwaysFails") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-1), + getInt64(+65536), + getInt64(+9223372036854775807), +]) { + expectNil(UInt16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt: (0)...(4294967295) +// MARK: UInt: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt16.test("FromUInt(0)_NeverTraps") { - let input = getUInt(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromUInt(0)_NeverFails") { - let input = getUInt(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromUInt(65535)_NeverTraps") { - let input = getUInt(65535) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromUInt(65535)_NeverFails") { - let input = getUInt(65535) - let actual = UInt16(exactly: input) - expectEqual(65535, actual) +FixedPointConversion_Debug32_ToUInt16 +.test("FromUInt_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getUInt(+0)), + (getUInt16(+65535), getUInt(+65535)), +]) { + expectEqual($0.0, UInt16($0.1)) } -FixedPointConversion_Debug32_ToUInt16.test("FromUInt(65536)_AlwaysTraps") { - let input = getUInt(65536) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } +FixedPointConversion_Debug32_ToUInt16 +.test("FromUInt_NeverFails") +.forEach(in: [ + (getUInt16(+0), getUInt(+0)), + (getUInt16(+65535), getUInt(+65535)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) } -FixedPointConversion_Debug32_ToUInt16.test("FromUInt(65536)_AlwaysFails") { - let input = getUInt(65536) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt16 +.test("FromUInt_AlwaysTraps") +.forEach(in: [ + getUInt(+65536), + getUInt(+4294967295), +]) { + expectCrashLater() + _blackHole(UInt16($0)) } -FixedPointConversion_Debug32_ToUInt16.test("FromUInt(4294967295)_AlwaysTraps") { - let input = getUInt(4294967295) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromUInt(4294967295)_AlwaysFails") { - let input = getUInt(4294967295) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt16 +.test("FromUInt_AlwaysFails") +.forEach(in: [ + getUInt(+65536), + getUInt(+4294967295), +]) { + expectNil(UInt16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int: (-2147483648)...(2147483647) +// MARK: Int: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt16.test("FromInt(-2147483648)_AlwaysTraps") { - let input = getInt(-2147483648) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt(-2147483648)_AlwaysFails") { - let input = getInt(-2147483648) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt(-1)_AlwaysTraps") { - let input = getInt(-1) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt(-1)_AlwaysFails") { - let input = getInt(-1) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt(0)_NeverTraps") { - let input = getInt(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt(0)_NeverFails") { - let input = getInt(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt(65535)_NeverTraps") { - let input = getInt(65535) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt(65535)_NeverFails") { - let input = getInt(65535) - let actual = UInt16(exactly: input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt(65536)_AlwaysTraps") { - let input = getInt(65536) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt(65536)_AlwaysFails") { - let input = getInt(65536) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt(2147483647)_AlwaysTraps") { - let input = getInt(2147483647) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromInt(2147483647)_AlwaysFails") { - let input = getInt(2147483647) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt16 +.test("FromInt_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getInt(+0)), + (getUInt16(+65535), getInt(+65535)), +]) { + expectEqual($0.0, UInt16($0.1)) +} + +FixedPointConversion_Debug32_ToUInt16 +.test("FromInt_NeverFails") +.forEach(in: [ + (getUInt16(+0), getInt(+0)), + (getUInt16(+65535), getInt(+65535)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToUInt16 +.test("FromInt_AlwaysTraps") +.forEach(in: [ + getInt(-2147483648), + getInt(-1), + getInt(+65536), + getInt(+2147483647), +]) { + expectCrashLater() + _blackHole(UInt16($0)) +} + +FixedPointConversion_Debug32_ToUInt16 +.test("FromInt_AlwaysFails") +.forEach(in: [ + getInt(-2147483648), + getInt(-1), + getInt(+65536), + getInt(+2147483647), +]) { + expectNil(UInt16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float16: (-2047)...(2047) +// MARK: Float16: (-2047)...(+2047) //===----------------------------------------------------------------------===// #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -FixedPointConversion_Debug32_ToUInt16.test("FromFloat16(-2047)_AlwaysTraps") { - let input = getFloat16(-2047) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat16(-2047)_AlwaysFails") { - let input = getFloat16(-2047) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat16(-128.5)_AlwaysTraps") { - let input = getFloat16(-128.5) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat16(-128.5)_AlwaysFails") { - let input = getFloat16(-128.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat16(-1)_AlwaysTraps") { - let input = getFloat16(-1) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat16(-1)_AlwaysFails") { - let input = getFloat16(-1) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat16(-0.5)_NeverTraps") { - let input = getFloat16(-0.5) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat16(-0.5)_AlwaysFails") { - let input = getFloat16(-0.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat16(0)_NeverTraps") { - let input = getFloat16(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat16(0)_NeverFails") { - let input = getFloat16(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat16(-0.0)_NeverTraps") { - let input = getFloat16(-0.0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat16(-0.0)_NeverFails") { - let input = getFloat16(-0.0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat16(0.0)_NeverTraps") { - let input = getFloat16(0.0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat16(0.0)_NeverFails") { - let input = getFloat16(0.0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat16(0.5)_NeverTraps") { - let input = getFloat16(0.5) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat16(0.5)_AlwaysFails") { - let input = getFloat16(0.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat16(127.5)_NeverTraps") { - let input = getFloat16(127.5) - let actual = UInt16(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat16(127.5)_AlwaysFails") { - let input = getFloat16(127.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat16(255.5)_NeverTraps") { - let input = getFloat16(255.5) - let actual = UInt16(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat16(255.5)_AlwaysFails") { - let input = getFloat16(255.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat16(2047)_NeverTraps") { - let input = getFloat16(2047) - let actual = UInt16(input) - expectEqual(2047, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat16(2047)_NeverFails") { - let input = getFloat16(2047) - let actual = UInt16(exactly: input) - expectEqual(2047, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat16(-.infinity)_AlwaysTraps") { - let input = getFloat16(-.infinity) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat16(-.infinity)_AlwaysFails") { - let input = getFloat16(-.infinity) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat16(+.infinity)_AlwaysTraps") { - let input = getFloat16(+.infinity) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat16(+.infinity)_AlwaysFails") { - let input = getFloat16(+.infinity) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat16(-.nan)_AlwaysTraps") { - let input = getFloat16(-.nan) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat16(-.nan)_AlwaysFails") { - let input = getFloat16(-.nan) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat16(+.nan)_AlwaysTraps") { - let input = getFloat16(+.nan) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat16(+.nan)_AlwaysFails") { - let input = getFloat16(+.nan) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat16(-.signalingNaN)_AlwaysTraps") { - let input = getFloat16(-.signalingNaN) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat16(-.signalingNaN)_AlwaysFails") { - let input = getFloat16(-.signalingNaN) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat16(+.signalingNaN)_AlwaysTraps") { - let input = getFloat16(+.signalingNaN) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat16(+.signalingNaN)_AlwaysFails") { - let input = getFloat16(+.signalingNaN) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt16 +.test("FromFloat16_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getFloat16(-0.5)), + (getUInt16(+0), getFloat16(+0)), + (getUInt16(+0), getFloat16(-0)), + (getUInt16(+0), getFloat16(+0.5)), + (getUInt16(+127), getFloat16(+127.5)), + (getUInt16(+255), getFloat16(+255.5)), + (getUInt16(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, UInt16($0.1)) +} + +FixedPointConversion_Debug32_ToUInt16 +.test("FromFloat16_NeverFails") +.forEach(in: [ + (getUInt16(+0), getFloat16(+0)), + (getUInt16(+0), getFloat16(-0)), + (getUInt16(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToUInt16 +.test("FromFloat16_AlwaysTraps") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-128.5), + getFloat16(-1), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt16($0)) +} + +FixedPointConversion_Debug32_ToUInt16 +.test("FromFloat16_AlwaysFails") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-128.5), + getFloat16(-1), + getFloat16(-0.5), + getFloat16(+0.5), + getFloat16(+127.5), + getFloat16(+255.5), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectNil(UInt16(exactly: $0)) } } #endif // Float16 //===----------------------------------------------------------------------===// -// MARK: Float32: (-16777215)...(16777215) +// MARK: Float32: (-16777215)...(+16777215) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(-16777215)_AlwaysTraps") { - let input = getFloat32(-16777215) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(-16777215)_AlwaysFails") { - let input = getFloat32(-16777215) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(-32768.5)_AlwaysTraps") { - let input = getFloat32(-32768.5) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(-32768.5)_AlwaysFails") { - let input = getFloat32(-32768.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(-128.5)_AlwaysTraps") { - let input = getFloat32(-128.5) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(-128.5)_AlwaysFails") { - let input = getFloat32(-128.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(-1)_AlwaysTraps") { - let input = getFloat32(-1) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(-1)_AlwaysFails") { - let input = getFloat32(-1) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(-0.5)_NeverTraps") { - let input = getFloat32(-0.5) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(-0.5)_AlwaysFails") { - let input = getFloat32(-0.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(0)_NeverTraps") { - let input = getFloat32(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(0)_NeverFails") { - let input = getFloat32(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(-0.0)_NeverTraps") { - let input = getFloat32(-0.0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(-0.0)_NeverFails") { - let input = getFloat32(-0.0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(0.0)_NeverTraps") { - let input = getFloat32(0.0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(0.0)_NeverFails") { - let input = getFloat32(0.0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(0.5)_NeverTraps") { - let input = getFloat32(0.5) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(0.5)_AlwaysFails") { - let input = getFloat32(0.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(127.5)_NeverTraps") { - let input = getFloat32(127.5) - let actual = UInt16(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(127.5)_AlwaysFails") { - let input = getFloat32(127.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(255.5)_NeverTraps") { - let input = getFloat32(255.5) - let actual = UInt16(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(255.5)_AlwaysFails") { - let input = getFloat32(255.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(32767.5)_NeverTraps") { - let input = getFloat32(32767.5) - let actual = UInt16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(32767.5)_AlwaysFails") { - let input = getFloat32(32767.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(65535)_NeverTraps") { - let input = getFloat32(65535) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(65535)_NeverFails") { - let input = getFloat32(65535) - let actual = UInt16(exactly: input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(65535.5)_NeverTraps") { - let input = getFloat32(65535.5) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(65535.5)_AlwaysFails") { - let input = getFloat32(65535.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(65536)_AlwaysTraps") { - let input = getFloat32(65536) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(65536)_AlwaysFails") { - let input = getFloat32(65536) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(16777215)_AlwaysTraps") { - let input = getFloat32(16777215) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(16777215)_AlwaysFails") { - let input = getFloat32(16777215) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(-.infinity)_AlwaysTraps") { - let input = getFloat32(-.infinity) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(-.infinity)_AlwaysFails") { - let input = getFloat32(-.infinity) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(+.infinity)_AlwaysTraps") { - let input = getFloat32(+.infinity) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(+.infinity)_AlwaysFails") { - let input = getFloat32(+.infinity) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(-.nan)_AlwaysTraps") { - let input = getFloat32(-.nan) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(-.nan)_AlwaysFails") { - let input = getFloat32(-.nan) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(+.nan)_AlwaysTraps") { - let input = getFloat32(+.nan) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(+.nan)_AlwaysFails") { - let input = getFloat32(+.nan) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(-.signalingNaN)_AlwaysTraps") { - let input = getFloat32(-.signalingNaN) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(-.signalingNaN)_AlwaysFails") { - let input = getFloat32(-.signalingNaN) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(+.signalingNaN)_AlwaysTraps") { - let input = getFloat32(+.signalingNaN) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat32(+.signalingNaN)_AlwaysFails") { - let input = getFloat32(+.signalingNaN) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt16 +.test("FromFloat32_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getFloat32(-0.5)), + (getUInt16(+0), getFloat32(+0)), + (getUInt16(+0), getFloat32(-0)), + (getUInt16(+0), getFloat32(+0.5)), + (getUInt16(+127), getFloat32(+127.5)), + (getUInt16(+255), getFloat32(+255.5)), + (getUInt16(+32767), getFloat32(+32767.5)), + (getUInt16(+65535), getFloat32(+65535)), + (getUInt16(+65535), getFloat32(+65535.5)), +]) { + expectEqual($0.0, UInt16($0.1)) +} + +FixedPointConversion_Debug32_ToUInt16 +.test("FromFloat32_NeverFails") +.forEach(in: [ + (getUInt16(+0), getFloat32(+0)), + (getUInt16(+0), getFloat32(-0)), + (getUInt16(+65535), getFloat32(+65535)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToUInt16 +.test("FromFloat32_AlwaysTraps") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-1), + getFloat32(+65536), + getFloat32(+16777215), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt16($0)) +} + +FixedPointConversion_Debug32_ToUInt16 +.test("FromFloat32_AlwaysFails") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-1), + getFloat32(-0.5), + getFloat32(+0.5), + getFloat32(+127.5), + getFloat32(+255.5), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(+65536), + getFloat32(+16777215), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectNil(UInt16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float64: (-9007199254740991)...(9007199254740991) +// MARK: Float64: (-9007199254740991)...(+9007199254740991) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(-9007199254740991)_AlwaysTraps") { - let input = getFloat64(-9007199254740991) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(-9007199254740991)_AlwaysFails") { - let input = getFloat64(-9007199254740991) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(-32768.5)_AlwaysTraps") { - let input = getFloat64(-32768.5) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(-32768.5)_AlwaysFails") { - let input = getFloat64(-32768.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(-128.5)_AlwaysTraps") { - let input = getFloat64(-128.5) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(-128.5)_AlwaysFails") { - let input = getFloat64(-128.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(-1)_AlwaysTraps") { - let input = getFloat64(-1) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(-1)_AlwaysFails") { - let input = getFloat64(-1) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(-0.5)_NeverTraps") { - let input = getFloat64(-0.5) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(-0.5)_AlwaysFails") { - let input = getFloat64(-0.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(0)_NeverTraps") { - let input = getFloat64(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(0)_NeverFails") { - let input = getFloat64(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(-0.0)_NeverTraps") { - let input = getFloat64(-0.0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(-0.0)_NeverFails") { - let input = getFloat64(-0.0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(0.0)_NeverTraps") { - let input = getFloat64(0.0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(0.0)_NeverFails") { - let input = getFloat64(0.0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(0.5)_NeverTraps") { - let input = getFloat64(0.5) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(0.5)_AlwaysFails") { - let input = getFloat64(0.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(127.5)_NeverTraps") { - let input = getFloat64(127.5) - let actual = UInt16(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(127.5)_AlwaysFails") { - let input = getFloat64(127.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(255.5)_NeverTraps") { - let input = getFloat64(255.5) - let actual = UInt16(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(255.5)_AlwaysFails") { - let input = getFloat64(255.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(32767.5)_NeverTraps") { - let input = getFloat64(32767.5) - let actual = UInt16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(32767.5)_AlwaysFails") { - let input = getFloat64(32767.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(65535)_NeverTraps") { - let input = getFloat64(65535) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(65535)_NeverFails") { - let input = getFloat64(65535) - let actual = UInt16(exactly: input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(65535.5)_NeverTraps") { - let input = getFloat64(65535.5) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(65535.5)_AlwaysFails") { - let input = getFloat64(65535.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(65536)_AlwaysTraps") { - let input = getFloat64(65536) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(65536)_AlwaysFails") { - let input = getFloat64(65536) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(9007199254740991)_AlwaysTraps") { - let input = getFloat64(9007199254740991) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(9007199254740991)_AlwaysFails") { - let input = getFloat64(9007199254740991) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(-.infinity)_AlwaysTraps") { - let input = getFloat64(-.infinity) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(-.infinity)_AlwaysFails") { - let input = getFloat64(-.infinity) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(+.infinity)_AlwaysTraps") { - let input = getFloat64(+.infinity) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(+.infinity)_AlwaysFails") { - let input = getFloat64(+.infinity) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(-.nan)_AlwaysTraps") { - let input = getFloat64(-.nan) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(-.nan)_AlwaysFails") { - let input = getFloat64(-.nan) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(+.nan)_AlwaysTraps") { - let input = getFloat64(+.nan) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(+.nan)_AlwaysFails") { - let input = getFloat64(+.nan) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(-.signalingNaN)_AlwaysTraps") { - let input = getFloat64(-.signalingNaN) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(-.signalingNaN)_AlwaysFails") { - let input = getFloat64(-.signalingNaN) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(+.signalingNaN)_AlwaysTraps") { - let input = getFloat64(+.signalingNaN) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat64(+.signalingNaN)_AlwaysFails") { - let input = getFloat64(+.signalingNaN) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt16 +.test("FromFloat64_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getFloat64(-0.5)), + (getUInt16(+0), getFloat64(+0)), + (getUInt16(+0), getFloat64(-0)), + (getUInt16(+0), getFloat64(+0.5)), + (getUInt16(+127), getFloat64(+127.5)), + (getUInt16(+255), getFloat64(+255.5)), + (getUInt16(+32767), getFloat64(+32767.5)), + (getUInt16(+65535), getFloat64(+65535)), + (getUInt16(+65535), getFloat64(+65535.5)), +]) { + expectEqual($0.0, UInt16($0.1)) +} + +FixedPointConversion_Debug32_ToUInt16 +.test("FromFloat64_NeverFails") +.forEach(in: [ + (getUInt16(+0), getFloat64(+0)), + (getUInt16(+0), getFloat64(-0)), + (getUInt16(+65535), getFloat64(+65535)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToUInt16 +.test("FromFloat64_AlwaysTraps") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-1), + getFloat64(+65536), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt16($0)) +} + +FixedPointConversion_Debug32_ToUInt16 +.test("FromFloat64_AlwaysFails") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-1), + getFloat64(-0.5), + getFloat64(+0.5), + getFloat64(+127.5), + getFloat64(+255.5), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(+65536), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectNil(UInt16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float80: (-18446744073709551615)...(18446744073709551615) +// MARK: Float80: (-18446744073709551615)...(+18446744073709551615) //===----------------------------------------------------------------------===// #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(-18446744073709551615)_AlwaysTraps") { - let input = getFloat80(-18446744073709551615) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(-18446744073709551615)_AlwaysFails") { - let input = getFloat80(-18446744073709551615) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(-32768.5)_AlwaysTraps") { - let input = getFloat80(-32768.5) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(-32768.5)_AlwaysFails") { - let input = getFloat80(-32768.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(-128.5)_AlwaysTraps") { - let input = getFloat80(-128.5) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(-128.5)_AlwaysFails") { - let input = getFloat80(-128.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(-1)_AlwaysTraps") { - let input = getFloat80(-1) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(-1)_AlwaysFails") { - let input = getFloat80(-1) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(-0.5)_NeverTraps") { - let input = getFloat80(-0.5) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(-0.5)_AlwaysFails") { - let input = getFloat80(-0.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(0)_NeverTraps") { - let input = getFloat80(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(0)_NeverFails") { - let input = getFloat80(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(-0.0)_NeverTraps") { - let input = getFloat80(-0.0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(-0.0)_NeverFails") { - let input = getFloat80(-0.0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(0.0)_NeverTraps") { - let input = getFloat80(0.0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(0.0)_NeverFails") { - let input = getFloat80(0.0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(0.5)_NeverTraps") { - let input = getFloat80(0.5) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(0.5)_AlwaysFails") { - let input = getFloat80(0.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(127.5)_NeverTraps") { - let input = getFloat80(127.5) - let actual = UInt16(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(127.5)_AlwaysFails") { - let input = getFloat80(127.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(255.5)_NeverTraps") { - let input = getFloat80(255.5) - let actual = UInt16(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(255.5)_AlwaysFails") { - let input = getFloat80(255.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(32767.5)_NeverTraps") { - let input = getFloat80(32767.5) - let actual = UInt16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(32767.5)_AlwaysFails") { - let input = getFloat80(32767.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(65535)_NeverTraps") { - let input = getFloat80(65535) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(65535)_NeverFails") { - let input = getFloat80(65535) - let actual = UInt16(exactly: input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(65535.5)_NeverTraps") { - let input = getFloat80(65535.5) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(65535.5)_AlwaysFails") { - let input = getFloat80(65535.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(65536)_AlwaysTraps") { - let input = getFloat80(65536) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(65536)_AlwaysFails") { - let input = getFloat80(65536) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(18446744073709551615)_AlwaysTraps") { - let input = getFloat80(18446744073709551615) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(18446744073709551615)_AlwaysFails") { - let input = getFloat80(18446744073709551615) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(-.infinity)_AlwaysTraps") { - let input = getFloat80(-.infinity) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(-.infinity)_AlwaysFails") { - let input = getFloat80(-.infinity) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(+.infinity)_AlwaysTraps") { - let input = getFloat80(+.infinity) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(+.infinity)_AlwaysFails") { - let input = getFloat80(+.infinity) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(-.nan)_AlwaysTraps") { - let input = getFloat80(-.nan) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(-.nan)_AlwaysFails") { - let input = getFloat80(-.nan) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(+.nan)_AlwaysTraps") { - let input = getFloat80(+.nan) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(+.nan)_AlwaysFails") { - let input = getFloat80(+.nan) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(-.signalingNaN)_AlwaysTraps") { - let input = getFloat80(-.signalingNaN) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(-.signalingNaN)_AlwaysFails") { - let input = getFloat80(-.signalingNaN) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(+.signalingNaN)_AlwaysTraps") { - let input = getFloat80(+.signalingNaN) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt16.test("FromFloat80(+.signalingNaN)_AlwaysFails") { - let input = getFloat80(+.signalingNaN) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt16 +.test("FromFloat80_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getFloat80(-0.5)), + (getUInt16(+0), getFloat80(+0)), + (getUInt16(+0), getFloat80(-0)), + (getUInt16(+0), getFloat80(+0.5)), + (getUInt16(+127), getFloat80(+127.5)), + (getUInt16(+255), getFloat80(+255.5)), + (getUInt16(+32767), getFloat80(+32767.5)), + (getUInt16(+65535), getFloat80(+65535)), + (getUInt16(+65535), getFloat80(+65535.5)), +]) { + expectEqual($0.0, UInt16($0.1)) +} + +FixedPointConversion_Debug32_ToUInt16 +.test("FromFloat80_NeverFails") +.forEach(in: [ + (getUInt16(+0), getFloat80(+0)), + (getUInt16(+0), getFloat80(-0)), + (getUInt16(+65535), getFloat80(+65535)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToUInt16 +.test("FromFloat80_AlwaysTraps") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-1), + getFloat80(+65536), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt16($0)) +} + +FixedPointConversion_Debug32_ToUInt16 +.test("FromFloat80_AlwaysFails") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-1), + getFloat80(-0.5), + getFloat80(+0.5), + getFloat80(+127.5), + getFloat80(+255.5), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(+65536), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectNil(UInt16(exactly: $0)) } #endif // Float80 diff --git a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug32_ToUInt32.swift b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug32_ToUInt32.swift index 6c3ca0b96d5f7..78ffb5188a802 100644 --- a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug32_ToUInt32.swift +++ b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug32_ToUInt32.swift @@ -14,1564 +14,640 @@ import StdlibUnittest -let FixedPointConversion_Debug32_ToUInt32 = TestSuite("FixedPointConversion_Debug32_ToUInt32") +let FixedPointConversion_Debug32_ToUInt32 = TestSuite( + "FixedPointConversion_Debug32_ToUInt32" +) //===----------------------------------------------------------------------===// -// MARK: UInt8: (0)...(255) +// MARK: UInt8: (+0)...(+255) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt32.test("FromUInt8(0)_NeverTraps") { - let input = getUInt8(0) - let actual = UInt32(input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToUInt32 +.test("FromUInt8_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getUInt8(+0)), + (getUInt32(+255), getUInt8(+255)), +]) { + expectEqual($0.0, UInt32($0.1)) } -FixedPointConversion_Debug32_ToUInt32.test("FromUInt8(0)_NeverFails") { - let input = getUInt8(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromUInt8(255)_NeverTraps") { - let input = getUInt8(255) - let actual = UInt32(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromUInt8(255)_NeverFails") { - let input = getUInt8(255) - let actual = UInt32(exactly: input) - expectEqual(255, actual) +FixedPointConversion_Debug32_ToUInt32 +.test("FromUInt8_NeverFails") +.forEach(in: [ + (getUInt32(+0), getUInt8(+0)), + (getUInt32(+255), getUInt8(+255)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int8: (-128)...(127) +// MARK: Int8: (-128)...(+127) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt32.test("FromInt8(-128)_AlwaysTraps") { - let input = getInt8(-128) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } +FixedPointConversion_Debug32_ToUInt32 +.test("FromInt8_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getInt8(+0)), + (getUInt32(+127), getInt8(+127)), +]) { + expectEqual($0.0, UInt32($0.1)) } -FixedPointConversion_Debug32_ToUInt32.test("FromInt8(-128)_AlwaysFails") { - let input = getInt8(-128) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt32 +.test("FromInt8_NeverFails") +.forEach(in: [ + (getUInt32(+0), getInt8(+0)), + (getUInt32(+127), getInt8(+127)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) } -FixedPointConversion_Debug32_ToUInt32.test("FromInt8(-1)_AlwaysTraps") { - let input = getInt8(-1) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } +FixedPointConversion_Debug32_ToUInt32 +.test("FromInt8_AlwaysTraps") +.forEach(in: [ + getInt8(-128), + getInt8(-1), +]) { + expectCrashLater() + _blackHole(UInt32($0)) } -FixedPointConversion_Debug32_ToUInt32.test("FromInt8(-1)_AlwaysFails") { - let input = getInt8(-1) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromInt8(0)_NeverTraps") { - let input = getInt8(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromInt8(0)_NeverFails") { - let input = getInt8(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromInt8(127)_NeverTraps") { - let input = getInt8(127) - let actual = UInt32(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromInt8(127)_NeverFails") { - let input = getInt8(127) - let actual = UInt32(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Debug32_ToUInt32 +.test("FromInt8_AlwaysFails") +.forEach(in: [ + getInt8(-128), + getInt8(-1), +]) { + expectNil(UInt32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt16: (0)...(65535) +// MARK: UInt16: (+0)...(+65535) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt32.test("FromUInt16(0)_NeverTraps") { - let input = getUInt16(0) - let actual = UInt32(input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToUInt32 +.test("FromUInt16_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getUInt16(+0)), + (getUInt32(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, UInt32($0.1)) } -FixedPointConversion_Debug32_ToUInt32.test("FromUInt16(0)_NeverFails") { - let input = getUInt16(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromUInt16(65535)_NeverTraps") { - let input = getUInt16(65535) - let actual = UInt32(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromUInt16(65535)_NeverFails") { - let input = getUInt16(65535) - let actual = UInt32(exactly: input) - expectEqual(65535, actual) +FixedPointConversion_Debug32_ToUInt32 +.test("FromUInt16_NeverFails") +.forEach(in: [ + (getUInt32(+0), getUInt16(+0)), + (getUInt32(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int16: (-32768)...(32767) +// MARK: Int16: (-32768)...(+32767) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt32.test("FromInt16(-32768)_AlwaysTraps") { - let input = getInt16(-32768) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromInt16(-32768)_AlwaysFails") { - let input = getInt16(-32768) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromInt16(-1)_AlwaysTraps") { - let input = getInt16(-1) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromInt16(-1)_AlwaysFails") { - let input = getInt16(-1) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt32 +.test("FromInt16_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getInt16(+0)), + (getUInt32(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, UInt32($0.1)) } -FixedPointConversion_Debug32_ToUInt32.test("FromInt16(0)_NeverTraps") { - let input = getInt16(0) - let actual = UInt32(input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToUInt32 +.test("FromInt16_NeverFails") +.forEach(in: [ + (getUInt32(+0), getInt16(+0)), + (getUInt32(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) } -FixedPointConversion_Debug32_ToUInt32.test("FromInt16(0)_NeverFails") { - let input = getInt16(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToUInt32 +.test("FromInt16_AlwaysTraps") +.forEach(in: [ + getInt16(-32768), + getInt16(-1), +]) { + expectCrashLater() + _blackHole(UInt32($0)) } -FixedPointConversion_Debug32_ToUInt32.test("FromInt16(32767)_NeverTraps") { - let input = getInt16(32767) - let actual = UInt32(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromInt16(32767)_NeverFails") { - let input = getInt16(32767) - let actual = UInt32(exactly: input) - expectEqual(32767, actual) +FixedPointConversion_Debug32_ToUInt32 +.test("FromInt16_AlwaysFails") +.forEach(in: [ + getInt16(-32768), + getInt16(-1), +]) { + expectNil(UInt32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt32: (0)...(4294967295) +// MARK: UInt32: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt32.test("FromUInt32(0)_NeverTraps") { - let input = getUInt32(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromUInt32(0)_NeverFails") { - let input = getUInt32(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromUInt32(4294967295)_NeverTraps") { - let input = getUInt32(4294967295) - let actual = UInt32(input) - expectEqual(4294967295, actual) +FixedPointConversion_Debug32_ToUInt32 +.test("FromUInt32_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getUInt32(+0)), + (getUInt32(+4294967295), getUInt32(+4294967295)), +]) { + expectEqual($0.0, UInt32($0.1)) } -FixedPointConversion_Debug32_ToUInt32.test("FromUInt32(4294967295)_NeverFails") { - let input = getUInt32(4294967295) - let actual = UInt32(exactly: input) - expectEqual(4294967295, actual) +FixedPointConversion_Debug32_ToUInt32 +.test("FromUInt32_NeverFails") +.forEach(in: [ + (getUInt32(+0), getUInt32(+0)), + (getUInt32(+4294967295), getUInt32(+4294967295)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int32: (-2147483648)...(2147483647) +// MARK: Int32: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt32.test("FromInt32(-2147483648)_AlwaysTraps") { - let input = getInt32(-2147483648) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromInt32(-2147483648)_AlwaysFails") { - let input = getInt32(-2147483648) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromInt32(-1)_AlwaysTraps") { - let input = getInt32(-1) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } +FixedPointConversion_Debug32_ToUInt32 +.test("FromInt32_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getInt32(+0)), + (getUInt32(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, UInt32($0.1)) } -FixedPointConversion_Debug32_ToUInt32.test("FromInt32(-1)_AlwaysFails") { - let input = getInt32(-1) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt32 +.test("FromInt32_NeverFails") +.forEach(in: [ + (getUInt32(+0), getInt32(+0)), + (getUInt32(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) } -FixedPointConversion_Debug32_ToUInt32.test("FromInt32(0)_NeverTraps") { - let input = getInt32(0) - let actual = UInt32(input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToUInt32 +.test("FromInt32_AlwaysTraps") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-1), +]) { + expectCrashLater() + _blackHole(UInt32($0)) } -FixedPointConversion_Debug32_ToUInt32.test("FromInt32(0)_NeverFails") { - let input = getInt32(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromInt32(2147483647)_NeverTraps") { - let input = getInt32(2147483647) - let actual = UInt32(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromInt32(2147483647)_NeverFails") { - let input = getInt32(2147483647) - let actual = UInt32(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Debug32_ToUInt32 +.test("FromInt32_AlwaysFails") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-1), +]) { + expectNil(UInt32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt64: (0)...(18446744073709551615) +// MARK: UInt64: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt32.test("FromUInt64(0)_NeverTraps") { - let input = getUInt64(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromUInt64(0)_NeverFails") { - let input = getUInt64(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToUInt32 +.test("FromUInt64_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getUInt64(+0)), + (getUInt32(+4294967295), getUInt64(+4294967295)), +]) { + expectEqual($0.0, UInt32($0.1)) } -FixedPointConversion_Debug32_ToUInt32.test("FromUInt64(4294967295)_NeverTraps") { - let input = getUInt64(4294967295) - let actual = UInt32(input) - expectEqual(4294967295, actual) +FixedPointConversion_Debug32_ToUInt32 +.test("FromUInt64_NeverFails") +.forEach(in: [ + (getUInt32(+0), getUInt64(+0)), + (getUInt32(+4294967295), getUInt64(+4294967295)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) } -FixedPointConversion_Debug32_ToUInt32.test("FromUInt64(4294967295)_NeverFails") { - let input = getUInt64(4294967295) - let actual = UInt32(exactly: input) - expectEqual(4294967295, actual) +FixedPointConversion_Debug32_ToUInt32 +.test("FromUInt64_AlwaysTraps") +.forEach(in: [ + getUInt64(+4294967296), + getUInt64(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(UInt32($0)) } -FixedPointConversion_Debug32_ToUInt32.test("FromUInt64(4294967296)_AlwaysTraps") { - let input = getUInt64(4294967296) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromUInt64(4294967296)_AlwaysFails") { - let input = getUInt64(4294967296) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromUInt64(18446744073709551615)_AlwaysTraps") { - let input = getUInt64(18446744073709551615) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromUInt64(18446744073709551615)_AlwaysFails") { - let input = getUInt64(18446744073709551615) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt32 +.test("FromUInt64_AlwaysFails") +.forEach(in: [ + getUInt64(+4294967296), + getUInt64(+18446744073709551615), +]) { + expectNil(UInt32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int64: (-9223372036854775808)...(9223372036854775807) +// MARK: Int64: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt32.test("FromInt64(-9223372036854775808)_AlwaysTraps") { - let input = getInt64(-9223372036854775808) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromInt64(-9223372036854775808)_AlwaysFails") { - let input = getInt64(-9223372036854775808) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromInt64(-1)_AlwaysTraps") { - let input = getInt64(-1) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromInt64(-1)_AlwaysFails") { - let input = getInt64(-1) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromInt64(0)_NeverTraps") { - let input = getInt64(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromInt64(0)_NeverFails") { - let input = getInt64(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromInt64(4294967295)_NeverTraps") { - let input = getInt64(4294967295) - let actual = UInt32(input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromInt64(4294967295)_NeverFails") { - let input = getInt64(4294967295) - let actual = UInt32(exactly: input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromInt64(4294967296)_AlwaysTraps") { - let input = getInt64(4294967296) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromInt64(4294967296)_AlwaysFails") { - let input = getInt64(4294967296) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromInt64(9223372036854775807)_AlwaysTraps") { - let input = getInt64(9223372036854775807) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromInt64(9223372036854775807)_AlwaysFails") { - let input = getInt64(9223372036854775807) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt32 +.test("FromInt64_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getInt64(+0)), + (getUInt32(+4294967295), getInt64(+4294967295)), +]) { + expectEqual($0.0, UInt32($0.1)) +} + +FixedPointConversion_Debug32_ToUInt32 +.test("FromInt64_NeverFails") +.forEach(in: [ + (getUInt32(+0), getInt64(+0)), + (getUInt32(+4294967295), getInt64(+4294967295)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToUInt32 +.test("FromInt64_AlwaysTraps") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-1), + getInt64(+4294967296), + getInt64(+9223372036854775807), +]) { + expectCrashLater() + _blackHole(UInt32($0)) +} + +FixedPointConversion_Debug32_ToUInt32 +.test("FromInt64_AlwaysFails") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-1), + getInt64(+4294967296), + getInt64(+9223372036854775807), +]) { + expectNil(UInt32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt: (0)...(4294967295) +// MARK: UInt: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt32.test("FromUInt(0)_NeverTraps") { - let input = getUInt(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromUInt(0)_NeverFails") { - let input = getUInt(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromUInt(4294967295)_NeverTraps") { - let input = getUInt(4294967295) - let actual = UInt32(input) - expectEqual(4294967295, actual) +FixedPointConversion_Debug32_ToUInt32 +.test("FromUInt_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getUInt(+0)), + (getUInt32(+4294967295), getUInt(+4294967295)), +]) { + expectEqual($0.0, UInt32($0.1)) } -FixedPointConversion_Debug32_ToUInt32.test("FromUInt(4294967295)_NeverFails") { - let input = getUInt(4294967295) - let actual = UInt32(exactly: input) - expectEqual(4294967295, actual) +FixedPointConversion_Debug32_ToUInt32 +.test("FromUInt_NeverFails") +.forEach(in: [ + (getUInt32(+0), getUInt(+0)), + (getUInt32(+4294967295), getUInt(+4294967295)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int: (-2147483648)...(2147483647) +// MARK: Int: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt32.test("FromInt(-2147483648)_AlwaysTraps") { - let input = getInt(-2147483648) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromInt(-2147483648)_AlwaysFails") { - let input = getInt(-2147483648) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt32 +.test("FromInt_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getInt(+0)), + (getUInt32(+2147483647), getInt(+2147483647)), +]) { + expectEqual($0.0, UInt32($0.1)) } -FixedPointConversion_Debug32_ToUInt32.test("FromInt(-1)_AlwaysTraps") { - let input = getInt(-1) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } +FixedPointConversion_Debug32_ToUInt32 +.test("FromInt_NeverFails") +.forEach(in: [ + (getUInt32(+0), getInt(+0)), + (getUInt32(+2147483647), getInt(+2147483647)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) } -FixedPointConversion_Debug32_ToUInt32.test("FromInt(-1)_AlwaysFails") { - let input = getInt(-1) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt32 +.test("FromInt_AlwaysTraps") +.forEach(in: [ + getInt(-2147483648), + getInt(-1), +]) { + expectCrashLater() + _blackHole(UInt32($0)) } -FixedPointConversion_Debug32_ToUInt32.test("FromInt(0)_NeverTraps") { - let input = getInt(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromInt(0)_NeverFails") { - let input = getInt(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromInt(2147483647)_NeverTraps") { - let input = getInt(2147483647) - let actual = UInt32(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromInt(2147483647)_NeverFails") { - let input = getInt(2147483647) - let actual = UInt32(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Debug32_ToUInt32 +.test("FromInt_AlwaysFails") +.forEach(in: [ + getInt(-2147483648), + getInt(-1), +]) { + expectNil(UInt32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float16: (-2047)...(2047) +// MARK: Float16: (-2047)...(+2047) //===----------------------------------------------------------------------===// #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -FixedPointConversion_Debug32_ToUInt32.test("FromFloat16(-2047)_AlwaysTraps") { - let input = getFloat16(-2047) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat16(-2047)_AlwaysFails") { - let input = getFloat16(-2047) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat16(-128.5)_AlwaysTraps") { - let input = getFloat16(-128.5) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat16(-128.5)_AlwaysFails") { - let input = getFloat16(-128.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat16(-1)_AlwaysTraps") { - let input = getFloat16(-1) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat16(-1)_AlwaysFails") { - let input = getFloat16(-1) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat16(-0.5)_NeverTraps") { - let input = getFloat16(-0.5) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat16(-0.5)_AlwaysFails") { - let input = getFloat16(-0.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat16(0)_NeverTraps") { - let input = getFloat16(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat16(0)_NeverFails") { - let input = getFloat16(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat16(-0.0)_NeverTraps") { - let input = getFloat16(-0.0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat16(-0.0)_NeverFails") { - let input = getFloat16(-0.0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat16(0.0)_NeverTraps") { - let input = getFloat16(0.0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat16(0.0)_NeverFails") { - let input = getFloat16(0.0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat16(0.5)_NeverTraps") { - let input = getFloat16(0.5) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat16(0.5)_AlwaysFails") { - let input = getFloat16(0.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat16(127.5)_NeverTraps") { - let input = getFloat16(127.5) - let actual = UInt32(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat16(127.5)_AlwaysFails") { - let input = getFloat16(127.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat16(255.5)_NeverTraps") { - let input = getFloat16(255.5) - let actual = UInt32(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat16(255.5)_AlwaysFails") { - let input = getFloat16(255.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat16(2047)_NeverTraps") { - let input = getFloat16(2047) - let actual = UInt32(input) - expectEqual(2047, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat16(2047)_NeverFails") { - let input = getFloat16(2047) - let actual = UInt32(exactly: input) - expectEqual(2047, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat16(-.infinity)_AlwaysTraps") { - let input = getFloat16(-.infinity) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat16(-.infinity)_AlwaysFails") { - let input = getFloat16(-.infinity) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat16(+.infinity)_AlwaysTraps") { - let input = getFloat16(+.infinity) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat16(+.infinity)_AlwaysFails") { - let input = getFloat16(+.infinity) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat16(-.nan)_AlwaysTraps") { - let input = getFloat16(-.nan) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat16(-.nan)_AlwaysFails") { - let input = getFloat16(-.nan) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat16(+.nan)_AlwaysTraps") { - let input = getFloat16(+.nan) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat16(+.nan)_AlwaysFails") { - let input = getFloat16(+.nan) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat16(-.signalingNaN)_AlwaysTraps") { - let input = getFloat16(-.signalingNaN) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat16(-.signalingNaN)_AlwaysFails") { - let input = getFloat16(-.signalingNaN) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat16(+.signalingNaN)_AlwaysTraps") { - let input = getFloat16(+.signalingNaN) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat16(+.signalingNaN)_AlwaysFails") { - let input = getFloat16(+.signalingNaN) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt32 +.test("FromFloat16_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getFloat16(-0.5)), + (getUInt32(+0), getFloat16(+0)), + (getUInt32(+0), getFloat16(-0)), + (getUInt32(+0), getFloat16(+0.5)), + (getUInt32(+127), getFloat16(+127.5)), + (getUInt32(+255), getFloat16(+255.5)), + (getUInt32(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, UInt32($0.1)) +} + +FixedPointConversion_Debug32_ToUInt32 +.test("FromFloat16_NeverFails") +.forEach(in: [ + (getUInt32(+0), getFloat16(+0)), + (getUInt32(+0), getFloat16(-0)), + (getUInt32(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToUInt32 +.test("FromFloat16_AlwaysTraps") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-128.5), + getFloat16(-1), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt32($0)) +} + +FixedPointConversion_Debug32_ToUInt32 +.test("FromFloat16_AlwaysFails") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-128.5), + getFloat16(-1), + getFloat16(-0.5), + getFloat16(+0.5), + getFloat16(+127.5), + getFloat16(+255.5), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectNil(UInt32(exactly: $0)) } } #endif // Float16 //===----------------------------------------------------------------------===// -// MARK: Float32: (-16777215)...(16777215) +// MARK: Float32: (-16777215)...(+16777215) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt32.test("FromFloat32(-16777215)_AlwaysTraps") { - let input = getFloat32(-16777215) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat32(-16777215)_AlwaysFails") { - let input = getFloat32(-16777215) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat32(-32768.5)_AlwaysTraps") { - let input = getFloat32(-32768.5) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat32(-32768.5)_AlwaysFails") { - let input = getFloat32(-32768.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat32(-128.5)_AlwaysTraps") { - let input = getFloat32(-128.5) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat32(-128.5)_AlwaysFails") { - let input = getFloat32(-128.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat32(-1)_AlwaysTraps") { - let input = getFloat32(-1) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat32(-1)_AlwaysFails") { - let input = getFloat32(-1) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat32(-0.5)_NeverTraps") { - let input = getFloat32(-0.5) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat32(-0.5)_AlwaysFails") { - let input = getFloat32(-0.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat32(0)_NeverTraps") { - let input = getFloat32(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat32(0)_NeverFails") { - let input = getFloat32(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat32(-0.0)_NeverTraps") { - let input = getFloat32(-0.0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat32(-0.0)_NeverFails") { - let input = getFloat32(-0.0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat32(0.0)_NeverTraps") { - let input = getFloat32(0.0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat32(0.0)_NeverFails") { - let input = getFloat32(0.0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat32(0.5)_NeverTraps") { - let input = getFloat32(0.5) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat32(0.5)_AlwaysFails") { - let input = getFloat32(0.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat32(127.5)_NeverTraps") { - let input = getFloat32(127.5) - let actual = UInt32(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat32(127.5)_AlwaysFails") { - let input = getFloat32(127.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat32(255.5)_NeverTraps") { - let input = getFloat32(255.5) - let actual = UInt32(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat32(255.5)_AlwaysFails") { - let input = getFloat32(255.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat32(32767.5)_NeverTraps") { - let input = getFloat32(32767.5) - let actual = UInt32(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat32(32767.5)_AlwaysFails") { - let input = getFloat32(32767.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat32(65535.5)_NeverTraps") { - let input = getFloat32(65535.5) - let actual = UInt32(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat32(65535.5)_AlwaysFails") { - let input = getFloat32(65535.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat32(16777215)_NeverTraps") { - let input = getFloat32(16777215) - let actual = UInt32(input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat32(16777215)_NeverFails") { - let input = getFloat32(16777215) - let actual = UInt32(exactly: input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat32(-.infinity)_AlwaysTraps") { - let input = getFloat32(-.infinity) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat32(-.infinity)_AlwaysFails") { - let input = getFloat32(-.infinity) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat32(+.infinity)_AlwaysTraps") { - let input = getFloat32(+.infinity) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat32(+.infinity)_AlwaysFails") { - let input = getFloat32(+.infinity) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat32(-.nan)_AlwaysTraps") { - let input = getFloat32(-.nan) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat32(-.nan)_AlwaysFails") { - let input = getFloat32(-.nan) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat32(+.nan)_AlwaysTraps") { - let input = getFloat32(+.nan) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat32(+.nan)_AlwaysFails") { - let input = getFloat32(+.nan) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat32(-.signalingNaN)_AlwaysTraps") { - let input = getFloat32(-.signalingNaN) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat32(-.signalingNaN)_AlwaysFails") { - let input = getFloat32(-.signalingNaN) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat32(+.signalingNaN)_AlwaysTraps") { - let input = getFloat32(+.signalingNaN) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat32(+.signalingNaN)_AlwaysFails") { - let input = getFloat32(+.signalingNaN) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt32 +.test("FromFloat32_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getFloat32(-0.5)), + (getUInt32(+0), getFloat32(+0)), + (getUInt32(+0), getFloat32(-0)), + (getUInt32(+0), getFloat32(+0.5)), + (getUInt32(+127), getFloat32(+127.5)), + (getUInt32(+255), getFloat32(+255.5)), + (getUInt32(+32767), getFloat32(+32767.5)), + (getUInt32(+65535), getFloat32(+65535.5)), + (getUInt32(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, UInt32($0.1)) +} + +FixedPointConversion_Debug32_ToUInt32 +.test("FromFloat32_NeverFails") +.forEach(in: [ + (getUInt32(+0), getFloat32(+0)), + (getUInt32(+0), getFloat32(-0)), + (getUInt32(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToUInt32 +.test("FromFloat32_AlwaysTraps") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-1), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt32($0)) +} + +FixedPointConversion_Debug32_ToUInt32 +.test("FromFloat32_AlwaysFails") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-1), + getFloat32(-0.5), + getFloat32(+0.5), + getFloat32(+127.5), + getFloat32(+255.5), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectNil(UInt32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float64: (-9007199254740991)...(9007199254740991) +// MARK: Float64: (-9007199254740991)...(+9007199254740991) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(-9007199254740991)_AlwaysTraps") { - let input = getFloat64(-9007199254740991) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(-9007199254740991)_AlwaysFails") { - let input = getFloat64(-9007199254740991) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(-32768.5)_AlwaysTraps") { - let input = getFloat64(-32768.5) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(-32768.5)_AlwaysFails") { - let input = getFloat64(-32768.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(-128.5)_AlwaysTraps") { - let input = getFloat64(-128.5) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(-128.5)_AlwaysFails") { - let input = getFloat64(-128.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(-1)_AlwaysTraps") { - let input = getFloat64(-1) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(-1)_AlwaysFails") { - let input = getFloat64(-1) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(-0.5)_NeverTraps") { - let input = getFloat64(-0.5) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(-0.5)_AlwaysFails") { - let input = getFloat64(-0.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(0)_NeverTraps") { - let input = getFloat64(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(0)_NeverFails") { - let input = getFloat64(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(-0.0)_NeverTraps") { - let input = getFloat64(-0.0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(-0.0)_NeverFails") { - let input = getFloat64(-0.0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(0.0)_NeverTraps") { - let input = getFloat64(0.0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(0.0)_NeverFails") { - let input = getFloat64(0.0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(0.5)_NeverTraps") { - let input = getFloat64(0.5) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(0.5)_AlwaysFails") { - let input = getFloat64(0.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(127.5)_NeverTraps") { - let input = getFloat64(127.5) - let actual = UInt32(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(127.5)_AlwaysFails") { - let input = getFloat64(127.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(255.5)_NeverTraps") { - let input = getFloat64(255.5) - let actual = UInt32(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(255.5)_AlwaysFails") { - let input = getFloat64(255.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(32767.5)_NeverTraps") { - let input = getFloat64(32767.5) - let actual = UInt32(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(32767.5)_AlwaysFails") { - let input = getFloat64(32767.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(65535.5)_NeverTraps") { - let input = getFloat64(65535.5) - let actual = UInt32(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(65535.5)_AlwaysFails") { - let input = getFloat64(65535.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(4294967295)_NeverTraps") { - let input = getFloat64(4294967295) - let actual = UInt32(input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(4294967295)_NeverFails") { - let input = getFloat64(4294967295) - let actual = UInt32(exactly: input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(4294967296)_AlwaysTraps") { - let input = getFloat64(4294967296) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(4294967296)_AlwaysFails") { - let input = getFloat64(4294967296) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(9007199254740991)_AlwaysTraps") { - let input = getFloat64(9007199254740991) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(9007199254740991)_AlwaysFails") { - let input = getFloat64(9007199254740991) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(-.infinity)_AlwaysTraps") { - let input = getFloat64(-.infinity) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(-.infinity)_AlwaysFails") { - let input = getFloat64(-.infinity) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(+.infinity)_AlwaysTraps") { - let input = getFloat64(+.infinity) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(+.infinity)_AlwaysFails") { - let input = getFloat64(+.infinity) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(-.nan)_AlwaysTraps") { - let input = getFloat64(-.nan) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(-.nan)_AlwaysFails") { - let input = getFloat64(-.nan) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(+.nan)_AlwaysTraps") { - let input = getFloat64(+.nan) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(+.nan)_AlwaysFails") { - let input = getFloat64(+.nan) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(-.signalingNaN)_AlwaysTraps") { - let input = getFloat64(-.signalingNaN) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(-.signalingNaN)_AlwaysFails") { - let input = getFloat64(-.signalingNaN) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(+.signalingNaN)_AlwaysTraps") { - let input = getFloat64(+.signalingNaN) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat64(+.signalingNaN)_AlwaysFails") { - let input = getFloat64(+.signalingNaN) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt32 +.test("FromFloat64_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getFloat64(-0.5)), + (getUInt32(+0), getFloat64(+0)), + (getUInt32(+0), getFloat64(-0)), + (getUInt32(+0), getFloat64(+0.5)), + (getUInt32(+127), getFloat64(+127.5)), + (getUInt32(+255), getFloat64(+255.5)), + (getUInt32(+32767), getFloat64(+32767.5)), + (getUInt32(+65535), getFloat64(+65535.5)), + (getUInt32(+4294967295), getFloat64(+4294967295)), +]) { + expectEqual($0.0, UInt32($0.1)) +} + +FixedPointConversion_Debug32_ToUInt32 +.test("FromFloat64_NeverFails") +.forEach(in: [ + (getUInt32(+0), getFloat64(+0)), + (getUInt32(+0), getFloat64(-0)), + (getUInt32(+4294967295), getFloat64(+4294967295)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToUInt32 +.test("FromFloat64_AlwaysTraps") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-1), + getFloat64(+4294967296), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt32($0)) +} + +FixedPointConversion_Debug32_ToUInt32 +.test("FromFloat64_AlwaysFails") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-1), + getFloat64(-0.5), + getFloat64(+0.5), + getFloat64(+127.5), + getFloat64(+255.5), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(+4294967296), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectNil(UInt32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float80: (-18446744073709551615)...(18446744073709551615) +// MARK: Float80: (-18446744073709551615)...(+18446744073709551615) //===----------------------------------------------------------------------===// #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(-18446744073709551615)_AlwaysTraps") { - let input = getFloat80(-18446744073709551615) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(-18446744073709551615)_AlwaysFails") { - let input = getFloat80(-18446744073709551615) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(-32768.5)_AlwaysTraps") { - let input = getFloat80(-32768.5) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(-32768.5)_AlwaysFails") { - let input = getFloat80(-32768.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(-128.5)_AlwaysTraps") { - let input = getFloat80(-128.5) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(-128.5)_AlwaysFails") { - let input = getFloat80(-128.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(-1)_AlwaysTraps") { - let input = getFloat80(-1) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(-1)_AlwaysFails") { - let input = getFloat80(-1) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(-0.5)_NeverTraps") { - let input = getFloat80(-0.5) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(-0.5)_AlwaysFails") { - let input = getFloat80(-0.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(0)_NeverTraps") { - let input = getFloat80(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(0)_NeverFails") { - let input = getFloat80(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(-0.0)_NeverTraps") { - let input = getFloat80(-0.0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(-0.0)_NeverFails") { - let input = getFloat80(-0.0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(0.0)_NeverTraps") { - let input = getFloat80(0.0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(0.0)_NeverFails") { - let input = getFloat80(0.0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(0.5)_NeverTraps") { - let input = getFloat80(0.5) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(0.5)_AlwaysFails") { - let input = getFloat80(0.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(127.5)_NeverTraps") { - let input = getFloat80(127.5) - let actual = UInt32(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(127.5)_AlwaysFails") { - let input = getFloat80(127.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(255.5)_NeverTraps") { - let input = getFloat80(255.5) - let actual = UInt32(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(255.5)_AlwaysFails") { - let input = getFloat80(255.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(32767.5)_NeverTraps") { - let input = getFloat80(32767.5) - let actual = UInt32(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(32767.5)_AlwaysFails") { - let input = getFloat80(32767.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(65535.5)_NeverTraps") { - let input = getFloat80(65535.5) - let actual = UInt32(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(65535.5)_AlwaysFails") { - let input = getFloat80(65535.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(4294967295)_NeverTraps") { - let input = getFloat80(4294967295) - let actual = UInt32(input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(4294967295)_NeverFails") { - let input = getFloat80(4294967295) - let actual = UInt32(exactly: input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(4294967296)_AlwaysTraps") { - let input = getFloat80(4294967296) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(4294967296)_AlwaysFails") { - let input = getFloat80(4294967296) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(18446744073709551615)_AlwaysTraps") { - let input = getFloat80(18446744073709551615) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(18446744073709551615)_AlwaysFails") { - let input = getFloat80(18446744073709551615) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(-.infinity)_AlwaysTraps") { - let input = getFloat80(-.infinity) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(-.infinity)_AlwaysFails") { - let input = getFloat80(-.infinity) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(+.infinity)_AlwaysTraps") { - let input = getFloat80(+.infinity) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(+.infinity)_AlwaysFails") { - let input = getFloat80(+.infinity) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(-.nan)_AlwaysTraps") { - let input = getFloat80(-.nan) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(-.nan)_AlwaysFails") { - let input = getFloat80(-.nan) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(+.nan)_AlwaysTraps") { - let input = getFloat80(+.nan) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(+.nan)_AlwaysFails") { - let input = getFloat80(+.nan) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(-.signalingNaN)_AlwaysTraps") { - let input = getFloat80(-.signalingNaN) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(-.signalingNaN)_AlwaysFails") { - let input = getFloat80(-.signalingNaN) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(+.signalingNaN)_AlwaysTraps") { - let input = getFloat80(+.signalingNaN) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt32.test("FromFloat80(+.signalingNaN)_AlwaysFails") { - let input = getFloat80(+.signalingNaN) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt32 +.test("FromFloat80_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getFloat80(-0.5)), + (getUInt32(+0), getFloat80(+0)), + (getUInt32(+0), getFloat80(-0)), + (getUInt32(+0), getFloat80(+0.5)), + (getUInt32(+127), getFloat80(+127.5)), + (getUInt32(+255), getFloat80(+255.5)), + (getUInt32(+32767), getFloat80(+32767.5)), + (getUInt32(+65535), getFloat80(+65535.5)), + (getUInt32(+4294967295), getFloat80(+4294967295)), +]) { + expectEqual($0.0, UInt32($0.1)) +} + +FixedPointConversion_Debug32_ToUInt32 +.test("FromFloat80_NeverFails") +.forEach(in: [ + (getUInt32(+0), getFloat80(+0)), + (getUInt32(+0), getFloat80(-0)), + (getUInt32(+4294967295), getFloat80(+4294967295)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToUInt32 +.test("FromFloat80_AlwaysTraps") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-1), + getFloat80(+4294967296), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt32($0)) +} + +FixedPointConversion_Debug32_ToUInt32 +.test("FromFloat80_AlwaysFails") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-1), + getFloat80(-0.5), + getFloat80(+0.5), + getFloat80(+127.5), + getFloat80(+255.5), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(+4294967296), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectNil(UInt32(exactly: $0)) } #endif // Float80 diff --git a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug32_ToUInt64.swift b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug32_ToUInt64.swift index 9bcb2d08d7670..2fe4ff05bb442 100644 --- a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug32_ToUInt64.swift +++ b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug32_ToUInt64.swift @@ -14,1464 +14,609 @@ import StdlibUnittest -let FixedPointConversion_Debug32_ToUInt64 = TestSuite("FixedPointConversion_Debug32_ToUInt64") +let FixedPointConversion_Debug32_ToUInt64 = TestSuite( + "FixedPointConversion_Debug32_ToUInt64" +) //===----------------------------------------------------------------------===// -// MARK: UInt8: (0)...(255) +// MARK: UInt8: (+0)...(+255) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt64.test("FromUInt8(0)_NeverTraps") { - let input = getUInt8(0) - let actual = UInt64(input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToUInt64 +.test("FromUInt8_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getUInt8(+0)), + (getUInt64(+255), getUInt8(+255)), +]) { + expectEqual($0.0, UInt64($0.1)) } -FixedPointConversion_Debug32_ToUInt64.test("FromUInt8(0)_NeverFails") { - let input = getUInt8(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromUInt8(255)_NeverTraps") { - let input = getUInt8(255) - let actual = UInt64(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromUInt8(255)_NeverFails") { - let input = getUInt8(255) - let actual = UInt64(exactly: input) - expectEqual(255, actual) +FixedPointConversion_Debug32_ToUInt64 +.test("FromUInt8_NeverFails") +.forEach(in: [ + (getUInt64(+0), getUInt8(+0)), + (getUInt64(+255), getUInt8(+255)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int8: (-128)...(127) +// MARK: Int8: (-128)...(+127) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt64.test("FromInt8(-128)_AlwaysTraps") { - let input = getInt8(-128) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromInt8(-128)_AlwaysFails") { - let input = getInt8(-128) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromInt8(-1)_AlwaysTraps") { - let input = getInt8(-1) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromInt8(-1)_AlwaysFails") { - let input = getInt8(-1) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromInt8(0)_NeverTraps") { - let input = getInt8(0) - let actual = UInt64(input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToUInt64 +.test("FromInt8_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getInt8(+0)), + (getUInt64(+127), getInt8(+127)), +]) { + expectEqual($0.0, UInt64($0.1)) } -FixedPointConversion_Debug32_ToUInt64.test("FromInt8(0)_NeverFails") { - let input = getInt8(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToUInt64 +.test("FromInt8_NeverFails") +.forEach(in: [ + (getUInt64(+0), getInt8(+0)), + (getUInt64(+127), getInt8(+127)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) } -FixedPointConversion_Debug32_ToUInt64.test("FromInt8(127)_NeverTraps") { - let input = getInt8(127) - let actual = UInt64(input) - expectEqual(127, actual) +FixedPointConversion_Debug32_ToUInt64 +.test("FromInt8_AlwaysTraps") +.forEach(in: [ + getInt8(-128), + getInt8(-1), +]) { + expectCrashLater() + _blackHole(UInt64($0)) } -FixedPointConversion_Debug32_ToUInt64.test("FromInt8(127)_NeverFails") { - let input = getInt8(127) - let actual = UInt64(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Debug32_ToUInt64 +.test("FromInt8_AlwaysFails") +.forEach(in: [ + getInt8(-128), + getInt8(-1), +]) { + expectNil(UInt64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt16: (0)...(65535) +// MARK: UInt16: (+0)...(+65535) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt64.test("FromUInt16(0)_NeverTraps") { - let input = getUInt16(0) - let actual = UInt64(input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToUInt64 +.test("FromUInt16_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getUInt16(+0)), + (getUInt64(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, UInt64($0.1)) } -FixedPointConversion_Debug32_ToUInt64.test("FromUInt16(0)_NeverFails") { - let input = getUInt16(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromUInt16(65535)_NeverTraps") { - let input = getUInt16(65535) - let actual = UInt64(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromUInt16(65535)_NeverFails") { - let input = getUInt16(65535) - let actual = UInt64(exactly: input) - expectEqual(65535, actual) +FixedPointConversion_Debug32_ToUInt64 +.test("FromUInt16_NeverFails") +.forEach(in: [ + (getUInt64(+0), getUInt16(+0)), + (getUInt64(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int16: (-32768)...(32767) +// MARK: Int16: (-32768)...(+32767) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt64.test("FromInt16(-32768)_AlwaysTraps") { - let input = getInt16(-32768) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromInt16(-32768)_AlwaysFails") { - let input = getInt16(-32768) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromInt16(-1)_AlwaysTraps") { - let input = getInt16(-1) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromInt16(-1)_AlwaysFails") { - let input = getInt16(-1) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromInt16(0)_NeverTraps") { - let input = getInt16(0) - let actual = UInt64(input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToUInt64 +.test("FromInt16_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getInt16(+0)), + (getUInt64(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, UInt64($0.1)) } -FixedPointConversion_Debug32_ToUInt64.test("FromInt16(0)_NeverFails") { - let input = getInt16(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToUInt64 +.test("FromInt16_NeverFails") +.forEach(in: [ + (getUInt64(+0), getInt16(+0)), + (getUInt64(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) } -FixedPointConversion_Debug32_ToUInt64.test("FromInt16(32767)_NeverTraps") { - let input = getInt16(32767) - let actual = UInt64(input) - expectEqual(32767, actual) +FixedPointConversion_Debug32_ToUInt64 +.test("FromInt16_AlwaysTraps") +.forEach(in: [ + getInt16(-32768), + getInt16(-1), +]) { + expectCrashLater() + _blackHole(UInt64($0)) } -FixedPointConversion_Debug32_ToUInt64.test("FromInt16(32767)_NeverFails") { - let input = getInt16(32767) - let actual = UInt64(exactly: input) - expectEqual(32767, actual) +FixedPointConversion_Debug32_ToUInt64 +.test("FromInt16_AlwaysFails") +.forEach(in: [ + getInt16(-32768), + getInt16(-1), +]) { + expectNil(UInt64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt32: (0)...(4294967295) +// MARK: UInt32: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt64.test("FromUInt32(0)_NeverTraps") { - let input = getUInt32(0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromUInt32(0)_NeverFails") { - let input = getUInt32(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToUInt64 +.test("FromUInt32_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getUInt32(+0)), + (getUInt64(+4294967295), getUInt32(+4294967295)), +]) { + expectEqual($0.0, UInt64($0.1)) } -FixedPointConversion_Debug32_ToUInt64.test("FromUInt32(4294967295)_NeverTraps") { - let input = getUInt32(4294967295) - let actual = UInt64(input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromUInt32(4294967295)_NeverFails") { - let input = getUInt32(4294967295) - let actual = UInt64(exactly: input) - expectEqual(4294967295, actual) +FixedPointConversion_Debug32_ToUInt64 +.test("FromUInt32_NeverFails") +.forEach(in: [ + (getUInt64(+0), getUInt32(+0)), + (getUInt64(+4294967295), getUInt32(+4294967295)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int32: (-2147483648)...(2147483647) +// MARK: Int32: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt64.test("FromInt32(-2147483648)_AlwaysTraps") { - let input = getInt32(-2147483648) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromInt32(-2147483648)_AlwaysFails") { - let input = getInt32(-2147483648) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromInt32(-1)_AlwaysTraps") { - let input = getInt32(-1) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } +FixedPointConversion_Debug32_ToUInt64 +.test("FromInt32_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getInt32(+0)), + (getUInt64(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, UInt64($0.1)) } -FixedPointConversion_Debug32_ToUInt64.test("FromInt32(-1)_AlwaysFails") { - let input = getInt32(-1) - let actual = UInt64(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt64 +.test("FromInt32_NeverFails") +.forEach(in: [ + (getUInt64(+0), getInt32(+0)), + (getUInt64(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) } -FixedPointConversion_Debug32_ToUInt64.test("FromInt32(0)_NeverTraps") { - let input = getInt32(0) - let actual = UInt64(input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToUInt64 +.test("FromInt32_AlwaysTraps") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-1), +]) { + expectCrashLater() + _blackHole(UInt64($0)) } -FixedPointConversion_Debug32_ToUInt64.test("FromInt32(0)_NeverFails") { - let input = getInt32(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromInt32(2147483647)_NeverTraps") { - let input = getInt32(2147483647) - let actual = UInt64(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromInt32(2147483647)_NeverFails") { - let input = getInt32(2147483647) - let actual = UInt64(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Debug32_ToUInt64 +.test("FromInt32_AlwaysFails") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-1), +]) { + expectNil(UInt64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt64: (0)...(18446744073709551615) +// MARK: UInt64: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt64.test("FromUInt64(0)_NeverTraps") { - let input = getUInt64(0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromUInt64(0)_NeverFails") { - let input = getUInt64(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToUInt64 +.test("FromUInt64_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getUInt64(+0)), + (getUInt64(+18446744073709551615), getUInt64(+18446744073709551615)), +]) { + expectEqual($0.0, UInt64($0.1)) } -FixedPointConversion_Debug32_ToUInt64.test("FromUInt64(18446744073709551615)_NeverTraps") { - let input = getUInt64(18446744073709551615) - let actual = UInt64(input) - expectEqual(18446744073709551615, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromUInt64(18446744073709551615)_NeverFails") { - let input = getUInt64(18446744073709551615) - let actual = UInt64(exactly: input) - expectEqual(18446744073709551615, actual) +FixedPointConversion_Debug32_ToUInt64 +.test("FromUInt64_NeverFails") +.forEach(in: [ + (getUInt64(+0), getUInt64(+0)), + (getUInt64(+18446744073709551615), getUInt64(+18446744073709551615)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int64: (-9223372036854775808)...(9223372036854775807) +// MARK: Int64: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt64.test("FromInt64(-9223372036854775808)_AlwaysTraps") { - let input = getInt64(-9223372036854775808) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromInt64(-9223372036854775808)_AlwaysFails") { - let input = getInt64(-9223372036854775808) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromInt64(-1)_AlwaysTraps") { - let input = getInt64(-1) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromInt64(-1)_AlwaysFails") { - let input = getInt64(-1) - let actual = UInt64(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt64 +.test("FromInt64_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getInt64(+0)), + (getUInt64(+9223372036854775807), getInt64(+9223372036854775807)), +]) { + expectEqual($0.0, UInt64($0.1)) } -FixedPointConversion_Debug32_ToUInt64.test("FromInt64(0)_NeverTraps") { - let input = getInt64(0) - let actual = UInt64(input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToUInt64 +.test("FromInt64_NeverFails") +.forEach(in: [ + (getUInt64(+0), getInt64(+0)), + (getUInt64(+9223372036854775807), getInt64(+9223372036854775807)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) } -FixedPointConversion_Debug32_ToUInt64.test("FromInt64(0)_NeverFails") { - let input = getInt64(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToUInt64 +.test("FromInt64_AlwaysTraps") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-1), +]) { + expectCrashLater() + _blackHole(UInt64($0)) } -FixedPointConversion_Debug32_ToUInt64.test("FromInt64(9223372036854775807)_NeverTraps") { - let input = getInt64(9223372036854775807) - let actual = UInt64(input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromInt64(9223372036854775807)_NeverFails") { - let input = getInt64(9223372036854775807) - let actual = UInt64(exactly: input) - expectEqual(9223372036854775807, actual) +FixedPointConversion_Debug32_ToUInt64 +.test("FromInt64_AlwaysFails") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-1), +]) { + expectNil(UInt64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt: (0)...(4294967295) +// MARK: UInt: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt64.test("FromUInt(0)_NeverTraps") { - let input = getUInt(0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromUInt(0)_NeverFails") { - let input = getUInt(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromUInt(4294967295)_NeverTraps") { - let input = getUInt(4294967295) - let actual = UInt64(input) - expectEqual(4294967295, actual) +FixedPointConversion_Debug32_ToUInt64 +.test("FromUInt_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getUInt(+0)), + (getUInt64(+4294967295), getUInt(+4294967295)), +]) { + expectEqual($0.0, UInt64($0.1)) } -FixedPointConversion_Debug32_ToUInt64.test("FromUInt(4294967295)_NeverFails") { - let input = getUInt(4294967295) - let actual = UInt64(exactly: input) - expectEqual(4294967295, actual) +FixedPointConversion_Debug32_ToUInt64 +.test("FromUInt_NeverFails") +.forEach(in: [ + (getUInt64(+0), getUInt(+0)), + (getUInt64(+4294967295), getUInt(+4294967295)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int: (-2147483648)...(2147483647) +// MARK: Int: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt64.test("FromInt(-2147483648)_AlwaysTraps") { - let input = getInt(-2147483648) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromInt(-2147483648)_AlwaysFails") { - let input = getInt(-2147483648) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromInt(-1)_AlwaysTraps") { - let input = getInt(-1) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromInt(-1)_AlwaysFails") { - let input = getInt(-1) - let actual = UInt64(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt64 +.test("FromInt_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getInt(+0)), + (getUInt64(+2147483647), getInt(+2147483647)), +]) { + expectEqual($0.0, UInt64($0.1)) } -FixedPointConversion_Debug32_ToUInt64.test("FromInt(0)_NeverTraps") { - let input = getInt(0) - let actual = UInt64(input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToUInt64 +.test("FromInt_NeverFails") +.forEach(in: [ + (getUInt64(+0), getInt(+0)), + (getUInt64(+2147483647), getInt(+2147483647)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) } -FixedPointConversion_Debug32_ToUInt64.test("FromInt(0)_NeverFails") { - let input = getInt(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToUInt64 +.test("FromInt_AlwaysTraps") +.forEach(in: [ + getInt(-2147483648), + getInt(-1), +]) { + expectCrashLater() + _blackHole(UInt64($0)) } -FixedPointConversion_Debug32_ToUInt64.test("FromInt(2147483647)_NeverTraps") { - let input = getInt(2147483647) - let actual = UInt64(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromInt(2147483647)_NeverFails") { - let input = getInt(2147483647) - let actual = UInt64(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Debug32_ToUInt64 +.test("FromInt_AlwaysFails") +.forEach(in: [ + getInt(-2147483648), + getInt(-1), +]) { + expectNil(UInt64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float16: (-2047)...(2047) +// MARK: Float16: (-2047)...(+2047) //===----------------------------------------------------------------------===// #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -FixedPointConversion_Debug32_ToUInt64.test("FromFloat16(-2047)_AlwaysTraps") { - let input = getFloat16(-2047) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat16(-2047)_AlwaysFails") { - let input = getFloat16(-2047) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat16(-128.5)_AlwaysTraps") { - let input = getFloat16(-128.5) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat16(-128.5)_AlwaysFails") { - let input = getFloat16(-128.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat16(-1)_AlwaysTraps") { - let input = getFloat16(-1) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat16(-1)_AlwaysFails") { - let input = getFloat16(-1) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat16(-0.5)_NeverTraps") { - let input = getFloat16(-0.5) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat16(-0.5)_AlwaysFails") { - let input = getFloat16(-0.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat16(0)_NeverTraps") { - let input = getFloat16(0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat16(0)_NeverFails") { - let input = getFloat16(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat16(-0.0)_NeverTraps") { - let input = getFloat16(-0.0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat16(-0.0)_NeverFails") { - let input = getFloat16(-0.0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat16(0.0)_NeverTraps") { - let input = getFloat16(0.0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat16(0.0)_NeverFails") { - let input = getFloat16(0.0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat16(0.5)_NeverTraps") { - let input = getFloat16(0.5) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat16(0.5)_AlwaysFails") { - let input = getFloat16(0.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat16(127.5)_NeverTraps") { - let input = getFloat16(127.5) - let actual = UInt64(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat16(127.5)_AlwaysFails") { - let input = getFloat16(127.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat16(255.5)_NeverTraps") { - let input = getFloat16(255.5) - let actual = UInt64(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat16(255.5)_AlwaysFails") { - let input = getFloat16(255.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat16(2047)_NeverTraps") { - let input = getFloat16(2047) - let actual = UInt64(input) - expectEqual(2047, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat16(2047)_NeverFails") { - let input = getFloat16(2047) - let actual = UInt64(exactly: input) - expectEqual(2047, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat16(-.infinity)_AlwaysTraps") { - let input = getFloat16(-.infinity) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat16(-.infinity)_AlwaysFails") { - let input = getFloat16(-.infinity) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat16(+.infinity)_AlwaysTraps") { - let input = getFloat16(+.infinity) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat16(+.infinity)_AlwaysFails") { - let input = getFloat16(+.infinity) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat16(-.nan)_AlwaysTraps") { - let input = getFloat16(-.nan) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat16(-.nan)_AlwaysFails") { - let input = getFloat16(-.nan) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat16(+.nan)_AlwaysTraps") { - let input = getFloat16(+.nan) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat16(+.nan)_AlwaysFails") { - let input = getFloat16(+.nan) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat16(-.signalingNaN)_AlwaysTraps") { - let input = getFloat16(-.signalingNaN) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat16(-.signalingNaN)_AlwaysFails") { - let input = getFloat16(-.signalingNaN) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat16(+.signalingNaN)_AlwaysTraps") { - let input = getFloat16(+.signalingNaN) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat16(+.signalingNaN)_AlwaysFails") { - let input = getFloat16(+.signalingNaN) - let actual = UInt64(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt64 +.test("FromFloat16_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getFloat16(-0.5)), + (getUInt64(+0), getFloat16(+0)), + (getUInt64(+0), getFloat16(-0)), + (getUInt64(+0), getFloat16(+0.5)), + (getUInt64(+127), getFloat16(+127.5)), + (getUInt64(+255), getFloat16(+255.5)), + (getUInt64(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, UInt64($0.1)) +} + +FixedPointConversion_Debug32_ToUInt64 +.test("FromFloat16_NeverFails") +.forEach(in: [ + (getUInt64(+0), getFloat16(+0)), + (getUInt64(+0), getFloat16(-0)), + (getUInt64(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToUInt64 +.test("FromFloat16_AlwaysTraps") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-128.5), + getFloat16(-1), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt64($0)) +} + +FixedPointConversion_Debug32_ToUInt64 +.test("FromFloat16_AlwaysFails") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-128.5), + getFloat16(-1), + getFloat16(-0.5), + getFloat16(+0.5), + getFloat16(+127.5), + getFloat16(+255.5), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectNil(UInt64(exactly: $0)) } } #endif // Float16 //===----------------------------------------------------------------------===// -// MARK: Float32: (-16777215)...(16777215) +// MARK: Float32: (-16777215)...(+16777215) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt64.test("FromFloat32(-16777215)_AlwaysTraps") { - let input = getFloat32(-16777215) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat32(-16777215)_AlwaysFails") { - let input = getFloat32(-16777215) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat32(-32768.5)_AlwaysTraps") { - let input = getFloat32(-32768.5) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat32(-32768.5)_AlwaysFails") { - let input = getFloat32(-32768.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat32(-128.5)_AlwaysTraps") { - let input = getFloat32(-128.5) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat32(-128.5)_AlwaysFails") { - let input = getFloat32(-128.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat32(-1)_AlwaysTraps") { - let input = getFloat32(-1) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat32(-1)_AlwaysFails") { - let input = getFloat32(-1) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat32(-0.5)_NeverTraps") { - let input = getFloat32(-0.5) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat32(-0.5)_AlwaysFails") { - let input = getFloat32(-0.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat32(0)_NeverTraps") { - let input = getFloat32(0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat32(0)_NeverFails") { - let input = getFloat32(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat32(-0.0)_NeverTraps") { - let input = getFloat32(-0.0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat32(-0.0)_NeverFails") { - let input = getFloat32(-0.0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat32(0.0)_NeverTraps") { - let input = getFloat32(0.0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat32(0.0)_NeverFails") { - let input = getFloat32(0.0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat32(0.5)_NeverTraps") { - let input = getFloat32(0.5) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat32(0.5)_AlwaysFails") { - let input = getFloat32(0.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat32(127.5)_NeverTraps") { - let input = getFloat32(127.5) - let actual = UInt64(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat32(127.5)_AlwaysFails") { - let input = getFloat32(127.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat32(255.5)_NeverTraps") { - let input = getFloat32(255.5) - let actual = UInt64(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat32(255.5)_AlwaysFails") { - let input = getFloat32(255.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat32(32767.5)_NeverTraps") { - let input = getFloat32(32767.5) - let actual = UInt64(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat32(32767.5)_AlwaysFails") { - let input = getFloat32(32767.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat32(65535.5)_NeverTraps") { - let input = getFloat32(65535.5) - let actual = UInt64(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat32(65535.5)_AlwaysFails") { - let input = getFloat32(65535.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat32(16777215)_NeverTraps") { - let input = getFloat32(16777215) - let actual = UInt64(input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat32(16777215)_NeverFails") { - let input = getFloat32(16777215) - let actual = UInt64(exactly: input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat32(-.infinity)_AlwaysTraps") { - let input = getFloat32(-.infinity) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat32(-.infinity)_AlwaysFails") { - let input = getFloat32(-.infinity) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat32(+.infinity)_AlwaysTraps") { - let input = getFloat32(+.infinity) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat32(+.infinity)_AlwaysFails") { - let input = getFloat32(+.infinity) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat32(-.nan)_AlwaysTraps") { - let input = getFloat32(-.nan) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat32(-.nan)_AlwaysFails") { - let input = getFloat32(-.nan) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat32(+.nan)_AlwaysTraps") { - let input = getFloat32(+.nan) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat32(+.nan)_AlwaysFails") { - let input = getFloat32(+.nan) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat32(-.signalingNaN)_AlwaysTraps") { - let input = getFloat32(-.signalingNaN) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat32(-.signalingNaN)_AlwaysFails") { - let input = getFloat32(-.signalingNaN) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat32(+.signalingNaN)_AlwaysTraps") { - let input = getFloat32(+.signalingNaN) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat32(+.signalingNaN)_AlwaysFails") { - let input = getFloat32(+.signalingNaN) - let actual = UInt64(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt64 +.test("FromFloat32_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getFloat32(-0.5)), + (getUInt64(+0), getFloat32(+0)), + (getUInt64(+0), getFloat32(-0)), + (getUInt64(+0), getFloat32(+0.5)), + (getUInt64(+127), getFloat32(+127.5)), + (getUInt64(+255), getFloat32(+255.5)), + (getUInt64(+32767), getFloat32(+32767.5)), + (getUInt64(+65535), getFloat32(+65535.5)), + (getUInt64(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, UInt64($0.1)) +} + +FixedPointConversion_Debug32_ToUInt64 +.test("FromFloat32_NeverFails") +.forEach(in: [ + (getUInt64(+0), getFloat32(+0)), + (getUInt64(+0), getFloat32(-0)), + (getUInt64(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToUInt64 +.test("FromFloat32_AlwaysTraps") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-1), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt64($0)) +} + +FixedPointConversion_Debug32_ToUInt64 +.test("FromFloat32_AlwaysFails") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-1), + getFloat32(-0.5), + getFloat32(+0.5), + getFloat32(+127.5), + getFloat32(+255.5), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectNil(UInt64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float64: (-9007199254740991)...(9007199254740991) +// MARK: Float64: (-9007199254740991)...(+9007199254740991) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt64.test("FromFloat64(-9007199254740991)_AlwaysTraps") { - let input = getFloat64(-9007199254740991) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat64(-9007199254740991)_AlwaysFails") { - let input = getFloat64(-9007199254740991) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat64(-32768.5)_AlwaysTraps") { - let input = getFloat64(-32768.5) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat64(-32768.5)_AlwaysFails") { - let input = getFloat64(-32768.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat64(-128.5)_AlwaysTraps") { - let input = getFloat64(-128.5) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat64(-128.5)_AlwaysFails") { - let input = getFloat64(-128.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat64(-1)_AlwaysTraps") { - let input = getFloat64(-1) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat64(-1)_AlwaysFails") { - let input = getFloat64(-1) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat64(-0.5)_NeverTraps") { - let input = getFloat64(-0.5) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat64(-0.5)_AlwaysFails") { - let input = getFloat64(-0.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat64(0)_NeverTraps") { - let input = getFloat64(0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat64(0)_NeverFails") { - let input = getFloat64(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat64(-0.0)_NeverTraps") { - let input = getFloat64(-0.0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat64(-0.0)_NeverFails") { - let input = getFloat64(-0.0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat64(0.0)_NeverTraps") { - let input = getFloat64(0.0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat64(0.0)_NeverFails") { - let input = getFloat64(0.0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat64(0.5)_NeverTraps") { - let input = getFloat64(0.5) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat64(0.5)_AlwaysFails") { - let input = getFloat64(0.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat64(127.5)_NeverTraps") { - let input = getFloat64(127.5) - let actual = UInt64(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat64(127.5)_AlwaysFails") { - let input = getFloat64(127.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat64(255.5)_NeverTraps") { - let input = getFloat64(255.5) - let actual = UInt64(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat64(255.5)_AlwaysFails") { - let input = getFloat64(255.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat64(32767.5)_NeverTraps") { - let input = getFloat64(32767.5) - let actual = UInt64(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat64(32767.5)_AlwaysFails") { - let input = getFloat64(32767.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat64(65535.5)_NeverTraps") { - let input = getFloat64(65535.5) - let actual = UInt64(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat64(65535.5)_AlwaysFails") { - let input = getFloat64(65535.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat64(9007199254740991)_NeverTraps") { - let input = getFloat64(9007199254740991) - let actual = UInt64(input) - expectEqual(9007199254740991, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat64(9007199254740991)_NeverFails") { - let input = getFloat64(9007199254740991) - let actual = UInt64(exactly: input) - expectEqual(9007199254740991, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat64(-.infinity)_AlwaysTraps") { - let input = getFloat64(-.infinity) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat64(-.infinity)_AlwaysFails") { - let input = getFloat64(-.infinity) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat64(+.infinity)_AlwaysTraps") { - let input = getFloat64(+.infinity) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat64(+.infinity)_AlwaysFails") { - let input = getFloat64(+.infinity) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat64(-.nan)_AlwaysTraps") { - let input = getFloat64(-.nan) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat64(-.nan)_AlwaysFails") { - let input = getFloat64(-.nan) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat64(+.nan)_AlwaysTraps") { - let input = getFloat64(+.nan) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat64(+.nan)_AlwaysFails") { - let input = getFloat64(+.nan) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat64(-.signalingNaN)_AlwaysTraps") { - let input = getFloat64(-.signalingNaN) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat64(-.signalingNaN)_AlwaysFails") { - let input = getFloat64(-.signalingNaN) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat64(+.signalingNaN)_AlwaysTraps") { - let input = getFloat64(+.signalingNaN) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat64(+.signalingNaN)_AlwaysFails") { - let input = getFloat64(+.signalingNaN) - let actual = UInt64(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt64 +.test("FromFloat64_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getFloat64(-0.5)), + (getUInt64(+0), getFloat64(+0)), + (getUInt64(+0), getFloat64(-0)), + (getUInt64(+0), getFloat64(+0.5)), + (getUInt64(+127), getFloat64(+127.5)), + (getUInt64(+255), getFloat64(+255.5)), + (getUInt64(+32767), getFloat64(+32767.5)), + (getUInt64(+65535), getFloat64(+65535.5)), + (getUInt64(+9007199254740991), getFloat64(+9007199254740991)), +]) { + expectEqual($0.0, UInt64($0.1)) +} + +FixedPointConversion_Debug32_ToUInt64 +.test("FromFloat64_NeverFails") +.forEach(in: [ + (getUInt64(+0), getFloat64(+0)), + (getUInt64(+0), getFloat64(-0)), + (getUInt64(+9007199254740991), getFloat64(+9007199254740991)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToUInt64 +.test("FromFloat64_AlwaysTraps") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-1), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt64($0)) +} + +FixedPointConversion_Debug32_ToUInt64 +.test("FromFloat64_AlwaysFails") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-1), + getFloat64(-0.5), + getFloat64(+0.5), + getFloat64(+127.5), + getFloat64(+255.5), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectNil(UInt64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float80: (-18446744073709551615)...(18446744073709551615) +// MARK: Float80: (-18446744073709551615)...(+18446744073709551615) //===----------------------------------------------------------------------===// #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(-18446744073709551615)_AlwaysTraps") { - let input = getFloat80(-18446744073709551615) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(-18446744073709551615)_AlwaysFails") { - let input = getFloat80(-18446744073709551615) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(-32768.5)_AlwaysTraps") { - let input = getFloat80(-32768.5) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(-32768.5)_AlwaysFails") { - let input = getFloat80(-32768.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(-128.5)_AlwaysTraps") { - let input = getFloat80(-128.5) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(-128.5)_AlwaysFails") { - let input = getFloat80(-128.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(-1)_AlwaysTraps") { - let input = getFloat80(-1) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(-1)_AlwaysFails") { - let input = getFloat80(-1) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(-0.5)_NeverTraps") { - let input = getFloat80(-0.5) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(-0.5)_AlwaysFails") { - let input = getFloat80(-0.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(0)_NeverTraps") { - let input = getFloat80(0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(0)_NeverFails") { - let input = getFloat80(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(-0.0)_NeverTraps") { - let input = getFloat80(-0.0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(-0.0)_NeverFails") { - let input = getFloat80(-0.0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(0.0)_NeverTraps") { - let input = getFloat80(0.0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(0.0)_NeverFails") { - let input = getFloat80(0.0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(0.5)_NeverTraps") { - let input = getFloat80(0.5) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(0.5)_AlwaysFails") { - let input = getFloat80(0.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(127.5)_NeverTraps") { - let input = getFloat80(127.5) - let actual = UInt64(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(127.5)_AlwaysFails") { - let input = getFloat80(127.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(255.5)_NeverTraps") { - let input = getFloat80(255.5) - let actual = UInt64(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(255.5)_AlwaysFails") { - let input = getFloat80(255.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(32767.5)_NeverTraps") { - let input = getFloat80(32767.5) - let actual = UInt64(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(32767.5)_AlwaysFails") { - let input = getFloat80(32767.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(65535.5)_NeverTraps") { - let input = getFloat80(65535.5) - let actual = UInt64(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(65535.5)_AlwaysFails") { - let input = getFloat80(65535.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(18446744073709551615)_NeverTraps") { - let input = getFloat80(18446744073709551615) - let actual = UInt64(input) - expectEqual(18446744073709551615, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(18446744073709551615)_NeverFails") { - let input = getFloat80(18446744073709551615) - let actual = UInt64(exactly: input) - expectEqual(18446744073709551615, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(18446744073709551615)_NeverTraps") { - let input = getFloat80(18446744073709551615) - let actual = UInt64(input) - expectEqual(18446744073709551615, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(18446744073709551615)_NeverFails") { - let input = getFloat80(18446744073709551615) - let actual = UInt64(exactly: input) - expectEqual(18446744073709551615, actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(-.infinity)_AlwaysTraps") { - let input = getFloat80(-.infinity) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(-.infinity)_AlwaysFails") { - let input = getFloat80(-.infinity) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(+.infinity)_AlwaysTraps") { - let input = getFloat80(+.infinity) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(+.infinity)_AlwaysFails") { - let input = getFloat80(+.infinity) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(-.nan)_AlwaysTraps") { - let input = getFloat80(-.nan) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(-.nan)_AlwaysFails") { - let input = getFloat80(-.nan) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(+.nan)_AlwaysTraps") { - let input = getFloat80(+.nan) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(+.nan)_AlwaysFails") { - let input = getFloat80(+.nan) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(-.signalingNaN)_AlwaysTraps") { - let input = getFloat80(-.signalingNaN) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(-.signalingNaN)_AlwaysFails") { - let input = getFloat80(-.signalingNaN) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(+.signalingNaN)_AlwaysTraps") { - let input = getFloat80(+.signalingNaN) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt64.test("FromFloat80(+.signalingNaN)_AlwaysFails") { - let input = getFloat80(+.signalingNaN) - let actual = UInt64(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt64 +.test("FromFloat80_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getFloat80(-0.5)), + (getUInt64(+0), getFloat80(+0)), + (getUInt64(+0), getFloat80(-0)), + (getUInt64(+0), getFloat80(+0.5)), + (getUInt64(+127), getFloat80(+127.5)), + (getUInt64(+255), getFloat80(+255.5)), + (getUInt64(+32767), getFloat80(+32767.5)), + (getUInt64(+65535), getFloat80(+65535.5)), + (getUInt64(+18446744073709551615), getFloat80(+18446744073709551615)), +]) { + expectEqual($0.0, UInt64($0.1)) +} + +FixedPointConversion_Debug32_ToUInt64 +.test("FromFloat80_NeverFails") +.forEach(in: [ + (getUInt64(+0), getFloat80(+0)), + (getUInt64(+0), getFloat80(-0)), + (getUInt64(+18446744073709551615), getFloat80(+18446744073709551615)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToUInt64 +.test("FromFloat80_AlwaysTraps") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-1), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt64($0)) +} + +FixedPointConversion_Debug32_ToUInt64 +.test("FromFloat80_AlwaysFails") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-1), + getFloat80(-0.5), + getFloat80(+0.5), + getFloat80(+127.5), + getFloat80(+255.5), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectNil(UInt64(exactly: $0)) } #endif // Float80 diff --git a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug32_ToUInt8.swift b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug32_ToUInt8.swift index eae9cb4f49ffc..462f16ca47fe8 100644 --- a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug32_ToUInt8.swift +++ b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug32_ToUInt8.swift @@ -14,1800 +14,717 @@ import StdlibUnittest -let FixedPointConversion_Debug32_ToUInt8 = TestSuite("FixedPointConversion_Debug32_ToUInt8") +let FixedPointConversion_Debug32_ToUInt8 = TestSuite( + "FixedPointConversion_Debug32_ToUInt8" +) //===----------------------------------------------------------------------===// -// MARK: UInt8: (0)...(255) +// MARK: UInt8: (+0)...(+255) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt8.test("FromUInt8(0)_NeverTraps") { - let input = getUInt8(0) - let actual = UInt8(input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToUInt8 +.test("FromUInt8_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getUInt8(+0)), + (getUInt8(+255), getUInt8(+255)), +]) { + expectEqual($0.0, UInt8($0.1)) } -FixedPointConversion_Debug32_ToUInt8.test("FromUInt8(0)_NeverFails") { - let input = getUInt8(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromUInt8(255)_NeverTraps") { - let input = getUInt8(255) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromUInt8(255)_NeverFails") { - let input = getUInt8(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) +FixedPointConversion_Debug32_ToUInt8 +.test("FromUInt8_NeverFails") +.forEach(in: [ + (getUInt8(+0), getUInt8(+0)), + (getUInt8(+255), getUInt8(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int8: (-128)...(127) +// MARK: Int8: (-128)...(+127) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt8.test("FromInt8(-128)_AlwaysTraps") { - let input = getInt8(-128) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt8(-128)_AlwaysFails") { - let input = getInt8(-128) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt8(-1)_AlwaysTraps") { - let input = getInt8(-1) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } +FixedPointConversion_Debug32_ToUInt8 +.test("FromInt8_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getInt8(+0)), + (getUInt8(+127), getInt8(+127)), +]) { + expectEqual($0.0, UInt8($0.1)) } -FixedPointConversion_Debug32_ToUInt8.test("FromInt8(-1)_AlwaysFails") { - let input = getInt8(-1) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt8 +.test("FromInt8_NeverFails") +.forEach(in: [ + (getUInt8(+0), getInt8(+0)), + (getUInt8(+127), getInt8(+127)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) } -FixedPointConversion_Debug32_ToUInt8.test("FromInt8(0)_NeverTraps") { - let input = getInt8(0) - let actual = UInt8(input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToUInt8 +.test("FromInt8_AlwaysTraps") +.forEach(in: [ + getInt8(-128), + getInt8(-1), +]) { + expectCrashLater() + _blackHole(UInt8($0)) } -FixedPointConversion_Debug32_ToUInt8.test("FromInt8(0)_NeverFails") { - let input = getInt8(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt8(127)_NeverTraps") { - let input = getInt8(127) - let actual = UInt8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt8(127)_NeverFails") { - let input = getInt8(127) - let actual = UInt8(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Debug32_ToUInt8 +.test("FromInt8_AlwaysFails") +.forEach(in: [ + getInt8(-128), + getInt8(-1), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt16: (0)...(65535) +// MARK: UInt16: (+0)...(+65535) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt8.test("FromUInt16(0)_NeverTraps") { - let input = getUInt16(0) - let actual = UInt8(input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToUInt8 +.test("FromUInt16_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getUInt16(+0)), + (getUInt8(+255), getUInt16(+255)), +]) { + expectEqual($0.0, UInt8($0.1)) } -FixedPointConversion_Debug32_ToUInt8.test("FromUInt16(0)_NeverFails") { - let input = getUInt16(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToUInt8 +.test("FromUInt16_NeverFails") +.forEach(in: [ + (getUInt8(+0), getUInt16(+0)), + (getUInt8(+255), getUInt16(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) } -FixedPointConversion_Debug32_ToUInt8.test("FromUInt16(255)_NeverTraps") { - let input = getUInt16(255) - let actual = UInt8(input) - expectEqual(255, actual) +FixedPointConversion_Debug32_ToUInt8 +.test("FromUInt16_AlwaysTraps") +.forEach(in: [ + getUInt16(+256), + getUInt16(+65535), +]) { + expectCrashLater() + _blackHole(UInt8($0)) } -FixedPointConversion_Debug32_ToUInt8.test("FromUInt16(255)_NeverFails") { - let input = getUInt16(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromUInt16(256)_AlwaysTraps") { - let input = getUInt16(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromUInt16(256)_AlwaysFails") { - let input = getUInt16(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromUInt16(65535)_AlwaysTraps") { - let input = getUInt16(65535) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromUInt16(65535)_AlwaysFails") { - let input = getUInt16(65535) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt8 +.test("FromUInt16_AlwaysFails") +.forEach(in: [ + getUInt16(+256), + getUInt16(+65535), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int16: (-32768)...(32767) +// MARK: Int16: (-32768)...(+32767) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt8.test("FromInt16(-32768)_AlwaysTraps") { - let input = getInt16(-32768) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt16(-32768)_AlwaysFails") { - let input = getInt16(-32768) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt16(-1)_AlwaysTraps") { - let input = getInt16(-1) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt16(-1)_AlwaysFails") { - let input = getInt16(-1) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt16(0)_NeverTraps") { - let input = getInt16(0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt16(0)_NeverFails") { - let input = getInt16(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt16(255)_NeverTraps") { - let input = getInt16(255) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt16(255)_NeverFails") { - let input = getInt16(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt16(256)_AlwaysTraps") { - let input = getInt16(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt16(256)_AlwaysFails") { - let input = getInt16(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt16(32767)_AlwaysTraps") { - let input = getInt16(32767) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt16(32767)_AlwaysFails") { - let input = getInt16(32767) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt8 +.test("FromInt16_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getInt16(+0)), + (getUInt8(+255), getInt16(+255)), +]) { + expectEqual($0.0, UInt8($0.1)) +} + +FixedPointConversion_Debug32_ToUInt8 +.test("FromInt16_NeverFails") +.forEach(in: [ + (getUInt8(+0), getInt16(+0)), + (getUInt8(+255), getInt16(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToUInt8 +.test("FromInt16_AlwaysTraps") +.forEach(in: [ + getInt16(-32768), + getInt16(-1), + getInt16(+256), + getInt16(+32767), +]) { + expectCrashLater() + _blackHole(UInt8($0)) +} + +FixedPointConversion_Debug32_ToUInt8 +.test("FromInt16_AlwaysFails") +.forEach(in: [ + getInt16(-32768), + getInt16(-1), + getInt16(+256), + getInt16(+32767), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt32: (0)...(4294967295) +// MARK: UInt32: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt8.test("FromUInt32(0)_NeverTraps") { - let input = getUInt32(0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromUInt32(0)_NeverFails") { - let input = getUInt32(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToUInt8 +.test("FromUInt32_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getUInt32(+0)), + (getUInt8(+255), getUInt32(+255)), +]) { + expectEqual($0.0, UInt8($0.1)) } -FixedPointConversion_Debug32_ToUInt8.test("FromUInt32(255)_NeverTraps") { - let input = getUInt32(255) - let actual = UInt8(input) - expectEqual(255, actual) +FixedPointConversion_Debug32_ToUInt8 +.test("FromUInt32_NeverFails") +.forEach(in: [ + (getUInt8(+0), getUInt32(+0)), + (getUInt8(+255), getUInt32(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) } -FixedPointConversion_Debug32_ToUInt8.test("FromUInt32(255)_NeverFails") { - let input = getUInt32(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) +FixedPointConversion_Debug32_ToUInt8 +.test("FromUInt32_AlwaysTraps") +.forEach(in: [ + getUInt32(+256), + getUInt32(+4294967295), +]) { + expectCrashLater() + _blackHole(UInt8($0)) } -FixedPointConversion_Debug32_ToUInt8.test("FromUInt32(256)_AlwaysTraps") { - let input = getUInt32(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromUInt32(256)_AlwaysFails") { - let input = getUInt32(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromUInt32(4294967295)_AlwaysTraps") { - let input = getUInt32(4294967295) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromUInt32(4294967295)_AlwaysFails") { - let input = getUInt32(4294967295) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt8 +.test("FromUInt32_AlwaysFails") +.forEach(in: [ + getUInt32(+256), + getUInt32(+4294967295), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int32: (-2147483648)...(2147483647) +// MARK: Int32: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt8.test("FromInt32(-2147483648)_AlwaysTraps") { - let input = getInt32(-2147483648) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt32(-2147483648)_AlwaysFails") { - let input = getInt32(-2147483648) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt32(-1)_AlwaysTraps") { - let input = getInt32(-1) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt32(-1)_AlwaysFails") { - let input = getInt32(-1) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt32(0)_NeverTraps") { - let input = getInt32(0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt32(0)_NeverFails") { - let input = getInt32(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt32(255)_NeverTraps") { - let input = getInt32(255) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt32(255)_NeverFails") { - let input = getInt32(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt32(256)_AlwaysTraps") { - let input = getInt32(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt32(256)_AlwaysFails") { - let input = getInt32(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt32(2147483647)_AlwaysTraps") { - let input = getInt32(2147483647) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt32(2147483647)_AlwaysFails") { - let input = getInt32(2147483647) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt8 +.test("FromInt32_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getInt32(+0)), + (getUInt8(+255), getInt32(+255)), +]) { + expectEqual($0.0, UInt8($0.1)) +} + +FixedPointConversion_Debug32_ToUInt8 +.test("FromInt32_NeverFails") +.forEach(in: [ + (getUInt8(+0), getInt32(+0)), + (getUInt8(+255), getInt32(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToUInt8 +.test("FromInt32_AlwaysTraps") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-1), + getInt32(+256), + getInt32(+2147483647), +]) { + expectCrashLater() + _blackHole(UInt8($0)) +} + +FixedPointConversion_Debug32_ToUInt8 +.test("FromInt32_AlwaysFails") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-1), + getInt32(+256), + getInt32(+2147483647), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt64: (0)...(18446744073709551615) +// MARK: UInt64: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt8.test("FromUInt64(0)_NeverTraps") { - let input = getUInt64(0) - let actual = UInt8(input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToUInt8 +.test("FromUInt64_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getUInt64(+0)), + (getUInt8(+255), getUInt64(+255)), +]) { + expectEqual($0.0, UInt8($0.1)) } -FixedPointConversion_Debug32_ToUInt8.test("FromUInt64(0)_NeverFails") { - let input = getUInt64(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToUInt8 +.test("FromUInt64_NeverFails") +.forEach(in: [ + (getUInt8(+0), getUInt64(+0)), + (getUInt8(+255), getUInt64(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) } -FixedPointConversion_Debug32_ToUInt8.test("FromUInt64(255)_NeverTraps") { - let input = getUInt64(255) - let actual = UInt8(input) - expectEqual(255, actual) +FixedPointConversion_Debug32_ToUInt8 +.test("FromUInt64_AlwaysTraps") +.forEach(in: [ + getUInt64(+256), + getUInt64(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(UInt8($0)) } -FixedPointConversion_Debug32_ToUInt8.test("FromUInt64(255)_NeverFails") { - let input = getUInt64(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromUInt64(256)_AlwaysTraps") { - let input = getUInt64(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromUInt64(256)_AlwaysFails") { - let input = getUInt64(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromUInt64(18446744073709551615)_AlwaysTraps") { - let input = getUInt64(18446744073709551615) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromUInt64(18446744073709551615)_AlwaysFails") { - let input = getUInt64(18446744073709551615) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt8 +.test("FromUInt64_AlwaysFails") +.forEach(in: [ + getUInt64(+256), + getUInt64(+18446744073709551615), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int64: (-9223372036854775808)...(9223372036854775807) +// MARK: Int64: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt8.test("FromInt64(-9223372036854775808)_AlwaysTraps") { - let input = getInt64(-9223372036854775808) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt64(-9223372036854775808)_AlwaysFails") { - let input = getInt64(-9223372036854775808) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt64(-1)_AlwaysTraps") { - let input = getInt64(-1) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt64(-1)_AlwaysFails") { - let input = getInt64(-1) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt64(0)_NeverTraps") { - let input = getInt64(0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt64(0)_NeverFails") { - let input = getInt64(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt64(255)_NeverTraps") { - let input = getInt64(255) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt64(255)_NeverFails") { - let input = getInt64(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt64(256)_AlwaysTraps") { - let input = getInt64(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt64(256)_AlwaysFails") { - let input = getInt64(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt64(9223372036854775807)_AlwaysTraps") { - let input = getInt64(9223372036854775807) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt64(9223372036854775807)_AlwaysFails") { - let input = getInt64(9223372036854775807) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt8 +.test("FromInt64_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getInt64(+0)), + (getUInt8(+255), getInt64(+255)), +]) { + expectEqual($0.0, UInt8($0.1)) +} + +FixedPointConversion_Debug32_ToUInt8 +.test("FromInt64_NeverFails") +.forEach(in: [ + (getUInt8(+0), getInt64(+0)), + (getUInt8(+255), getInt64(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToUInt8 +.test("FromInt64_AlwaysTraps") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-1), + getInt64(+256), + getInt64(+9223372036854775807), +]) { + expectCrashLater() + _blackHole(UInt8($0)) +} + +FixedPointConversion_Debug32_ToUInt8 +.test("FromInt64_AlwaysFails") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-1), + getInt64(+256), + getInt64(+9223372036854775807), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt: (0)...(4294967295) +// MARK: UInt: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt8.test("FromUInt(0)_NeverTraps") { - let input = getUInt(0) - let actual = UInt8(input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToUInt8 +.test("FromUInt_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getUInt(+0)), + (getUInt8(+255), getUInt(+255)), +]) { + expectEqual($0.0, UInt8($0.1)) } -FixedPointConversion_Debug32_ToUInt8.test("FromUInt(0)_NeverFails") { - let input = getUInt(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug32_ToUInt8 +.test("FromUInt_NeverFails") +.forEach(in: [ + (getUInt8(+0), getUInt(+0)), + (getUInt8(+255), getUInt(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) } -FixedPointConversion_Debug32_ToUInt8.test("FromUInt(255)_NeverTraps") { - let input = getUInt(255) - let actual = UInt8(input) - expectEqual(255, actual) +FixedPointConversion_Debug32_ToUInt8 +.test("FromUInt_AlwaysTraps") +.forEach(in: [ + getUInt(+256), + getUInt(+4294967295), +]) { + expectCrashLater() + _blackHole(UInt8($0)) } -FixedPointConversion_Debug32_ToUInt8.test("FromUInt(255)_NeverFails") { - let input = getUInt(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromUInt(256)_AlwaysTraps") { - let input = getUInt(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromUInt(256)_AlwaysFails") { - let input = getUInt(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromUInt(4294967295)_AlwaysTraps") { - let input = getUInt(4294967295) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromUInt(4294967295)_AlwaysFails") { - let input = getUInt(4294967295) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt8 +.test("FromUInt_AlwaysFails") +.forEach(in: [ + getUInt(+256), + getUInt(+4294967295), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int: (-2147483648)...(2147483647) +// MARK: Int: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt8.test("FromInt(-2147483648)_AlwaysTraps") { - let input = getInt(-2147483648) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt(-2147483648)_AlwaysFails") { - let input = getInt(-2147483648) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt(-1)_AlwaysTraps") { - let input = getInt(-1) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt(-1)_AlwaysFails") { - let input = getInt(-1) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt(0)_NeverTraps") { - let input = getInt(0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt(0)_NeverFails") { - let input = getInt(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt(255)_NeverTraps") { - let input = getInt(255) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt(255)_NeverFails") { - let input = getInt(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt(256)_AlwaysTraps") { - let input = getInt(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt(256)_AlwaysFails") { - let input = getInt(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt(2147483647)_AlwaysTraps") { - let input = getInt(2147483647) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromInt(2147483647)_AlwaysFails") { - let input = getInt(2147483647) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt8 +.test("FromInt_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getInt(+0)), + (getUInt8(+255), getInt(+255)), +]) { + expectEqual($0.0, UInt8($0.1)) +} + +FixedPointConversion_Debug32_ToUInt8 +.test("FromInt_NeverFails") +.forEach(in: [ + (getUInt8(+0), getInt(+0)), + (getUInt8(+255), getInt(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToUInt8 +.test("FromInt_AlwaysTraps") +.forEach(in: [ + getInt(-2147483648), + getInt(-1), + getInt(+256), + getInt(+2147483647), +]) { + expectCrashLater() + _blackHole(UInt8($0)) +} + +FixedPointConversion_Debug32_ToUInt8 +.test("FromInt_AlwaysFails") +.forEach(in: [ + getInt(-2147483648), + getInt(-1), + getInt(+256), + getInt(+2147483647), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float16: (-2047)...(2047) +// MARK: Float16: (-2047)...(+2047) //===----------------------------------------------------------------------===// #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -FixedPointConversion_Debug32_ToUInt8.test("FromFloat16(-2047)_AlwaysTraps") { - let input = getFloat16(-2047) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat16(-2047)_AlwaysFails") { - let input = getFloat16(-2047) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat16(-128.5)_AlwaysTraps") { - let input = getFloat16(-128.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat16(-128.5)_AlwaysFails") { - let input = getFloat16(-128.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat16(-1)_AlwaysTraps") { - let input = getFloat16(-1) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat16(-1)_AlwaysFails") { - let input = getFloat16(-1) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat16(-0.5)_NeverTraps") { - let input = getFloat16(-0.5) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat16(-0.5)_AlwaysFails") { - let input = getFloat16(-0.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat16(0)_NeverTraps") { - let input = getFloat16(0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat16(0)_NeverFails") { - let input = getFloat16(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat16(-0.0)_NeverTraps") { - let input = getFloat16(-0.0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat16(-0.0)_NeverFails") { - let input = getFloat16(-0.0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat16(0.0)_NeverTraps") { - let input = getFloat16(0.0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat16(0.0)_NeverFails") { - let input = getFloat16(0.0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat16(0.5)_NeverTraps") { - let input = getFloat16(0.5) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat16(0.5)_AlwaysFails") { - let input = getFloat16(0.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat16(127.5)_NeverTraps") { - let input = getFloat16(127.5) - let actual = UInt8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat16(127.5)_AlwaysFails") { - let input = getFloat16(127.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat16(255)_NeverTraps") { - let input = getFloat16(255) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat16(255)_NeverFails") { - let input = getFloat16(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat16(255.5)_NeverTraps") { - let input = getFloat16(255.5) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat16(255.5)_AlwaysFails") { - let input = getFloat16(255.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat16(256)_AlwaysTraps") { - let input = getFloat16(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat16(256)_AlwaysFails") { - let input = getFloat16(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat16(2047)_AlwaysTraps") { - let input = getFloat16(2047) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat16(2047)_AlwaysFails") { - let input = getFloat16(2047) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat16(-.infinity)_AlwaysTraps") { - let input = getFloat16(-.infinity) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat16(-.infinity)_AlwaysFails") { - let input = getFloat16(-.infinity) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat16(+.infinity)_AlwaysTraps") { - let input = getFloat16(+.infinity) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat16(+.infinity)_AlwaysFails") { - let input = getFloat16(+.infinity) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat16(-.nan)_AlwaysTraps") { - let input = getFloat16(-.nan) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat16(-.nan)_AlwaysFails") { - let input = getFloat16(-.nan) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat16(+.nan)_AlwaysTraps") { - let input = getFloat16(+.nan) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat16(+.nan)_AlwaysFails") { - let input = getFloat16(+.nan) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat16(-.signalingNaN)_AlwaysTraps") { - let input = getFloat16(-.signalingNaN) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat16(-.signalingNaN)_AlwaysFails") { - let input = getFloat16(-.signalingNaN) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat16(+.signalingNaN)_AlwaysTraps") { - let input = getFloat16(+.signalingNaN) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat16(+.signalingNaN)_AlwaysFails") { - let input = getFloat16(+.signalingNaN) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt8 +.test("FromFloat16_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getFloat16(-0.5)), + (getUInt8(+0), getFloat16(-0)), + (getUInt8(+0), getFloat16(+0)), + (getUInt8(+0), getFloat16(+0.5)), + (getUInt8(+127), getFloat16(+127.5)), + (getUInt8(+255), getFloat16(+255)), + (getUInt8(+255), getFloat16(+255.5)), +]) { + expectEqual($0.0, UInt8($0.1)) +} + +FixedPointConversion_Debug32_ToUInt8 +.test("FromFloat16_NeverFails") +.forEach(in: [ + (getUInt8(+0), getFloat16(-0)), + (getUInt8(+0), getFloat16(+0)), + (getUInt8(+255), getFloat16(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToUInt8 +.test("FromFloat16_AlwaysTraps") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-128.5), + getFloat16(-1), + getFloat16(+256), + getFloat16(+2047), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt8($0)) +} + +FixedPointConversion_Debug32_ToUInt8 +.test("FromFloat16_AlwaysFails") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-128.5), + getFloat16(-1), + getFloat16(-0.5), + getFloat16(+0.5), + getFloat16(+127.5), + getFloat16(+255.5), + getFloat16(+256), + getFloat16(+2047), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectNil(UInt8(exactly: $0)) } } #endif // Float16 //===----------------------------------------------------------------------===// -// MARK: Float32: (-16777215)...(16777215) +// MARK: Float32: (-16777215)...(+16777215) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(-16777215)_AlwaysTraps") { - let input = getFloat32(-16777215) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(-16777215)_AlwaysFails") { - let input = getFloat32(-16777215) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(-32768.5)_AlwaysTraps") { - let input = getFloat32(-32768.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(-32768.5)_AlwaysFails") { - let input = getFloat32(-32768.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(-128.5)_AlwaysTraps") { - let input = getFloat32(-128.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(-128.5)_AlwaysFails") { - let input = getFloat32(-128.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(-1)_AlwaysTraps") { - let input = getFloat32(-1) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(-1)_AlwaysFails") { - let input = getFloat32(-1) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(-0.5)_NeverTraps") { - let input = getFloat32(-0.5) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(-0.5)_AlwaysFails") { - let input = getFloat32(-0.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(0)_NeverTraps") { - let input = getFloat32(0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(0)_NeverFails") { - let input = getFloat32(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(-0.0)_NeverTraps") { - let input = getFloat32(-0.0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(-0.0)_NeverFails") { - let input = getFloat32(-0.0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(0.0)_NeverTraps") { - let input = getFloat32(0.0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(0.0)_NeverFails") { - let input = getFloat32(0.0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(0.5)_NeverTraps") { - let input = getFloat32(0.5) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(0.5)_AlwaysFails") { - let input = getFloat32(0.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(127.5)_NeverTraps") { - let input = getFloat32(127.5) - let actual = UInt8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(127.5)_AlwaysFails") { - let input = getFloat32(127.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(255)_NeverTraps") { - let input = getFloat32(255) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(255)_NeverFails") { - let input = getFloat32(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(255.5)_NeverTraps") { - let input = getFloat32(255.5) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(255.5)_AlwaysFails") { - let input = getFloat32(255.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(256)_AlwaysTraps") { - let input = getFloat32(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(256)_AlwaysFails") { - let input = getFloat32(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(32767.5)_AlwaysTraps") { - let input = getFloat32(32767.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(32767.5)_AlwaysFails") { - let input = getFloat32(32767.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(65535.5)_AlwaysTraps") { - let input = getFloat32(65535.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(65535.5)_AlwaysFails") { - let input = getFloat32(65535.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(16777215)_AlwaysTraps") { - let input = getFloat32(16777215) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(16777215)_AlwaysFails") { - let input = getFloat32(16777215) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(-.infinity)_AlwaysTraps") { - let input = getFloat32(-.infinity) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(-.infinity)_AlwaysFails") { - let input = getFloat32(-.infinity) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(+.infinity)_AlwaysTraps") { - let input = getFloat32(+.infinity) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(+.infinity)_AlwaysFails") { - let input = getFloat32(+.infinity) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(-.nan)_AlwaysTraps") { - let input = getFloat32(-.nan) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(-.nan)_AlwaysFails") { - let input = getFloat32(-.nan) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(+.nan)_AlwaysTraps") { - let input = getFloat32(+.nan) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(+.nan)_AlwaysFails") { - let input = getFloat32(+.nan) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(-.signalingNaN)_AlwaysTraps") { - let input = getFloat32(-.signalingNaN) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(-.signalingNaN)_AlwaysFails") { - let input = getFloat32(-.signalingNaN) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(+.signalingNaN)_AlwaysTraps") { - let input = getFloat32(+.signalingNaN) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat32(+.signalingNaN)_AlwaysFails") { - let input = getFloat32(+.signalingNaN) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt8 +.test("FromFloat32_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getFloat32(-0.5)), + (getUInt8(+0), getFloat32(+0)), + (getUInt8(+0), getFloat32(-0)), + (getUInt8(+0), getFloat32(+0.5)), + (getUInt8(+127), getFloat32(+127.5)), + (getUInt8(+255), getFloat32(+255)), + (getUInt8(+255), getFloat32(+255.5)), +]) { + expectEqual($0.0, UInt8($0.1)) +} + +FixedPointConversion_Debug32_ToUInt8 +.test("FromFloat32_NeverFails") +.forEach(in: [ + (getUInt8(+0), getFloat32(+0)), + (getUInt8(+0), getFloat32(-0)), + (getUInt8(+255), getFloat32(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToUInt8 +.test("FromFloat32_AlwaysTraps") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-1), + getFloat32(+256), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(+16777215), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt8($0)) +} + +FixedPointConversion_Debug32_ToUInt8 +.test("FromFloat32_AlwaysFails") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-1), + getFloat32(-0.5), + getFloat32(+0.5), + getFloat32(+127.5), + getFloat32(+255.5), + getFloat32(+256), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(+16777215), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float64: (-9007199254740991)...(9007199254740991) +// MARK: Float64: (-9007199254740991)...(+9007199254740991) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(-9007199254740991)_AlwaysTraps") { - let input = getFloat64(-9007199254740991) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(-9007199254740991)_AlwaysFails") { - let input = getFloat64(-9007199254740991) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(-32768.5)_AlwaysTraps") { - let input = getFloat64(-32768.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(-32768.5)_AlwaysFails") { - let input = getFloat64(-32768.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(-128.5)_AlwaysTraps") { - let input = getFloat64(-128.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(-128.5)_AlwaysFails") { - let input = getFloat64(-128.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(-1)_AlwaysTraps") { - let input = getFloat64(-1) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(-1)_AlwaysFails") { - let input = getFloat64(-1) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(-0.5)_NeverTraps") { - let input = getFloat64(-0.5) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(-0.5)_AlwaysFails") { - let input = getFloat64(-0.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(0)_NeverTraps") { - let input = getFloat64(0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(0)_NeverFails") { - let input = getFloat64(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(-0.0)_NeverTraps") { - let input = getFloat64(-0.0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(-0.0)_NeverFails") { - let input = getFloat64(-0.0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(0.0)_NeverTraps") { - let input = getFloat64(0.0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(0.0)_NeverFails") { - let input = getFloat64(0.0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(0.5)_NeverTraps") { - let input = getFloat64(0.5) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(0.5)_AlwaysFails") { - let input = getFloat64(0.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(127.5)_NeverTraps") { - let input = getFloat64(127.5) - let actual = UInt8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(127.5)_AlwaysFails") { - let input = getFloat64(127.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(255)_NeverTraps") { - let input = getFloat64(255) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(255)_NeverFails") { - let input = getFloat64(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(255.5)_NeverTraps") { - let input = getFloat64(255.5) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(255.5)_AlwaysFails") { - let input = getFloat64(255.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(256)_AlwaysTraps") { - let input = getFloat64(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(256)_AlwaysFails") { - let input = getFloat64(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(32767.5)_AlwaysTraps") { - let input = getFloat64(32767.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(32767.5)_AlwaysFails") { - let input = getFloat64(32767.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(65535.5)_AlwaysTraps") { - let input = getFloat64(65535.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(65535.5)_AlwaysFails") { - let input = getFloat64(65535.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(9007199254740991)_AlwaysTraps") { - let input = getFloat64(9007199254740991) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(9007199254740991)_AlwaysFails") { - let input = getFloat64(9007199254740991) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(-.infinity)_AlwaysTraps") { - let input = getFloat64(-.infinity) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(-.infinity)_AlwaysFails") { - let input = getFloat64(-.infinity) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(+.infinity)_AlwaysTraps") { - let input = getFloat64(+.infinity) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(+.infinity)_AlwaysFails") { - let input = getFloat64(+.infinity) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(-.nan)_AlwaysTraps") { - let input = getFloat64(-.nan) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(-.nan)_AlwaysFails") { - let input = getFloat64(-.nan) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(+.nan)_AlwaysTraps") { - let input = getFloat64(+.nan) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(+.nan)_AlwaysFails") { - let input = getFloat64(+.nan) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(-.signalingNaN)_AlwaysTraps") { - let input = getFloat64(-.signalingNaN) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(-.signalingNaN)_AlwaysFails") { - let input = getFloat64(-.signalingNaN) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(+.signalingNaN)_AlwaysTraps") { - let input = getFloat64(+.signalingNaN) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat64(+.signalingNaN)_AlwaysFails") { - let input = getFloat64(+.signalingNaN) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt8 +.test("FromFloat64_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getFloat64(-0.5)), + (getUInt8(+0), getFloat64(+0)), + (getUInt8(+0), getFloat64(-0)), + (getUInt8(+0), getFloat64(+0.5)), + (getUInt8(+127), getFloat64(+127.5)), + (getUInt8(+255), getFloat64(+255)), + (getUInt8(+255), getFloat64(+255.5)), +]) { + expectEqual($0.0, UInt8($0.1)) +} + +FixedPointConversion_Debug32_ToUInt8 +.test("FromFloat64_NeverFails") +.forEach(in: [ + (getUInt8(+0), getFloat64(+0)), + (getUInt8(+0), getFloat64(-0)), + (getUInt8(+255), getFloat64(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToUInt8 +.test("FromFloat64_AlwaysTraps") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-1), + getFloat64(+256), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt8($0)) +} + +FixedPointConversion_Debug32_ToUInt8 +.test("FromFloat64_AlwaysFails") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-1), + getFloat64(-0.5), + getFloat64(+0.5), + getFloat64(+127.5), + getFloat64(+255.5), + getFloat64(+256), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float80: (-18446744073709551615)...(18446744073709551615) +// MARK: Float80: (-18446744073709551615)...(+18446744073709551615) //===----------------------------------------------------------------------===// #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(-18446744073709551615)_AlwaysTraps") { - let input = getFloat80(-18446744073709551615) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(-18446744073709551615)_AlwaysFails") { - let input = getFloat80(-18446744073709551615) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(-32768.5)_AlwaysTraps") { - let input = getFloat80(-32768.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(-32768.5)_AlwaysFails") { - let input = getFloat80(-32768.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(-128.5)_AlwaysTraps") { - let input = getFloat80(-128.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(-128.5)_AlwaysFails") { - let input = getFloat80(-128.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(-1)_AlwaysTraps") { - let input = getFloat80(-1) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(-1)_AlwaysFails") { - let input = getFloat80(-1) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(-0.5)_NeverTraps") { - let input = getFloat80(-0.5) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(-0.5)_AlwaysFails") { - let input = getFloat80(-0.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(0)_NeverTraps") { - let input = getFloat80(0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(0)_NeverFails") { - let input = getFloat80(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(-0.0)_NeverTraps") { - let input = getFloat80(-0.0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(-0.0)_NeverFails") { - let input = getFloat80(-0.0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(0.0)_NeverTraps") { - let input = getFloat80(0.0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(0.0)_NeverFails") { - let input = getFloat80(0.0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(0.5)_NeverTraps") { - let input = getFloat80(0.5) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(0.5)_AlwaysFails") { - let input = getFloat80(0.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(127.5)_NeverTraps") { - let input = getFloat80(127.5) - let actual = UInt8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(127.5)_AlwaysFails") { - let input = getFloat80(127.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(255)_NeverTraps") { - let input = getFloat80(255) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(255)_NeverFails") { - let input = getFloat80(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(255.5)_NeverTraps") { - let input = getFloat80(255.5) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(255.5)_AlwaysFails") { - let input = getFloat80(255.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(256)_AlwaysTraps") { - let input = getFloat80(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(256)_AlwaysFails") { - let input = getFloat80(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(32767.5)_AlwaysTraps") { - let input = getFloat80(32767.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(32767.5)_AlwaysFails") { - let input = getFloat80(32767.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(65535.5)_AlwaysTraps") { - let input = getFloat80(65535.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(65535.5)_AlwaysFails") { - let input = getFloat80(65535.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(18446744073709551615)_AlwaysTraps") { - let input = getFloat80(18446744073709551615) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(18446744073709551615)_AlwaysFails") { - let input = getFloat80(18446744073709551615) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(-.infinity)_AlwaysTraps") { - let input = getFloat80(-.infinity) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(-.infinity)_AlwaysFails") { - let input = getFloat80(-.infinity) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(+.infinity)_AlwaysTraps") { - let input = getFloat80(+.infinity) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(+.infinity)_AlwaysFails") { - let input = getFloat80(+.infinity) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(-.nan)_AlwaysTraps") { - let input = getFloat80(-.nan) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(-.nan)_AlwaysFails") { - let input = getFloat80(-.nan) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(+.nan)_AlwaysTraps") { - let input = getFloat80(+.nan) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(+.nan)_AlwaysFails") { - let input = getFloat80(+.nan) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(-.signalingNaN)_AlwaysTraps") { - let input = getFloat80(-.signalingNaN) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(-.signalingNaN)_AlwaysFails") { - let input = getFloat80(-.signalingNaN) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(+.signalingNaN)_AlwaysTraps") { - let input = getFloat80(+.signalingNaN) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug32_ToUInt8.test("FromFloat80(+.signalingNaN)_AlwaysFails") { - let input = getFloat80(+.signalingNaN) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug32_ToUInt8 +.test("FromFloat80_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getFloat80(-0.5)), + (getUInt8(+0), getFloat80(-0)), + (getUInt8(+0), getFloat80(+0)), + (getUInt8(+0), getFloat80(+0.5)), + (getUInt8(+127), getFloat80(+127.5)), + (getUInt8(+255), getFloat80(+255)), + (getUInt8(+255), getFloat80(+255.5)), +]) { + expectEqual($0.0, UInt8($0.1)) +} + +FixedPointConversion_Debug32_ToUInt8 +.test("FromFloat80_NeverFails") +.forEach(in: [ + (getUInt8(+0), getFloat80(-0)), + (getUInt8(+0), getFloat80(+0)), + (getUInt8(+255), getFloat80(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) +} + +FixedPointConversion_Debug32_ToUInt8 +.test("FromFloat80_AlwaysTraps") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-1), + getFloat80(+256), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt8($0)) +} + +FixedPointConversion_Debug32_ToUInt8 +.test("FromFloat80_AlwaysFails") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-1), + getFloat80(-0.5), + getFloat80(+0.5), + getFloat80(+127.5), + getFloat80(+255.5), + getFloat80(+256), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectNil(UInt8(exactly: $0)) } #endif // Float80 diff --git a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug64_ToInt.swift b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug64_ToInt.swift index 8e8c9de9c51d1..ccc3ed5b8cc0f 100644 --- a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug64_ToInt.swift +++ b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug64_ToInt.swift @@ -14,1358 +14,562 @@ import StdlibUnittest -let FixedPointConversion_Debug64_ToInt = TestSuite("FixedPointConversion_Debug64_ToInt") +let FixedPointConversion_Debug64_ToInt = TestSuite( + "FixedPointConversion_Debug64_ToInt" +) //===----------------------------------------------------------------------===// -// MARK: UInt8: (0)...(255) +// MARK: UInt8: (+0)...(+255) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt.test("FromUInt8(0)_NeverTraps") { - let input = getUInt8(0) - let actual = Int(input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToInt +.test("FromUInt8_NeverTraps") +.forEach(in: [ + (getInt(+0), getUInt8(+0)), + (getInt(+255), getUInt8(+255)), +]) { + expectEqual($0.0, Int($0.1)) } -FixedPointConversion_Debug64_ToInt.test("FromUInt8(0)_NeverFails") { - let input = getUInt8(0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromUInt8(255)_NeverTraps") { - let input = getUInt8(255) - let actual = Int(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromUInt8(255)_NeverFails") { - let input = getUInt8(255) - let actual = Int(exactly: input) - expectEqual(255, actual) +FixedPointConversion_Debug64_ToInt +.test("FromUInt8_NeverFails") +.forEach(in: [ + (getInt(+0), getUInt8(+0)), + (getInt(+255), getUInt8(+255)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int8: (-128)...(127) +// MARK: Int8: (-128)...(+127) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt.test("FromInt8(-128)_NeverTraps") { - let input = getInt8(-128) - let actual = Int(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromInt8(-128)_NeverFails") { - let input = getInt8(-128) - let actual = Int(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromInt8(0)_NeverTraps") { - let input = getInt8(0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromInt8(0)_NeverFails") { - let input = getInt8(0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromInt8(127)_NeverTraps") { - let input = getInt8(127) - let actual = Int(input) - expectEqual(127, actual) +FixedPointConversion_Debug64_ToInt +.test("FromInt8_NeverTraps") +.forEach(in: [ + (getInt(-128), getInt8(-128)), + (getInt(+0), getInt8(+0)), + (getInt(+127), getInt8(+127)), +]) { + expectEqual($0.0, Int($0.1)) } -FixedPointConversion_Debug64_ToInt.test("FromInt8(127)_NeverFails") { - let input = getInt8(127) - let actual = Int(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Debug64_ToInt +.test("FromInt8_NeverFails") +.forEach(in: [ + (getInt(-128), getInt8(-128)), + (getInt(+0), getInt8(+0)), + (getInt(+127), getInt8(+127)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt16: (0)...(65535) +// MARK: UInt16: (+0)...(+65535) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt.test("FromUInt16(0)_NeverTraps") { - let input = getUInt16(0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromUInt16(0)_NeverFails") { - let input = getUInt16(0) - let actual = Int(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToInt +.test("FromUInt16_NeverTraps") +.forEach(in: [ + (getInt(+0), getUInt16(+0)), + (getInt(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, Int($0.1)) } -FixedPointConversion_Debug64_ToInt.test("FromUInt16(65535)_NeverTraps") { - let input = getUInt16(65535) - let actual = Int(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromUInt16(65535)_NeverFails") { - let input = getUInt16(65535) - let actual = Int(exactly: input) - expectEqual(65535, actual) +FixedPointConversion_Debug64_ToInt +.test("FromUInt16_NeverFails") +.forEach(in: [ + (getInt(+0), getUInt16(+0)), + (getInt(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int16: (-32768)...(32767) +// MARK: Int16: (-32768)...(+32767) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt.test("FromInt16(-32768)_NeverTraps") { - let input = getInt16(-32768) - let actual = Int(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromInt16(-32768)_NeverFails") { - let input = getInt16(-32768) - let actual = Int(exactly: input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromInt16(0)_NeverTraps") { - let input = getInt16(0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromInt16(0)_NeverFails") { - let input = getInt16(0) - let actual = Int(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToInt +.test("FromInt16_NeverTraps") +.forEach(in: [ + (getInt(-32768), getInt16(-32768)), + (getInt(+0), getInt16(+0)), + (getInt(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, Int($0.1)) } -FixedPointConversion_Debug64_ToInt.test("FromInt16(32767)_NeverTraps") { - let input = getInt16(32767) - let actual = Int(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromInt16(32767)_NeverFails") { - let input = getInt16(32767) - let actual = Int(exactly: input) - expectEqual(32767, actual) +FixedPointConversion_Debug64_ToInt +.test("FromInt16_NeverFails") +.forEach(in: [ + (getInt(-32768), getInt16(-32768)), + (getInt(+0), getInt16(+0)), + (getInt(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt32: (0)...(4294967295) +// MARK: UInt32: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt.test("FromUInt32(0)_NeverTraps") { - let input = getUInt32(0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromUInt32(0)_NeverFails") { - let input = getUInt32(0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromUInt32(4294967295)_NeverTraps") { - let input = getUInt32(4294967295) - let actual = Int(input) - expectEqual(4294967295, actual) +FixedPointConversion_Debug64_ToInt +.test("FromUInt32_NeverTraps") +.forEach(in: [ + (getInt(+0), getUInt32(+0)), + (getInt(+4294967295), getUInt32(+4294967295)), +]) { + expectEqual($0.0, Int($0.1)) } -FixedPointConversion_Debug64_ToInt.test("FromUInt32(4294967295)_NeverFails") { - let input = getUInt32(4294967295) - let actual = Int(exactly: input) - expectEqual(4294967295, actual) +FixedPointConversion_Debug64_ToInt +.test("FromUInt32_NeverFails") +.forEach(in: [ + (getInt(+0), getUInt32(+0)), + (getInt(+4294967295), getUInt32(+4294967295)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int32: (-2147483648)...(2147483647) +// MARK: Int32: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt.test("FromInt32(-2147483648)_NeverTraps") { - let input = getInt32(-2147483648) - let actual = Int(input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromInt32(-2147483648)_NeverFails") { - let input = getInt32(-2147483648) - let actual = Int(exactly: input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromInt32(0)_NeverTraps") { - let input = getInt32(0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromInt32(0)_NeverFails") { - let input = getInt32(0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromInt32(2147483647)_NeverTraps") { - let input = getInt32(2147483647) - let actual = Int(input) - expectEqual(2147483647, actual) +FixedPointConversion_Debug64_ToInt +.test("FromInt32_NeverTraps") +.forEach(in: [ + (getInt(-2147483648), getInt32(-2147483648)), + (getInt(+0), getInt32(+0)), + (getInt(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, Int($0.1)) } -FixedPointConversion_Debug64_ToInt.test("FromInt32(2147483647)_NeverFails") { - let input = getInt32(2147483647) - let actual = Int(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Debug64_ToInt +.test("FromInt32_NeverFails") +.forEach(in: [ + (getInt(-2147483648), getInt32(-2147483648)), + (getInt(+0), getInt32(+0)), + (getInt(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt64: (0)...(18446744073709551615) +// MARK: UInt64: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt.test("FromUInt64(0)_NeverTraps") { - let input = getUInt64(0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromUInt64(0)_NeverFails") { - let input = getUInt64(0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromUInt64(9223372036854775807)_NeverTraps") { - let input = getUInt64(9223372036854775807) - let actual = Int(input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromUInt64(9223372036854775807)_NeverFails") { - let input = getUInt64(9223372036854775807) - let actual = Int(exactly: input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromUInt64(9223372036854775808)_AlwaysTraps") { - let input = getUInt64(9223372036854775808) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } +FixedPointConversion_Debug64_ToInt +.test("FromUInt64_NeverTraps") +.forEach(in: [ + (getInt(+0), getUInt64(+0)), + (getInt(+9223372036854775807), getUInt64(+9223372036854775807)), +]) { + expectEqual($0.0, Int($0.1)) } -FixedPointConversion_Debug64_ToInt.test("FromUInt64(9223372036854775808)_AlwaysFails") { - let input = getUInt64(9223372036854775808) - let actual = Int(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt +.test("FromUInt64_NeverFails") +.forEach(in: [ + (getInt(+0), getUInt64(+0)), + (getInt(+9223372036854775807), getUInt64(+9223372036854775807)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) } -FixedPointConversion_Debug64_ToInt.test("FromUInt64(18446744073709551615)_AlwaysTraps") { - let input = getUInt64(18446744073709551615) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } +FixedPointConversion_Debug64_ToInt +.test("FromUInt64_AlwaysTraps") +.forEach(in: [ + getUInt64(+9223372036854775808), + getUInt64(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(Int($0)) } -FixedPointConversion_Debug64_ToInt.test("FromUInt64(18446744073709551615)_AlwaysFails") { - let input = getUInt64(18446744073709551615) - let actual = Int(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt +.test("FromUInt64_AlwaysFails") +.forEach(in: [ + getUInt64(+9223372036854775808), + getUInt64(+18446744073709551615), +]) { + expectNil(Int(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int64: (-9223372036854775808)...(9223372036854775807) +// MARK: Int64: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt.test("FromInt64(-9223372036854775808)_NeverTraps") { - let input = getInt64(-9223372036854775808) - let actual = Int(input) - expectEqual(-9223372036854775808, actual) +FixedPointConversion_Debug64_ToInt +.test("FromInt64_NeverTraps") +.forEach(in: [ + (getInt(-9223372036854775808), getInt64(-9223372036854775808)), + (getInt(+0), getInt64(+0)), + (getInt(+9223372036854775807), getInt64(+9223372036854775807)), +]) { + expectEqual($0.0, Int($0.1)) } -FixedPointConversion_Debug64_ToInt.test("FromInt64(-9223372036854775808)_NeverFails") { - let input = getInt64(-9223372036854775808) - let actual = Int(exactly: input) - expectEqual(-9223372036854775808, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromInt64(0)_NeverTraps") { - let input = getInt64(0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromInt64(0)_NeverFails") { - let input = getInt64(0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromInt64(9223372036854775807)_NeverTraps") { - let input = getInt64(9223372036854775807) - let actual = Int(input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromInt64(9223372036854775807)_NeverFails") { - let input = getInt64(9223372036854775807) - let actual = Int(exactly: input) - expectEqual(9223372036854775807, actual) +FixedPointConversion_Debug64_ToInt +.test("FromInt64_NeverFails") +.forEach(in: [ + (getInt(-9223372036854775808), getInt64(-9223372036854775808)), + (getInt(+0), getInt64(+0)), + (getInt(+9223372036854775807), getInt64(+9223372036854775807)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt: (0)...(18446744073709551615) +// MARK: UInt: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt.test("FromUInt(0)_NeverTraps") { - let input = getUInt(0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromUInt(0)_NeverFails") { - let input = getUInt(0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromUInt(9223372036854775807)_NeverTraps") { - let input = getUInt(9223372036854775807) - let actual = Int(input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromUInt(9223372036854775807)_NeverFails") { - let input = getUInt(9223372036854775807) - let actual = Int(exactly: input) - expectEqual(9223372036854775807, actual) +FixedPointConversion_Debug64_ToInt +.test("FromUInt_NeverTraps") +.forEach(in: [ + (getInt(+0), getUInt(+0)), + (getInt(+9223372036854775807), getUInt(+9223372036854775807)), +]) { + expectEqual($0.0, Int($0.1)) } -FixedPointConversion_Debug64_ToInt.test("FromUInt(9223372036854775808)_AlwaysTraps") { - let input = getUInt(9223372036854775808) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } +FixedPointConversion_Debug64_ToInt +.test("FromUInt_NeverFails") +.forEach(in: [ + (getInt(+0), getUInt(+0)), + (getInt(+9223372036854775807), getUInt(+9223372036854775807)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) } -FixedPointConversion_Debug64_ToInt.test("FromUInt(9223372036854775808)_AlwaysFails") { - let input = getUInt(9223372036854775808) - let actual = Int(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt +.test("FromUInt_AlwaysTraps") +.forEach(in: [ + getUInt(+9223372036854775808), + getUInt(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(Int($0)) } -FixedPointConversion_Debug64_ToInt.test("FromUInt(18446744073709551615)_AlwaysTraps") { - let input = getUInt(18446744073709551615) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt.test("FromUInt(18446744073709551615)_AlwaysFails") { - let input = getUInt(18446744073709551615) - let actual = Int(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt +.test("FromUInt_AlwaysFails") +.forEach(in: [ + getUInt(+9223372036854775808), + getUInt(+18446744073709551615), +]) { + expectNil(Int(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int: (-9223372036854775808)...(9223372036854775807) +// MARK: Int: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt.test("FromInt(-9223372036854775808)_NeverTraps") { - let input = getInt(-9223372036854775808) - let actual = Int(input) - expectEqual(-9223372036854775808, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromInt(-9223372036854775808)_NeverFails") { - let input = getInt(-9223372036854775808) - let actual = Int(exactly: input) - expectEqual(-9223372036854775808, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromInt(0)_NeverTraps") { - let input = getInt(0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromInt(0)_NeverFails") { - let input = getInt(0) - let actual = Int(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToInt +.test("FromInt_NeverTraps") +.forEach(in: [ + (getInt(-9223372036854775808), getInt(-9223372036854775808)), + (getInt(+0), getInt(+0)), + (getInt(+9223372036854775807), getInt(+9223372036854775807)), +]) { + expectEqual($0.0, Int($0.1)) } -FixedPointConversion_Debug64_ToInt.test("FromInt(9223372036854775807)_NeverTraps") { - let input = getInt(9223372036854775807) - let actual = Int(input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromInt(9223372036854775807)_NeverFails") { - let input = getInt(9223372036854775807) - let actual = Int(exactly: input) - expectEqual(9223372036854775807, actual) +FixedPointConversion_Debug64_ToInt +.test("FromInt_NeverFails") +.forEach(in: [ + (getInt(-9223372036854775808), getInt(-9223372036854775808)), + (getInt(+0), getInt(+0)), + (getInt(+9223372036854775807), getInt(+9223372036854775807)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Float16: (-2047)...(2047) +// MARK: Float16: (-2047)...(+2047) //===----------------------------------------------------------------------===// #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -FixedPointConversion_Debug64_ToInt.test("FromFloat16(-2047)_NeverTraps") { - let input = getFloat16(-2047) - let actual = Int(input) - expectEqual(-2047, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat16(-2047)_NeverFails") { - let input = getFloat16(-2047) - let actual = Int(exactly: input) - expectEqual(-2047, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat16(-128.5)_NeverTraps") { - let input = getFloat16(-128.5) - let actual = Int(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat16(-128.5)_AlwaysFails") { - let input = getFloat16(-128.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat16(-0.5)_NeverTraps") { - let input = getFloat16(-0.5) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat16(-0.5)_AlwaysFails") { - let input = getFloat16(-0.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat16(-0.0)_NeverTraps") { - let input = getFloat16(-0.0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat16(-0.0)_NeverFails") { - let input = getFloat16(-0.0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat16(0.0)_NeverTraps") { - let input = getFloat16(0.0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat16(0.0)_NeverFails") { - let input = getFloat16(0.0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat16(0.5)_NeverTraps") { - let input = getFloat16(0.5) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat16(0.5)_AlwaysFails") { - let input = getFloat16(0.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat16(127.5)_NeverTraps") { - let input = getFloat16(127.5) - let actual = Int(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat16(127.5)_AlwaysFails") { - let input = getFloat16(127.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat16(255.5)_NeverTraps") { - let input = getFloat16(255.5) - let actual = Int(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat16(255.5)_AlwaysFails") { - let input = getFloat16(255.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat16(2047)_NeverTraps") { - let input = getFloat16(2047) - let actual = Int(input) - expectEqual(2047, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat16(2047)_NeverFails") { - let input = getFloat16(2047) - let actual = Int(exactly: input) - expectEqual(2047, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat16(-.infinity)_AlwaysTraps") { - let input = getFloat16(-.infinity) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat16(-.infinity)_AlwaysFails") { - let input = getFloat16(-.infinity) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat16(+.infinity)_AlwaysTraps") { - let input = getFloat16(+.infinity) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat16(+.infinity)_AlwaysFails") { - let input = getFloat16(+.infinity) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat16(-.nan)_AlwaysTraps") { - let input = getFloat16(-.nan) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat16(-.nan)_AlwaysFails") { - let input = getFloat16(-.nan) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat16(+.nan)_AlwaysTraps") { - let input = getFloat16(+.nan) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat16(+.nan)_AlwaysFails") { - let input = getFloat16(+.nan) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat16(-.signalingNaN)_AlwaysTraps") { - let input = getFloat16(-.signalingNaN) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat16(-.signalingNaN)_AlwaysFails") { - let input = getFloat16(-.signalingNaN) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat16(+.signalingNaN)_AlwaysTraps") { - let input = getFloat16(+.signalingNaN) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat16(+.signalingNaN)_AlwaysFails") { - let input = getFloat16(+.signalingNaN) - let actual = Int(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt +.test("FromFloat16_NeverTraps") +.forEach(in: [ + (getInt(-2047), getFloat16(-2047)), + (getInt(-128), getFloat16(-128.5)), + (getInt(+0), getFloat16(-0.5)), + (getInt(+0), getFloat16(+0)), + (getInt(+0), getFloat16(-0)), + (getInt(+0), getFloat16(+0.5)), + (getInt(+127), getFloat16(+127.5)), + (getInt(+255), getFloat16(+255.5)), + (getInt(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, Int($0.1)) +} + +FixedPointConversion_Debug64_ToInt +.test("FromFloat16_NeverFails") +.forEach(in: [ + (getInt(-2047), getFloat16(-2047)), + (getInt(+0), getFloat16(+0)), + (getInt(+0), getFloat16(-0)), + (getInt(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToInt +.test("FromFloat16_AlwaysTraps") +.forEach(in: [ + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int($0)) +} + +FixedPointConversion_Debug64_ToInt +.test("FromFloat16_AlwaysFails") +.forEach(in: [ + getFloat16(-128.5), + getFloat16(-0.5), + getFloat16(+0.5), + getFloat16(+127.5), + getFloat16(+255.5), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectNil(Int(exactly: $0)) } } #endif // Float16 //===----------------------------------------------------------------------===// -// MARK: Float32: (-16777215)...(16777215) +// MARK: Float32: (-16777215)...(+16777215) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt.test("FromFloat32(-16777215)_NeverTraps") { - let input = getFloat32(-16777215) - let actual = Int(input) - expectEqual(-16777215, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat32(-16777215)_NeverFails") { - let input = getFloat32(-16777215) - let actual = Int(exactly: input) - expectEqual(-16777215, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat32(-32768.5)_NeverTraps") { - let input = getFloat32(-32768.5) - let actual = Int(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat32(-32768.5)_AlwaysFails") { - let input = getFloat32(-32768.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat32(-128.5)_NeverTraps") { - let input = getFloat32(-128.5) - let actual = Int(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat32(-128.5)_AlwaysFails") { - let input = getFloat32(-128.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat32(-0.5)_NeverTraps") { - let input = getFloat32(-0.5) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat32(-0.5)_AlwaysFails") { - let input = getFloat32(-0.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat32(-0.0)_NeverTraps") { - let input = getFloat32(-0.0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat32(-0.0)_NeverFails") { - let input = getFloat32(-0.0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat32(0.0)_NeverTraps") { - let input = getFloat32(0.0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat32(0.0)_NeverFails") { - let input = getFloat32(0.0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat32(0.5)_NeverTraps") { - let input = getFloat32(0.5) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat32(0.5)_AlwaysFails") { - let input = getFloat32(0.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat32(127.5)_NeverTraps") { - let input = getFloat32(127.5) - let actual = Int(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat32(127.5)_AlwaysFails") { - let input = getFloat32(127.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat32(255.5)_NeverTraps") { - let input = getFloat32(255.5) - let actual = Int(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat32(255.5)_AlwaysFails") { - let input = getFloat32(255.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat32(32767.5)_NeverTraps") { - let input = getFloat32(32767.5) - let actual = Int(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat32(32767.5)_AlwaysFails") { - let input = getFloat32(32767.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat32(65535.5)_NeverTraps") { - let input = getFloat32(65535.5) - let actual = Int(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat32(65535.5)_AlwaysFails") { - let input = getFloat32(65535.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat32(16777215)_NeverTraps") { - let input = getFloat32(16777215) - let actual = Int(input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat32(16777215)_NeverFails") { - let input = getFloat32(16777215) - let actual = Int(exactly: input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat32(-.infinity)_AlwaysTraps") { - let input = getFloat32(-.infinity) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat32(-.infinity)_AlwaysFails") { - let input = getFloat32(-.infinity) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat32(+.infinity)_AlwaysTraps") { - let input = getFloat32(+.infinity) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat32(+.infinity)_AlwaysFails") { - let input = getFloat32(+.infinity) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat32(-.nan)_AlwaysTraps") { - let input = getFloat32(-.nan) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat32(-.nan)_AlwaysFails") { - let input = getFloat32(-.nan) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat32(+.nan)_AlwaysTraps") { - let input = getFloat32(+.nan) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat32(+.nan)_AlwaysFails") { - let input = getFloat32(+.nan) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat32(-.signalingNaN)_AlwaysTraps") { - let input = getFloat32(-.signalingNaN) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat32(-.signalingNaN)_AlwaysFails") { - let input = getFloat32(-.signalingNaN) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat32(+.signalingNaN)_AlwaysTraps") { - let input = getFloat32(+.signalingNaN) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat32(+.signalingNaN)_AlwaysFails") { - let input = getFloat32(+.signalingNaN) - let actual = Int(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt +.test("FromFloat32_NeverTraps") +.forEach(in: [ + (getInt(-16777215), getFloat32(-16777215)), + (getInt(-32768), getFloat32(-32768.5)), + (getInt(-128), getFloat32(-128.5)), + (getInt(+0), getFloat32(-0.5)), + (getInt(+0), getFloat32(+0)), + (getInt(+0), getFloat32(-0)), + (getInt(+0), getFloat32(+0.5)), + (getInt(+127), getFloat32(+127.5)), + (getInt(+255), getFloat32(+255.5)), + (getInt(+32767), getFloat32(+32767.5)), + (getInt(+65535), getFloat32(+65535.5)), + (getInt(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, Int($0.1)) +} + +FixedPointConversion_Debug64_ToInt +.test("FromFloat32_NeverFails") +.forEach(in: [ + (getInt(-16777215), getFloat32(-16777215)), + (getInt(+0), getFloat32(+0)), + (getInt(+0), getFloat32(-0)), + (getInt(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToInt +.test("FromFloat32_AlwaysTraps") +.forEach(in: [ + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int($0)) +} + +FixedPointConversion_Debug64_ToInt +.test("FromFloat32_AlwaysFails") +.forEach(in: [ + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-0.5), + getFloat32(+0.5), + getFloat32(+127.5), + getFloat32(+255.5), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectNil(Int(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float64: (-9007199254740991)...(9007199254740991) +// MARK: Float64: (-9007199254740991)...(+9007199254740991) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt.test("FromFloat64(-9007199254740991)_NeverTraps") { - let input = getFloat64(-9007199254740991) - let actual = Int(input) - expectEqual(-9007199254740991, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat64(-9007199254740991)_NeverFails") { - let input = getFloat64(-9007199254740991) - let actual = Int(exactly: input) - expectEqual(-9007199254740991, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat64(-32768.5)_NeverTraps") { - let input = getFloat64(-32768.5) - let actual = Int(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat64(-32768.5)_AlwaysFails") { - let input = getFloat64(-32768.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat64(-128.5)_NeverTraps") { - let input = getFloat64(-128.5) - let actual = Int(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat64(-128.5)_AlwaysFails") { - let input = getFloat64(-128.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat64(-0.5)_NeverTraps") { - let input = getFloat64(-0.5) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat64(-0.5)_AlwaysFails") { - let input = getFloat64(-0.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat64(-0.0)_NeverTraps") { - let input = getFloat64(-0.0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat64(-0.0)_NeverFails") { - let input = getFloat64(-0.0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat64(0.0)_NeverTraps") { - let input = getFloat64(0.0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat64(0.0)_NeverFails") { - let input = getFloat64(0.0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat64(0.5)_NeverTraps") { - let input = getFloat64(0.5) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat64(0.5)_AlwaysFails") { - let input = getFloat64(0.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat64(127.5)_NeverTraps") { - let input = getFloat64(127.5) - let actual = Int(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat64(127.5)_AlwaysFails") { - let input = getFloat64(127.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat64(255.5)_NeverTraps") { - let input = getFloat64(255.5) - let actual = Int(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat64(255.5)_AlwaysFails") { - let input = getFloat64(255.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat64(32767.5)_NeverTraps") { - let input = getFloat64(32767.5) - let actual = Int(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat64(32767.5)_AlwaysFails") { - let input = getFloat64(32767.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat64(65535.5)_NeverTraps") { - let input = getFloat64(65535.5) - let actual = Int(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat64(65535.5)_AlwaysFails") { - let input = getFloat64(65535.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat64(9007199254740991)_NeverTraps") { - let input = getFloat64(9007199254740991) - let actual = Int(input) - expectEqual(9007199254740991, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat64(9007199254740991)_NeverFails") { - let input = getFloat64(9007199254740991) - let actual = Int(exactly: input) - expectEqual(9007199254740991, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat64(-.infinity)_AlwaysTraps") { - let input = getFloat64(-.infinity) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat64(-.infinity)_AlwaysFails") { - let input = getFloat64(-.infinity) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat64(+.infinity)_AlwaysTraps") { - let input = getFloat64(+.infinity) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat64(+.infinity)_AlwaysFails") { - let input = getFloat64(+.infinity) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat64(-.nan)_AlwaysTraps") { - let input = getFloat64(-.nan) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat64(-.nan)_AlwaysFails") { - let input = getFloat64(-.nan) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat64(+.nan)_AlwaysTraps") { - let input = getFloat64(+.nan) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat64(+.nan)_AlwaysFails") { - let input = getFloat64(+.nan) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat64(-.signalingNaN)_AlwaysTraps") { - let input = getFloat64(-.signalingNaN) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat64(-.signalingNaN)_AlwaysFails") { - let input = getFloat64(-.signalingNaN) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat64(+.signalingNaN)_AlwaysTraps") { - let input = getFloat64(+.signalingNaN) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat64(+.signalingNaN)_AlwaysFails") { - let input = getFloat64(+.signalingNaN) - let actual = Int(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt +.test("FromFloat64_NeverTraps") +.forEach(in: [ + (getInt(-9007199254740991), getFloat64(-9007199254740991)), + (getInt(-32768), getFloat64(-32768.5)), + (getInt(-128), getFloat64(-128.5)), + (getInt(+0), getFloat64(-0.5)), + (getInt(+0), getFloat64(+0)), + (getInt(+0), getFloat64(-0)), + (getInt(+0), getFloat64(+0.5)), + (getInt(+127), getFloat64(+127.5)), + (getInt(+255), getFloat64(+255.5)), + (getInt(+32767), getFloat64(+32767.5)), + (getInt(+65535), getFloat64(+65535.5)), + (getInt(+9007199254740991), getFloat64(+9007199254740991)), +]) { + expectEqual($0.0, Int($0.1)) +} + +FixedPointConversion_Debug64_ToInt +.test("FromFloat64_NeverFails") +.forEach(in: [ + (getInt(-9007199254740991), getFloat64(-9007199254740991)), + (getInt(+0), getFloat64(+0)), + (getInt(+0), getFloat64(-0)), + (getInt(+9007199254740991), getFloat64(+9007199254740991)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToInt +.test("FromFloat64_AlwaysTraps") +.forEach(in: [ + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int($0)) +} + +FixedPointConversion_Debug64_ToInt +.test("FromFloat64_AlwaysFails") +.forEach(in: [ + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-0.5), + getFloat64(+0.5), + getFloat64(+127.5), + getFloat64(+255.5), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectNil(Int(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float80: (-18446744073709551615)...(18446744073709551615) +// MARK: Float80: (-18446744073709551615)...(+18446744073709551615) //===----------------------------------------------------------------------===// #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) -FixedPointConversion_Debug64_ToInt.test("FromFloat80(-18446744073709551615)_AlwaysTraps") { - let input = getFloat80(-18446744073709551615) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(-18446744073709551615)_AlwaysFails") { - let input = getFloat80(-18446744073709551615) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(-9223372036854775809)_AlwaysTraps") { - let input = getFloat80(-9223372036854775809) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(-9223372036854775809)_AlwaysFails") { - let input = getFloat80(-9223372036854775809) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(-9223372036854775808)_NeverTraps") { - let input = getFloat80(-9223372036854775808) - let actual = Int(input) - expectEqual(-9223372036854775808, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(-9223372036854775808)_NeverFails") { - let input = getFloat80(-9223372036854775808) - let actual = Int(exactly: input) - expectEqual(-9223372036854775808, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(-32768.5)_NeverTraps") { - let input = getFloat80(-32768.5) - let actual = Int(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(-32768.5)_AlwaysFails") { - let input = getFloat80(-32768.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(-128.5)_NeverTraps") { - let input = getFloat80(-128.5) - let actual = Int(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(-128.5)_AlwaysFails") { - let input = getFloat80(-128.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(-0.5)_NeverTraps") { - let input = getFloat80(-0.5) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(-0.5)_AlwaysFails") { - let input = getFloat80(-0.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(-0.0)_NeverTraps") { - let input = getFloat80(-0.0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(-0.0)_NeverFails") { - let input = getFloat80(-0.0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(0.0)_NeverTraps") { - let input = getFloat80(0.0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(0.0)_NeverFails") { - let input = getFloat80(0.0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(0.5)_NeverTraps") { - let input = getFloat80(0.5) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(0.5)_AlwaysFails") { - let input = getFloat80(0.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(127.5)_NeverTraps") { - let input = getFloat80(127.5) - let actual = Int(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(127.5)_AlwaysFails") { - let input = getFloat80(127.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(255.5)_NeverTraps") { - let input = getFloat80(255.5) - let actual = Int(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(255.5)_AlwaysFails") { - let input = getFloat80(255.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(32767.5)_NeverTraps") { - let input = getFloat80(32767.5) - let actual = Int(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(32767.5)_AlwaysFails") { - let input = getFloat80(32767.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(65535.5)_NeverTraps") { - let input = getFloat80(65535.5) - let actual = Int(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(65535.5)_AlwaysFails") { - let input = getFloat80(65535.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(9223372036854775807)_NeverTraps") { - let input = getFloat80(9223372036854775807) - let actual = Int(input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(9223372036854775807)_NeverFails") { - let input = getFloat80(9223372036854775807) - let actual = Int(exactly: input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(9223372036854775808)_AlwaysTraps") { - let input = getFloat80(9223372036854775808) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(9223372036854775808)_AlwaysFails") { - let input = getFloat80(9223372036854775808) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(18446744073709551615)_AlwaysTraps") { - let input = getFloat80(18446744073709551615) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(18446744073709551615)_AlwaysFails") { - let input = getFloat80(18446744073709551615) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(-.infinity)_AlwaysTraps") { - let input = getFloat80(-.infinity) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(-.infinity)_AlwaysFails") { - let input = getFloat80(-.infinity) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(+.infinity)_AlwaysTraps") { - let input = getFloat80(+.infinity) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(+.infinity)_AlwaysFails") { - let input = getFloat80(+.infinity) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(-.nan)_AlwaysTraps") { - let input = getFloat80(-.nan) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(-.nan)_AlwaysFails") { - let input = getFloat80(-.nan) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(+.nan)_AlwaysTraps") { - let input = getFloat80(+.nan) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(+.nan)_AlwaysFails") { - let input = getFloat80(+.nan) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(-.signalingNaN)_AlwaysTraps") { - let input = getFloat80(-.signalingNaN) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(-.signalingNaN)_AlwaysFails") { - let input = getFloat80(-.signalingNaN) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(+.signalingNaN)_AlwaysTraps") { - let input = getFloat80(+.signalingNaN) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt.test("FromFloat80(+.signalingNaN)_AlwaysFails") { - let input = getFloat80(+.signalingNaN) - let actual = Int(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt +.test("FromFloat80_NeverTraps") +.forEach(in: [ + (getInt(-9223372036854775808), getFloat80(-9223372036854775808)), + (getInt(-32768), getFloat80(-32768.5)), + (getInt(-128), getFloat80(-128.5)), + (getInt(+0), getFloat80(-0.5)), + (getInt(+0), getFloat80(-0)), + (getInt(+0), getFloat80(+0)), + (getInt(+0), getFloat80(+0.5)), + (getInt(+127), getFloat80(+127.5)), + (getInt(+255), getFloat80(+255.5)), + (getInt(+32767), getFloat80(+32767.5)), + (getInt(+65535), getFloat80(+65535.5)), + (getInt(+9223372036854775807), getFloat80(+9223372036854775807)), +]) { + expectEqual($0.0, Int($0.1)) +} + +FixedPointConversion_Debug64_ToInt +.test("FromFloat80_NeverFails") +.forEach(in: [ + (getInt(-9223372036854775808), getFloat80(-9223372036854775808)), + (getInt(+0), getFloat80(-0)), + (getInt(+0), getFloat80(+0)), + (getInt(+9223372036854775807), getFloat80(+9223372036854775807)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToInt +.test("FromFloat80_AlwaysTraps") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-9223372036854775809), + getFloat80(+9223372036854775808), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int($0)) +} + +FixedPointConversion_Debug64_ToInt +.test("FromFloat80_AlwaysFails") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-9223372036854775809), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-0.5), + getFloat80(+0.5), + getFloat80(+127.5), + getFloat80(+255.5), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(+9223372036854775808), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectNil(Int(exactly: $0)) } #endif // Float80 diff --git a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug64_ToInt16.swift b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug64_ToInt16.swift index f3e2d80ab005f..cc6f0afafd959 100644 --- a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug64_ToInt16.swift +++ b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug64_ToInt16.swift @@ -14,1700 +14,685 @@ import StdlibUnittest -let FixedPointConversion_Debug64_ToInt16 = TestSuite("FixedPointConversion_Debug64_ToInt16") +let FixedPointConversion_Debug64_ToInt16 = TestSuite( + "FixedPointConversion_Debug64_ToInt16" +) //===----------------------------------------------------------------------===// -// MARK: UInt8: (0)...(255) +// MARK: UInt8: (+0)...(+255) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt16.test("FromUInt8(0)_NeverTraps") { - let input = getUInt8(0) - let actual = Int16(input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToInt16 +.test("FromUInt8_NeverTraps") +.forEach(in: [ + (getInt16(+0), getUInt8(+0)), + (getInt16(+255), getUInt8(+255)), +]) { + expectEqual($0.0, Int16($0.1)) } -FixedPointConversion_Debug64_ToInt16.test("FromUInt8(0)_NeverFails") { - let input = getUInt8(0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromUInt8(255)_NeverTraps") { - let input = getUInt8(255) - let actual = Int16(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromUInt8(255)_NeverFails") { - let input = getUInt8(255) - let actual = Int16(exactly: input) - expectEqual(255, actual) +FixedPointConversion_Debug64_ToInt16 +.test("FromUInt8_NeverFails") +.forEach(in: [ + (getInt16(+0), getUInt8(+0)), + (getInt16(+255), getUInt8(+255)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int8: (-128)...(127) +// MARK: Int8: (-128)...(+127) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt16.test("FromInt8(-128)_NeverTraps") { - let input = getInt8(-128) - let actual = Int16(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt8(-128)_NeverFails") { - let input = getInt8(-128) - let actual = Int16(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt8(0)_NeverTraps") { - let input = getInt8(0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt8(0)_NeverFails") { - let input = getInt8(0) - let actual = Int16(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToInt16 +.test("FromInt8_NeverTraps") +.forEach(in: [ + (getInt16(-128), getInt8(-128)), + (getInt16(+0), getInt8(+0)), + (getInt16(+127), getInt8(+127)), +]) { + expectEqual($0.0, Int16($0.1)) } -FixedPointConversion_Debug64_ToInt16.test("FromInt8(127)_NeverTraps") { - let input = getInt8(127) - let actual = Int16(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt8(127)_NeverFails") { - let input = getInt8(127) - let actual = Int16(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Debug64_ToInt16 +.test("FromInt8_NeverFails") +.forEach(in: [ + (getInt16(-128), getInt8(-128)), + (getInt16(+0), getInt8(+0)), + (getInt16(+127), getInt8(+127)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt16: (0)...(65535) +// MARK: UInt16: (+0)...(+65535) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt16.test("FromUInt16(0)_NeverTraps") { - let input = getUInt16(0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromUInt16(0)_NeverFails") { - let input = getUInt16(0) - let actual = Int16(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToInt16 +.test("FromUInt16_NeverTraps") +.forEach(in: [ + (getInt16(+0), getUInt16(+0)), + (getInt16(+32767), getUInt16(+32767)), +]) { + expectEqual($0.0, Int16($0.1)) } -FixedPointConversion_Debug64_ToInt16.test("FromUInt16(32767)_NeverTraps") { - let input = getUInt16(32767) - let actual = Int16(input) - expectEqual(32767, actual) +FixedPointConversion_Debug64_ToInt16 +.test("FromUInt16_NeverFails") +.forEach(in: [ + (getInt16(+0), getUInt16(+0)), + (getInt16(+32767), getUInt16(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) } -FixedPointConversion_Debug64_ToInt16.test("FromUInt16(32767)_NeverFails") { - let input = getUInt16(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) +FixedPointConversion_Debug64_ToInt16 +.test("FromUInt16_AlwaysTraps") +.forEach(in: [ + getUInt16(+32768), + getUInt16(+65535), +]) { + expectCrashLater() + _blackHole(Int16($0)) } -FixedPointConversion_Debug64_ToInt16.test("FromUInt16(32768)_AlwaysTraps") { - let input = getUInt16(32768) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromUInt16(32768)_AlwaysFails") { - let input = getUInt16(32768) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromUInt16(65535)_AlwaysTraps") { - let input = getUInt16(65535) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromUInt16(65535)_AlwaysFails") { - let input = getUInt16(65535) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt16 +.test("FromUInt16_AlwaysFails") +.forEach(in: [ + getUInt16(+32768), + getUInt16(+65535), +]) { + expectNil(Int16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int16: (-32768)...(32767) +// MARK: Int16: (-32768)...(+32767) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt16.test("FromInt16(-32768)_NeverTraps") { - let input = getInt16(-32768) - let actual = Int16(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt16(-32768)_NeverFails") { - let input = getInt16(-32768) - let actual = Int16(exactly: input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt16(0)_NeverTraps") { - let input = getInt16(0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt16(0)_NeverFails") { - let input = getInt16(0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt16(32767)_NeverTraps") { - let input = getInt16(32767) - let actual = Int16(input) - expectEqual(32767, actual) +FixedPointConversion_Debug64_ToInt16 +.test("FromInt16_NeverTraps") +.forEach(in: [ + (getInt16(-32768), getInt16(-32768)), + (getInt16(+0), getInt16(+0)), + (getInt16(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, Int16($0.1)) } -FixedPointConversion_Debug64_ToInt16.test("FromInt16(32767)_NeverFails") { - let input = getInt16(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) +FixedPointConversion_Debug64_ToInt16 +.test("FromInt16_NeverFails") +.forEach(in: [ + (getInt16(-32768), getInt16(-32768)), + (getInt16(+0), getInt16(+0)), + (getInt16(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt32: (0)...(4294967295) +// MARK: UInt32: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt16.test("FromUInt32(0)_NeverTraps") { - let input = getUInt32(0) - let actual = Int16(input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToInt16 +.test("FromUInt32_NeverTraps") +.forEach(in: [ + (getInt16(+0), getUInt32(+0)), + (getInt16(+32767), getUInt32(+32767)), +]) { + expectEqual($0.0, Int16($0.1)) } -FixedPointConversion_Debug64_ToInt16.test("FromUInt32(0)_NeverFails") { - let input = getUInt32(0) - let actual = Int16(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToInt16 +.test("FromUInt32_NeverFails") +.forEach(in: [ + (getInt16(+0), getUInt32(+0)), + (getInt16(+32767), getUInt32(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) } -FixedPointConversion_Debug64_ToInt16.test("FromUInt32(32767)_NeverTraps") { - let input = getUInt32(32767) - let actual = Int16(input) - expectEqual(32767, actual) +FixedPointConversion_Debug64_ToInt16 +.test("FromUInt32_AlwaysTraps") +.forEach(in: [ + getUInt32(+32768), + getUInt32(+4294967295), +]) { + expectCrashLater() + _blackHole(Int16($0)) } -FixedPointConversion_Debug64_ToInt16.test("FromUInt32(32767)_NeverFails") { - let input = getUInt32(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromUInt32(32768)_AlwaysTraps") { - let input = getUInt32(32768) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromUInt32(32768)_AlwaysFails") { - let input = getUInt32(32768) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromUInt32(4294967295)_AlwaysTraps") { - let input = getUInt32(4294967295) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromUInt32(4294967295)_AlwaysFails") { - let input = getUInt32(4294967295) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt16 +.test("FromUInt32_AlwaysFails") +.forEach(in: [ + getUInt32(+32768), + getUInt32(+4294967295), +]) { + expectNil(Int16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int32: (-2147483648)...(2147483647) +// MARK: Int32: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt16.test("FromInt32(-2147483648)_AlwaysTraps") { - let input = getInt32(-2147483648) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt32(-2147483648)_AlwaysFails") { - let input = getInt32(-2147483648) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt32(-32769)_AlwaysTraps") { - let input = getInt32(-32769) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt32(-32769)_AlwaysFails") { - let input = getInt32(-32769) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt32(-32768)_NeverTraps") { - let input = getInt32(-32768) - let actual = Int16(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt32(-32768)_NeverFails") { - let input = getInt32(-32768) - let actual = Int16(exactly: input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt32(0)_NeverTraps") { - let input = getInt32(0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt32(0)_NeverFails") { - let input = getInt32(0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt32(32767)_NeverTraps") { - let input = getInt32(32767) - let actual = Int16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt32(32767)_NeverFails") { - let input = getInt32(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt32(32768)_AlwaysTraps") { - let input = getInt32(32768) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt32(32768)_AlwaysFails") { - let input = getInt32(32768) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt32(2147483647)_AlwaysTraps") { - let input = getInt32(2147483647) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt32(2147483647)_AlwaysFails") { - let input = getInt32(2147483647) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt16 +.test("FromInt32_NeverTraps") +.forEach(in: [ + (getInt16(-32768), getInt32(-32768)), + (getInt16(+0), getInt32(+0)), + (getInt16(+32767), getInt32(+32767)), +]) { + expectEqual($0.0, Int16($0.1)) +} + +FixedPointConversion_Debug64_ToInt16 +.test("FromInt32_NeverFails") +.forEach(in: [ + (getInt16(-32768), getInt32(-32768)), + (getInt16(+0), getInt32(+0)), + (getInt16(+32767), getInt32(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToInt16 +.test("FromInt32_AlwaysTraps") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-32769), + getInt32(+32768), + getInt32(+2147483647), +]) { + expectCrashLater() + _blackHole(Int16($0)) +} + +FixedPointConversion_Debug64_ToInt16 +.test("FromInt32_AlwaysFails") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-32769), + getInt32(+32768), + getInt32(+2147483647), +]) { + expectNil(Int16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt64: (0)...(18446744073709551615) +// MARK: UInt64: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt16.test("FromUInt64(0)_NeverTraps") { - let input = getUInt64(0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromUInt64(0)_NeverFails") { - let input = getUInt64(0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromUInt64(32767)_NeverTraps") { - let input = getUInt64(32767) - let actual = Int16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromUInt64(32767)_NeverFails") { - let input = getUInt64(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromUInt64(32768)_AlwaysTraps") { - let input = getUInt64(32768) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } +FixedPointConversion_Debug64_ToInt16 +.test("FromUInt64_NeverTraps") +.forEach(in: [ + (getInt16(+0), getUInt64(+0)), + (getInt16(+32767), getUInt64(+32767)), +]) { + expectEqual($0.0, Int16($0.1)) } -FixedPointConversion_Debug64_ToInt16.test("FromUInt64(32768)_AlwaysFails") { - let input = getUInt64(32768) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt16 +.test("FromUInt64_NeverFails") +.forEach(in: [ + (getInt16(+0), getUInt64(+0)), + (getInt16(+32767), getUInt64(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) } -FixedPointConversion_Debug64_ToInt16.test("FromUInt64(18446744073709551615)_AlwaysTraps") { - let input = getUInt64(18446744073709551615) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } +FixedPointConversion_Debug64_ToInt16 +.test("FromUInt64_AlwaysTraps") +.forEach(in: [ + getUInt64(+32768), + getUInt64(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(Int16($0)) } -FixedPointConversion_Debug64_ToInt16.test("FromUInt64(18446744073709551615)_AlwaysFails") { - let input = getUInt64(18446744073709551615) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt16 +.test("FromUInt64_AlwaysFails") +.forEach(in: [ + getUInt64(+32768), + getUInt64(+18446744073709551615), +]) { + expectNil(Int16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int64: (-9223372036854775808)...(9223372036854775807) +// MARK: Int64: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt16.test("FromInt64(-9223372036854775808)_AlwaysTraps") { - let input = getInt64(-9223372036854775808) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt64(-9223372036854775808)_AlwaysFails") { - let input = getInt64(-9223372036854775808) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt64(-32769)_AlwaysTraps") { - let input = getInt64(-32769) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt64(-32769)_AlwaysFails") { - let input = getInt64(-32769) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt64(-32768)_NeverTraps") { - let input = getInt64(-32768) - let actual = Int16(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt64(-32768)_NeverFails") { - let input = getInt64(-32768) - let actual = Int16(exactly: input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt64(0)_NeverTraps") { - let input = getInt64(0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt64(0)_NeverFails") { - let input = getInt64(0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt64(32767)_NeverTraps") { - let input = getInt64(32767) - let actual = Int16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt64(32767)_NeverFails") { - let input = getInt64(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt64(32768)_AlwaysTraps") { - let input = getInt64(32768) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt64(32768)_AlwaysFails") { - let input = getInt64(32768) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt64(9223372036854775807)_AlwaysTraps") { - let input = getInt64(9223372036854775807) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt64(9223372036854775807)_AlwaysFails") { - let input = getInt64(9223372036854775807) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt16 +.test("FromInt64_NeverTraps") +.forEach(in: [ + (getInt16(-32768), getInt64(-32768)), + (getInt16(+0), getInt64(+0)), + (getInt16(+32767), getInt64(+32767)), +]) { + expectEqual($0.0, Int16($0.1)) +} + +FixedPointConversion_Debug64_ToInt16 +.test("FromInt64_NeverFails") +.forEach(in: [ + (getInt16(-32768), getInt64(-32768)), + (getInt16(+0), getInt64(+0)), + (getInt16(+32767), getInt64(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToInt16 +.test("FromInt64_AlwaysTraps") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-32769), + getInt64(+32768), + getInt64(+9223372036854775807), +]) { + expectCrashLater() + _blackHole(Int16($0)) +} + +FixedPointConversion_Debug64_ToInt16 +.test("FromInt64_AlwaysFails") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-32769), + getInt64(+32768), + getInt64(+9223372036854775807), +]) { + expectNil(Int16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt: (0)...(18446744073709551615) +// MARK: UInt: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt16.test("FromUInt(0)_NeverTraps") { - let input = getUInt(0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromUInt(0)_NeverFails") { - let input = getUInt(0) - let actual = Int16(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToInt16 +.test("FromUInt_NeverTraps") +.forEach(in: [ + (getInt16(+0), getUInt(+0)), + (getInt16(+32767), getUInt(+32767)), +]) { + expectEqual($0.0, Int16($0.1)) } -FixedPointConversion_Debug64_ToInt16.test("FromUInt(32767)_NeverTraps") { - let input = getUInt(32767) - let actual = Int16(input) - expectEqual(32767, actual) +FixedPointConversion_Debug64_ToInt16 +.test("FromUInt_NeverFails") +.forEach(in: [ + (getInt16(+0), getUInt(+0)), + (getInt16(+32767), getUInt(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) } -FixedPointConversion_Debug64_ToInt16.test("FromUInt(32767)_NeverFails") { - let input = getUInt(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) +FixedPointConversion_Debug64_ToInt16 +.test("FromUInt_AlwaysTraps") +.forEach(in: [ + getUInt(+32768), + getUInt(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(Int16($0)) } -FixedPointConversion_Debug64_ToInt16.test("FromUInt(32768)_AlwaysTraps") { - let input = getUInt(32768) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromUInt(32768)_AlwaysFails") { - let input = getUInt(32768) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromUInt(18446744073709551615)_AlwaysTraps") { - let input = getUInt(18446744073709551615) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromUInt(18446744073709551615)_AlwaysFails") { - let input = getUInt(18446744073709551615) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt16 +.test("FromUInt_AlwaysFails") +.forEach(in: [ + getUInt(+32768), + getUInt(+18446744073709551615), +]) { + expectNil(Int16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int: (-9223372036854775808)...(9223372036854775807) +// MARK: Int: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt16.test("FromInt(-9223372036854775808)_AlwaysTraps") { - let input = getInt(-9223372036854775808) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt(-9223372036854775808)_AlwaysFails") { - let input = getInt(-9223372036854775808) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt(-32769)_AlwaysTraps") { - let input = getInt(-32769) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt(-32769)_AlwaysFails") { - let input = getInt(-32769) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt(-32768)_NeverTraps") { - let input = getInt(-32768) - let actual = Int16(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt(-32768)_NeverFails") { - let input = getInt(-32768) - let actual = Int16(exactly: input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt(0)_NeverTraps") { - let input = getInt(0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt(0)_NeverFails") { - let input = getInt(0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt(32767)_NeverTraps") { - let input = getInt(32767) - let actual = Int16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt(32767)_NeverFails") { - let input = getInt(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt(32768)_AlwaysTraps") { - let input = getInt(32768) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt(32768)_AlwaysFails") { - let input = getInt(32768) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt(9223372036854775807)_AlwaysTraps") { - let input = getInt(9223372036854775807) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromInt(9223372036854775807)_AlwaysFails") { - let input = getInt(9223372036854775807) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt16 +.test("FromInt_NeverTraps") +.forEach(in: [ + (getInt16(-32768), getInt(-32768)), + (getInt16(+0), getInt(+0)), + (getInt16(+32767), getInt(+32767)), +]) { + expectEqual($0.0, Int16($0.1)) +} + +FixedPointConversion_Debug64_ToInt16 +.test("FromInt_NeverFails") +.forEach(in: [ + (getInt16(-32768), getInt(-32768)), + (getInt16(+0), getInt(+0)), + (getInt16(+32767), getInt(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToInt16 +.test("FromInt_AlwaysTraps") +.forEach(in: [ + getInt(-9223372036854775808), + getInt(-32769), + getInt(+32768), + getInt(+9223372036854775807), +]) { + expectCrashLater() + _blackHole(Int16($0)) +} + +FixedPointConversion_Debug64_ToInt16 +.test("FromInt_AlwaysFails") +.forEach(in: [ + getInt(-9223372036854775808), + getInt(-32769), + getInt(+32768), + getInt(+9223372036854775807), +]) { + expectNil(Int16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float16: (-2047)...(2047) +// MARK: Float16: (-2047)...(+2047) //===----------------------------------------------------------------------===// #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -FixedPointConversion_Debug64_ToInt16.test("FromFloat16(-2047)_NeverTraps") { - let input = getFloat16(-2047) - let actual = Int16(input) - expectEqual(-2047, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat16(-2047)_NeverFails") { - let input = getFloat16(-2047) - let actual = Int16(exactly: input) - expectEqual(-2047, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat16(-128.5)_NeverTraps") { - let input = getFloat16(-128.5) - let actual = Int16(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat16(-128.5)_AlwaysFails") { - let input = getFloat16(-128.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat16(-0.5)_NeverTraps") { - let input = getFloat16(-0.5) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat16(-0.5)_AlwaysFails") { - let input = getFloat16(-0.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat16(-0.0)_NeverTraps") { - let input = getFloat16(-0.0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat16(-0.0)_NeverFails") { - let input = getFloat16(-0.0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat16(0.0)_NeverTraps") { - let input = getFloat16(0.0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat16(0.0)_NeverFails") { - let input = getFloat16(0.0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat16(0.5)_NeverTraps") { - let input = getFloat16(0.5) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat16(0.5)_AlwaysFails") { - let input = getFloat16(0.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat16(127.5)_NeverTraps") { - let input = getFloat16(127.5) - let actual = Int16(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat16(127.5)_AlwaysFails") { - let input = getFloat16(127.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat16(255.5)_NeverTraps") { - let input = getFloat16(255.5) - let actual = Int16(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat16(255.5)_AlwaysFails") { - let input = getFloat16(255.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat16(2047)_NeverTraps") { - let input = getFloat16(2047) - let actual = Int16(input) - expectEqual(2047, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat16(2047)_NeverFails") { - let input = getFloat16(2047) - let actual = Int16(exactly: input) - expectEqual(2047, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat16(-.infinity)_AlwaysTraps") { - let input = getFloat16(-.infinity) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat16(-.infinity)_AlwaysFails") { - let input = getFloat16(-.infinity) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat16(+.infinity)_AlwaysTraps") { - let input = getFloat16(+.infinity) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat16(+.infinity)_AlwaysFails") { - let input = getFloat16(+.infinity) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat16(-.nan)_AlwaysTraps") { - let input = getFloat16(-.nan) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat16(-.nan)_AlwaysFails") { - let input = getFloat16(-.nan) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat16(+.nan)_AlwaysTraps") { - let input = getFloat16(+.nan) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat16(+.nan)_AlwaysFails") { - let input = getFloat16(+.nan) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat16(-.signalingNaN)_AlwaysTraps") { - let input = getFloat16(-.signalingNaN) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat16(-.signalingNaN)_AlwaysFails") { - let input = getFloat16(-.signalingNaN) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat16(+.signalingNaN)_AlwaysTraps") { - let input = getFloat16(+.signalingNaN) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat16(+.signalingNaN)_AlwaysFails") { - let input = getFloat16(+.signalingNaN) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt16 +.test("FromFloat16_NeverTraps") +.forEach(in: [ + (getInt16(-2047), getFloat16(-2047)), + (getInt16(-128), getFloat16(-128.5)), + (getInt16(+0), getFloat16(-0.5)), + (getInt16(+0), getFloat16(+0)), + (getInt16(+0), getFloat16(-0)), + (getInt16(+0), getFloat16(+0.5)), + (getInt16(+127), getFloat16(+127.5)), + (getInt16(+255), getFloat16(+255.5)), + (getInt16(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, Int16($0.1)) +} + +FixedPointConversion_Debug64_ToInt16 +.test("FromFloat16_NeverFails") +.forEach(in: [ + (getInt16(-2047), getFloat16(-2047)), + (getInt16(+0), getFloat16(+0)), + (getInt16(+0), getFloat16(-0)), + (getInt16(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToInt16 +.test("FromFloat16_AlwaysTraps") +.forEach(in: [ + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int16($0)) +} + +FixedPointConversion_Debug64_ToInt16 +.test("FromFloat16_AlwaysFails") +.forEach(in: [ + getFloat16(-128.5), + getFloat16(-0.5), + getFloat16(+0.5), + getFloat16(+127.5), + getFloat16(+255.5), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectNil(Int16(exactly: $0)) } } #endif // Float16 //===----------------------------------------------------------------------===// -// MARK: Float32: (-16777215)...(16777215) +// MARK: Float32: (-16777215)...(+16777215) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(-16777215)_AlwaysTraps") { - let input = getFloat32(-16777215) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(-16777215)_AlwaysFails") { - let input = getFloat32(-16777215) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(-32769)_AlwaysTraps") { - let input = getFloat32(-32769) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(-32769)_AlwaysFails") { - let input = getFloat32(-32769) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(-32768.5)_NeverTraps") { - let input = getFloat32(-32768.5) - let actual = Int16(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(-32768.5)_AlwaysFails") { - let input = getFloat32(-32768.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(-32768)_NeverTraps") { - let input = getFloat32(-32768) - let actual = Int16(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(-32768)_NeverFails") { - let input = getFloat32(-32768) - let actual = Int16(exactly: input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(-128.5)_NeverTraps") { - let input = getFloat32(-128.5) - let actual = Int16(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(-128.5)_AlwaysFails") { - let input = getFloat32(-128.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(-0.5)_NeverTraps") { - let input = getFloat32(-0.5) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(-0.5)_AlwaysFails") { - let input = getFloat32(-0.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(-0.0)_NeverTraps") { - let input = getFloat32(-0.0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(-0.0)_NeverFails") { - let input = getFloat32(-0.0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(0.0)_NeverTraps") { - let input = getFloat32(0.0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(0.0)_NeverFails") { - let input = getFloat32(0.0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(0.5)_NeverTraps") { - let input = getFloat32(0.5) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(0.5)_AlwaysFails") { - let input = getFloat32(0.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(127.5)_NeverTraps") { - let input = getFloat32(127.5) - let actual = Int16(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(127.5)_AlwaysFails") { - let input = getFloat32(127.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(255.5)_NeverTraps") { - let input = getFloat32(255.5) - let actual = Int16(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(255.5)_AlwaysFails") { - let input = getFloat32(255.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(32767)_NeverTraps") { - let input = getFloat32(32767) - let actual = Int16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(32767)_NeverFails") { - let input = getFloat32(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(32767.5)_NeverTraps") { - let input = getFloat32(32767.5) - let actual = Int16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(32767.5)_AlwaysFails") { - let input = getFloat32(32767.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(32768)_AlwaysTraps") { - let input = getFloat32(32768) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(32768)_AlwaysFails") { - let input = getFloat32(32768) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(65535.5)_AlwaysTraps") { - let input = getFloat32(65535.5) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(65535.5)_AlwaysFails") { - let input = getFloat32(65535.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(16777215)_AlwaysTraps") { - let input = getFloat32(16777215) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(16777215)_AlwaysFails") { - let input = getFloat32(16777215) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(-.infinity)_AlwaysTraps") { - let input = getFloat32(-.infinity) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(-.infinity)_AlwaysFails") { - let input = getFloat32(-.infinity) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(+.infinity)_AlwaysTraps") { - let input = getFloat32(+.infinity) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(+.infinity)_AlwaysFails") { - let input = getFloat32(+.infinity) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(-.nan)_AlwaysTraps") { - let input = getFloat32(-.nan) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(-.nan)_AlwaysFails") { - let input = getFloat32(-.nan) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(+.nan)_AlwaysTraps") { - let input = getFloat32(+.nan) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(+.nan)_AlwaysFails") { - let input = getFloat32(+.nan) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(-.signalingNaN)_AlwaysTraps") { - let input = getFloat32(-.signalingNaN) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(-.signalingNaN)_AlwaysFails") { - let input = getFloat32(-.signalingNaN) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(+.signalingNaN)_AlwaysTraps") { - let input = getFloat32(+.signalingNaN) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat32(+.signalingNaN)_AlwaysFails") { - let input = getFloat32(+.signalingNaN) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt16 +.test("FromFloat32_NeverTraps") +.forEach(in: [ + (getInt16(-32768), getFloat32(-32768.5)), + (getInt16(-32768), getFloat32(-32768)), + (getInt16(-128), getFloat32(-128.5)), + (getInt16(+0), getFloat32(-0.5)), + (getInt16(+0), getFloat32(+0)), + (getInt16(+0), getFloat32(-0)), + (getInt16(+0), getFloat32(+0.5)), + (getInt16(+127), getFloat32(+127.5)), + (getInt16(+255), getFloat32(+255.5)), + (getInt16(+32767), getFloat32(+32767)), + (getInt16(+32767), getFloat32(+32767.5)), +]) { + expectEqual($0.0, Int16($0.1)) +} + +FixedPointConversion_Debug64_ToInt16 +.test("FromFloat32_NeverFails") +.forEach(in: [ + (getInt16(-32768), getFloat32(-32768)), + (getInt16(+0), getFloat32(+0)), + (getInt16(+0), getFloat32(-0)), + (getInt16(+32767), getFloat32(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToInt16 +.test("FromFloat32_AlwaysTraps") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32769), + getFloat32(+32768), + getFloat32(+65535.5), + getFloat32(+16777215), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int16($0)) +} + +FixedPointConversion_Debug64_ToInt16 +.test("FromFloat32_AlwaysFails") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32769), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-0.5), + getFloat32(+0.5), + getFloat32(+127.5), + getFloat32(+255.5), + getFloat32(+32767.5), + getFloat32(+32768), + getFloat32(+65535.5), + getFloat32(+16777215), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectNil(Int16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float64: (-9007199254740991)...(9007199254740991) +// MARK: Float64: (-9007199254740991)...(+9007199254740991) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(-9007199254740991)_AlwaysTraps") { - let input = getFloat64(-9007199254740991) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(-9007199254740991)_AlwaysFails") { - let input = getFloat64(-9007199254740991) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(-32769)_AlwaysTraps") { - let input = getFloat64(-32769) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(-32769)_AlwaysFails") { - let input = getFloat64(-32769) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(-32768.5)_NeverTraps") { - let input = getFloat64(-32768.5) - let actual = Int16(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(-32768.5)_AlwaysFails") { - let input = getFloat64(-32768.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(-32768)_NeverTraps") { - let input = getFloat64(-32768) - let actual = Int16(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(-32768)_NeverFails") { - let input = getFloat64(-32768) - let actual = Int16(exactly: input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(-128.5)_NeverTraps") { - let input = getFloat64(-128.5) - let actual = Int16(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(-128.5)_AlwaysFails") { - let input = getFloat64(-128.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(-0.5)_NeverTraps") { - let input = getFloat64(-0.5) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(-0.5)_AlwaysFails") { - let input = getFloat64(-0.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(-0.0)_NeverTraps") { - let input = getFloat64(-0.0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(-0.0)_NeverFails") { - let input = getFloat64(-0.0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(0.0)_NeverTraps") { - let input = getFloat64(0.0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(0.0)_NeverFails") { - let input = getFloat64(0.0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(0.5)_NeverTraps") { - let input = getFloat64(0.5) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(0.5)_AlwaysFails") { - let input = getFloat64(0.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(127.5)_NeverTraps") { - let input = getFloat64(127.5) - let actual = Int16(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(127.5)_AlwaysFails") { - let input = getFloat64(127.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(255.5)_NeverTraps") { - let input = getFloat64(255.5) - let actual = Int16(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(255.5)_AlwaysFails") { - let input = getFloat64(255.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(32767)_NeverTraps") { - let input = getFloat64(32767) - let actual = Int16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(32767)_NeverFails") { - let input = getFloat64(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(32767.5)_NeverTraps") { - let input = getFloat64(32767.5) - let actual = Int16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(32767.5)_AlwaysFails") { - let input = getFloat64(32767.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(32768)_AlwaysTraps") { - let input = getFloat64(32768) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(32768)_AlwaysFails") { - let input = getFloat64(32768) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(65535.5)_AlwaysTraps") { - let input = getFloat64(65535.5) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(65535.5)_AlwaysFails") { - let input = getFloat64(65535.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(9007199254740991)_AlwaysTraps") { - let input = getFloat64(9007199254740991) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(9007199254740991)_AlwaysFails") { - let input = getFloat64(9007199254740991) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(-.infinity)_AlwaysTraps") { - let input = getFloat64(-.infinity) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(-.infinity)_AlwaysFails") { - let input = getFloat64(-.infinity) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(+.infinity)_AlwaysTraps") { - let input = getFloat64(+.infinity) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(+.infinity)_AlwaysFails") { - let input = getFloat64(+.infinity) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(-.nan)_AlwaysTraps") { - let input = getFloat64(-.nan) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(-.nan)_AlwaysFails") { - let input = getFloat64(-.nan) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(+.nan)_AlwaysTraps") { - let input = getFloat64(+.nan) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(+.nan)_AlwaysFails") { - let input = getFloat64(+.nan) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(-.signalingNaN)_AlwaysTraps") { - let input = getFloat64(-.signalingNaN) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(-.signalingNaN)_AlwaysFails") { - let input = getFloat64(-.signalingNaN) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(+.signalingNaN)_AlwaysTraps") { - let input = getFloat64(+.signalingNaN) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat64(+.signalingNaN)_AlwaysFails") { - let input = getFloat64(+.signalingNaN) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt16 +.test("FromFloat64_NeverTraps") +.forEach(in: [ + (getInt16(-32768), getFloat64(-32768.5)), + (getInt16(-32768), getFloat64(-32768)), + (getInt16(-128), getFloat64(-128.5)), + (getInt16(+0), getFloat64(-0.5)), + (getInt16(+0), getFloat64(+0)), + (getInt16(+0), getFloat64(-0)), + (getInt16(+0), getFloat64(+0.5)), + (getInt16(+127), getFloat64(+127.5)), + (getInt16(+255), getFloat64(+255.5)), + (getInt16(+32767), getFloat64(+32767)), + (getInt16(+32767), getFloat64(+32767.5)), +]) { + expectEqual($0.0, Int16($0.1)) +} + +FixedPointConversion_Debug64_ToInt16 +.test("FromFloat64_NeverFails") +.forEach(in: [ + (getInt16(-32768), getFloat64(-32768)), + (getInt16(+0), getFloat64(+0)), + (getInt16(+0), getFloat64(-0)), + (getInt16(+32767), getFloat64(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToInt16 +.test("FromFloat64_AlwaysTraps") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32769), + getFloat64(+32768), + getFloat64(+65535.5), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int16($0)) +} + +FixedPointConversion_Debug64_ToInt16 +.test("FromFloat64_AlwaysFails") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32769), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-0.5), + getFloat64(+0.5), + getFloat64(+127.5), + getFloat64(+255.5), + getFloat64(+32767.5), + getFloat64(+32768), + getFloat64(+65535.5), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectNil(Int16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float80: (-18446744073709551615)...(18446744073709551615) +// MARK: Float80: (-18446744073709551615)...(+18446744073709551615) //===----------------------------------------------------------------------===// #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(-18446744073709551615)_AlwaysTraps") { - let input = getFloat80(-18446744073709551615) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(-18446744073709551615)_AlwaysFails") { - let input = getFloat80(-18446744073709551615) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(-32769)_AlwaysTraps") { - let input = getFloat80(-32769) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(-32769)_AlwaysFails") { - let input = getFloat80(-32769) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(-32768.5)_NeverTraps") { - let input = getFloat80(-32768.5) - let actual = Int16(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(-32768.5)_AlwaysFails") { - let input = getFloat80(-32768.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(-32768)_NeverTraps") { - let input = getFloat80(-32768) - let actual = Int16(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(-32768)_NeverFails") { - let input = getFloat80(-32768) - let actual = Int16(exactly: input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(-128.5)_NeverTraps") { - let input = getFloat80(-128.5) - let actual = Int16(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(-128.5)_AlwaysFails") { - let input = getFloat80(-128.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(-0.5)_NeverTraps") { - let input = getFloat80(-0.5) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(-0.5)_AlwaysFails") { - let input = getFloat80(-0.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(-0.0)_NeverTraps") { - let input = getFloat80(-0.0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(-0.0)_NeverFails") { - let input = getFloat80(-0.0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(0.0)_NeverTraps") { - let input = getFloat80(0.0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(0.0)_NeverFails") { - let input = getFloat80(0.0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(0.5)_NeverTraps") { - let input = getFloat80(0.5) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(0.5)_AlwaysFails") { - let input = getFloat80(0.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(127.5)_NeverTraps") { - let input = getFloat80(127.5) - let actual = Int16(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(127.5)_AlwaysFails") { - let input = getFloat80(127.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(255.5)_NeverTraps") { - let input = getFloat80(255.5) - let actual = Int16(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(255.5)_AlwaysFails") { - let input = getFloat80(255.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(32767)_NeverTraps") { - let input = getFloat80(32767) - let actual = Int16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(32767)_NeverFails") { - let input = getFloat80(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(32767.5)_NeverTraps") { - let input = getFloat80(32767.5) - let actual = Int16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(32767.5)_AlwaysFails") { - let input = getFloat80(32767.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(32768)_AlwaysTraps") { - let input = getFloat80(32768) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(32768)_AlwaysFails") { - let input = getFloat80(32768) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(65535.5)_AlwaysTraps") { - let input = getFloat80(65535.5) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(65535.5)_AlwaysFails") { - let input = getFloat80(65535.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(18446744073709551615)_AlwaysTraps") { - let input = getFloat80(18446744073709551615) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(18446744073709551615)_AlwaysFails") { - let input = getFloat80(18446744073709551615) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(-.infinity)_AlwaysTraps") { - let input = getFloat80(-.infinity) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(-.infinity)_AlwaysFails") { - let input = getFloat80(-.infinity) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(+.infinity)_AlwaysTraps") { - let input = getFloat80(+.infinity) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(+.infinity)_AlwaysFails") { - let input = getFloat80(+.infinity) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(-.nan)_AlwaysTraps") { - let input = getFloat80(-.nan) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(-.nan)_AlwaysFails") { - let input = getFloat80(-.nan) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(+.nan)_AlwaysTraps") { - let input = getFloat80(+.nan) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(+.nan)_AlwaysFails") { - let input = getFloat80(+.nan) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(-.signalingNaN)_AlwaysTraps") { - let input = getFloat80(-.signalingNaN) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(-.signalingNaN)_AlwaysFails") { - let input = getFloat80(-.signalingNaN) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(+.signalingNaN)_AlwaysTraps") { - let input = getFloat80(+.signalingNaN) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt16.test("FromFloat80(+.signalingNaN)_AlwaysFails") { - let input = getFloat80(+.signalingNaN) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt16 +.test("FromFloat80_NeverTraps") +.forEach(in: [ + (getInt16(-32768), getFloat80(-32768.5)), + (getInt16(-32768), getFloat80(-32768)), + (getInt16(-128), getFloat80(-128.5)), + (getInt16(+0), getFloat80(-0.5)), + (getInt16(+0), getFloat80(+0)), + (getInt16(+0), getFloat80(-0)), + (getInt16(+0), getFloat80(+0.5)), + (getInt16(+127), getFloat80(+127.5)), + (getInt16(+255), getFloat80(+255.5)), + (getInt16(+32767), getFloat80(+32767)), + (getInt16(+32767), getFloat80(+32767.5)), +]) { + expectEqual($0.0, Int16($0.1)) +} + +FixedPointConversion_Debug64_ToInt16 +.test("FromFloat80_NeverFails") +.forEach(in: [ + (getInt16(-32768), getFloat80(-32768)), + (getInt16(+0), getFloat80(+0)), + (getInt16(+0), getFloat80(-0)), + (getInt16(+32767), getFloat80(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToInt16 +.test("FromFloat80_AlwaysTraps") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32769), + getFloat80(+32768), + getFloat80(+65535.5), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int16($0)) +} + +FixedPointConversion_Debug64_ToInt16 +.test("FromFloat80_AlwaysFails") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32769), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-0.5), + getFloat80(+0.5), + getFloat80(+127.5), + getFloat80(+255.5), + getFloat80(+32767.5), + getFloat80(+32768), + getFloat80(+65535.5), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectNil(Int16(exactly: $0)) } #endif // Float80 diff --git a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug64_ToInt32.swift b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug64_ToInt32.swift index 340157f433a14..fcde9e4064e71 100644 --- a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug64_ToInt32.swift +++ b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug64_ToInt32.swift @@ -14,1554 +14,635 @@ import StdlibUnittest -let FixedPointConversion_Debug64_ToInt32 = TestSuite("FixedPointConversion_Debug64_ToInt32") +let FixedPointConversion_Debug64_ToInt32 = TestSuite( + "FixedPointConversion_Debug64_ToInt32" +) //===----------------------------------------------------------------------===// -// MARK: UInt8: (0)...(255) +// MARK: UInt8: (+0)...(+255) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt32.test("FromUInt8(0)_NeverTraps") { - let input = getUInt8(0) - let actual = Int32(input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToInt32 +.test("FromUInt8_NeverTraps") +.forEach(in: [ + (getInt32(+0), getUInt8(+0)), + (getInt32(+255), getUInt8(+255)), +]) { + expectEqual($0.0, Int32($0.1)) } -FixedPointConversion_Debug64_ToInt32.test("FromUInt8(0)_NeverFails") { - let input = getUInt8(0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromUInt8(255)_NeverTraps") { - let input = getUInt8(255) - let actual = Int32(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromUInt8(255)_NeverFails") { - let input = getUInt8(255) - let actual = Int32(exactly: input) - expectEqual(255, actual) +FixedPointConversion_Debug64_ToInt32 +.test("FromUInt8_NeverFails") +.forEach(in: [ + (getInt32(+0), getUInt8(+0)), + (getInt32(+255), getUInt8(+255)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int8: (-128)...(127) +// MARK: Int8: (-128)...(+127) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt32.test("FromInt8(-128)_NeverTraps") { - let input = getInt8(-128) - let actual = Int32(input) - expectEqual(-128, actual) +FixedPointConversion_Debug64_ToInt32 +.test("FromInt8_NeverTraps") +.forEach(in: [ + (getInt32(-128), getInt8(-128)), + (getInt32(+0), getInt8(+0)), + (getInt32(+127), getInt8(+127)), +]) { + expectEqual($0.0, Int32($0.1)) } -FixedPointConversion_Debug64_ToInt32.test("FromInt8(-128)_NeverFails") { - let input = getInt8(-128) - let actual = Int32(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromInt8(0)_NeverTraps") { - let input = getInt8(0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromInt8(0)_NeverFails") { - let input = getInt8(0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromInt8(127)_NeverTraps") { - let input = getInt8(127) - let actual = Int32(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromInt8(127)_NeverFails") { - let input = getInt8(127) - let actual = Int32(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Debug64_ToInt32 +.test("FromInt8_NeverFails") +.forEach(in: [ + (getInt32(-128), getInt8(-128)), + (getInt32(+0), getInt8(+0)), + (getInt32(+127), getInt8(+127)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt16: (0)...(65535) +// MARK: UInt16: (+0)...(+65535) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt32.test("FromUInt16(0)_NeverTraps") { - let input = getUInt16(0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromUInt16(0)_NeverFails") { - let input = getUInt16(0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromUInt16(65535)_NeverTraps") { - let input = getUInt16(65535) - let actual = Int32(input) - expectEqual(65535, actual) +FixedPointConversion_Debug64_ToInt32 +.test("FromUInt16_NeverTraps") +.forEach(in: [ + (getInt32(+0), getUInt16(+0)), + (getInt32(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, Int32($0.1)) } -FixedPointConversion_Debug64_ToInt32.test("FromUInt16(65535)_NeverFails") { - let input = getUInt16(65535) - let actual = Int32(exactly: input) - expectEqual(65535, actual) +FixedPointConversion_Debug64_ToInt32 +.test("FromUInt16_NeverFails") +.forEach(in: [ + (getInt32(+0), getUInt16(+0)), + (getInt32(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int16: (-32768)...(32767) +// MARK: Int16: (-32768)...(+32767) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt32.test("FromInt16(-32768)_NeverTraps") { - let input = getInt16(-32768) - let actual = Int32(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromInt16(-32768)_NeverFails") { - let input = getInt16(-32768) - let actual = Int32(exactly: input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromInt16(0)_NeverTraps") { - let input = getInt16(0) - let actual = Int32(input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToInt32 +.test("FromInt16_NeverTraps") +.forEach(in: [ + (getInt32(-32768), getInt16(-32768)), + (getInt32(+0), getInt16(+0)), + (getInt32(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, Int32($0.1)) } -FixedPointConversion_Debug64_ToInt32.test("FromInt16(0)_NeverFails") { - let input = getInt16(0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromInt16(32767)_NeverTraps") { - let input = getInt16(32767) - let actual = Int32(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromInt16(32767)_NeverFails") { - let input = getInt16(32767) - let actual = Int32(exactly: input) - expectEqual(32767, actual) +FixedPointConversion_Debug64_ToInt32 +.test("FromInt16_NeverFails") +.forEach(in: [ + (getInt32(-32768), getInt16(-32768)), + (getInt32(+0), getInt16(+0)), + (getInt32(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt32: (0)...(4294967295) +// MARK: UInt32: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt32.test("FromUInt32(0)_NeverTraps") { - let input = getUInt32(0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromUInt32(0)_NeverFails") { - let input = getUInt32(0) - let actual = Int32(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToInt32 +.test("FromUInt32_NeverTraps") +.forEach(in: [ + (getInt32(+0), getUInt32(+0)), + (getInt32(+2147483647), getUInt32(+2147483647)), +]) { + expectEqual($0.0, Int32($0.1)) } -FixedPointConversion_Debug64_ToInt32.test("FromUInt32(2147483647)_NeverTraps") { - let input = getUInt32(2147483647) - let actual = Int32(input) - expectEqual(2147483647, actual) +FixedPointConversion_Debug64_ToInt32 +.test("FromUInt32_NeverFails") +.forEach(in: [ + (getInt32(+0), getUInt32(+0)), + (getInt32(+2147483647), getUInt32(+2147483647)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) } -FixedPointConversion_Debug64_ToInt32.test("FromUInt32(2147483647)_NeverFails") { - let input = getUInt32(2147483647) - let actual = Int32(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Debug64_ToInt32 +.test("FromUInt32_AlwaysTraps") +.forEach(in: [ + getUInt32(+2147483648), + getUInt32(+4294967295), +]) { + expectCrashLater() + _blackHole(Int32($0)) } -FixedPointConversion_Debug64_ToInt32.test("FromUInt32(2147483648)_AlwaysTraps") { - let input = getUInt32(2147483648) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromUInt32(2147483648)_AlwaysFails") { - let input = getUInt32(2147483648) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromUInt32(4294967295)_AlwaysTraps") { - let input = getUInt32(4294967295) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromUInt32(4294967295)_AlwaysFails") { - let input = getUInt32(4294967295) - let actual = Int32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt32 +.test("FromUInt32_AlwaysFails") +.forEach(in: [ + getUInt32(+2147483648), + getUInt32(+4294967295), +]) { + expectNil(Int32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int32: (-2147483648)...(2147483647) +// MARK: Int32: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt32.test("FromInt32(-2147483648)_NeverTraps") { - let input = getInt32(-2147483648) - let actual = Int32(input) - expectEqual(-2147483648, actual) +FixedPointConversion_Debug64_ToInt32 +.test("FromInt32_NeverTraps") +.forEach(in: [ + (getInt32(-2147483648), getInt32(-2147483648)), + (getInt32(+0), getInt32(+0)), + (getInt32(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, Int32($0.1)) } -FixedPointConversion_Debug64_ToInt32.test("FromInt32(-2147483648)_NeverFails") { - let input = getInt32(-2147483648) - let actual = Int32(exactly: input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromInt32(0)_NeverTraps") { - let input = getInt32(0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromInt32(0)_NeverFails") { - let input = getInt32(0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromInt32(2147483647)_NeverTraps") { - let input = getInt32(2147483647) - let actual = Int32(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromInt32(2147483647)_NeverFails") { - let input = getInt32(2147483647) - let actual = Int32(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Debug64_ToInt32 +.test("FromInt32_NeverFails") +.forEach(in: [ + (getInt32(-2147483648), getInt32(-2147483648)), + (getInt32(+0), getInt32(+0)), + (getInt32(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt64: (0)...(18446744073709551615) +// MARK: UInt64: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt32.test("FromUInt64(0)_NeverTraps") { - let input = getUInt64(0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromUInt64(0)_NeverFails") { - let input = getUInt64(0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromUInt64(2147483647)_NeverTraps") { - let input = getUInt64(2147483647) - let actual = Int32(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromUInt64(2147483647)_NeverFails") { - let input = getUInt64(2147483647) - let actual = Int32(exactly: input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromUInt64(2147483648)_AlwaysTraps") { - let input = getUInt64(2147483648) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } +FixedPointConversion_Debug64_ToInt32 +.test("FromUInt64_NeverTraps") +.forEach(in: [ + (getInt32(+0), getUInt64(+0)), + (getInt32(+2147483647), getUInt64(+2147483647)), +]) { + expectEqual($0.0, Int32($0.1)) } -FixedPointConversion_Debug64_ToInt32.test("FromUInt64(2147483648)_AlwaysFails") { - let input = getUInt64(2147483648) - let actual = Int32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt32 +.test("FromUInt64_NeverFails") +.forEach(in: [ + (getInt32(+0), getUInt64(+0)), + (getInt32(+2147483647), getUInt64(+2147483647)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) } -FixedPointConversion_Debug64_ToInt32.test("FromUInt64(18446744073709551615)_AlwaysTraps") { - let input = getUInt64(18446744073709551615) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } +FixedPointConversion_Debug64_ToInt32 +.test("FromUInt64_AlwaysTraps") +.forEach(in: [ + getUInt64(+2147483648), + getUInt64(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(Int32($0)) } -FixedPointConversion_Debug64_ToInt32.test("FromUInt64(18446744073709551615)_AlwaysFails") { - let input = getUInt64(18446744073709551615) - let actual = Int32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt32 +.test("FromUInt64_AlwaysFails") +.forEach(in: [ + getUInt64(+2147483648), + getUInt64(+18446744073709551615), +]) { + expectNil(Int32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int64: (-9223372036854775808)...(9223372036854775807) +// MARK: Int64: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt32.test("FromInt64(-9223372036854775808)_AlwaysTraps") { - let input = getInt64(-9223372036854775808) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromInt64(-9223372036854775808)_AlwaysFails") { - let input = getInt64(-9223372036854775808) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromInt64(-2147483649)_AlwaysTraps") { - let input = getInt64(-2147483649) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromInt64(-2147483649)_AlwaysFails") { - let input = getInt64(-2147483649) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromInt64(-2147483648)_NeverTraps") { - let input = getInt64(-2147483648) - let actual = Int32(input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromInt64(-2147483648)_NeverFails") { - let input = getInt64(-2147483648) - let actual = Int32(exactly: input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromInt64(0)_NeverTraps") { - let input = getInt64(0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromInt64(0)_NeverFails") { - let input = getInt64(0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromInt64(2147483647)_NeverTraps") { - let input = getInt64(2147483647) - let actual = Int32(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromInt64(2147483647)_NeverFails") { - let input = getInt64(2147483647) - let actual = Int32(exactly: input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromInt64(2147483648)_AlwaysTraps") { - let input = getInt64(2147483648) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromInt64(2147483648)_AlwaysFails") { - let input = getInt64(2147483648) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromInt64(9223372036854775807)_AlwaysTraps") { - let input = getInt64(9223372036854775807) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromInt64(9223372036854775807)_AlwaysFails") { - let input = getInt64(9223372036854775807) - let actual = Int32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt32 +.test("FromInt64_NeverTraps") +.forEach(in: [ + (getInt32(-2147483648), getInt64(-2147483648)), + (getInt32(+0), getInt64(+0)), + (getInt32(+2147483647), getInt64(+2147483647)), +]) { + expectEqual($0.0, Int32($0.1)) +} + +FixedPointConversion_Debug64_ToInt32 +.test("FromInt64_NeverFails") +.forEach(in: [ + (getInt32(-2147483648), getInt64(-2147483648)), + (getInt32(+0), getInt64(+0)), + (getInt32(+2147483647), getInt64(+2147483647)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToInt32 +.test("FromInt64_AlwaysTraps") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-2147483649), + getInt64(+2147483648), + getInt64(+9223372036854775807), +]) { + expectCrashLater() + _blackHole(Int32($0)) +} + +FixedPointConversion_Debug64_ToInt32 +.test("FromInt64_AlwaysFails") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-2147483649), + getInt64(+2147483648), + getInt64(+9223372036854775807), +]) { + expectNil(Int32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt: (0)...(18446744073709551615) +// MARK: UInt: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt32.test("FromUInt(0)_NeverTraps") { - let input = getUInt(0) - let actual = Int32(input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToInt32 +.test("FromUInt_NeverTraps") +.forEach(in: [ + (getInt32(+0), getUInt(+0)), + (getInt32(+2147483647), getUInt(+2147483647)), +]) { + expectEqual($0.0, Int32($0.1)) } -FixedPointConversion_Debug64_ToInt32.test("FromUInt(0)_NeverFails") { - let input = getUInt(0) - let actual = Int32(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToInt32 +.test("FromUInt_NeverFails") +.forEach(in: [ + (getInt32(+0), getUInt(+0)), + (getInt32(+2147483647), getUInt(+2147483647)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) } -FixedPointConversion_Debug64_ToInt32.test("FromUInt(2147483647)_NeverTraps") { - let input = getUInt(2147483647) - let actual = Int32(input) - expectEqual(2147483647, actual) +FixedPointConversion_Debug64_ToInt32 +.test("FromUInt_AlwaysTraps") +.forEach(in: [ + getUInt(+2147483648), + getUInt(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(Int32($0)) } -FixedPointConversion_Debug64_ToInt32.test("FromUInt(2147483647)_NeverFails") { - let input = getUInt(2147483647) - let actual = Int32(exactly: input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromUInt(2147483648)_AlwaysTraps") { - let input = getUInt(2147483648) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromUInt(2147483648)_AlwaysFails") { - let input = getUInt(2147483648) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromUInt(18446744073709551615)_AlwaysTraps") { - let input = getUInt(18446744073709551615) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromUInt(18446744073709551615)_AlwaysFails") { - let input = getUInt(18446744073709551615) - let actual = Int32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt32 +.test("FromUInt_AlwaysFails") +.forEach(in: [ + getUInt(+2147483648), + getUInt(+18446744073709551615), +]) { + expectNil(Int32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int: (-9223372036854775808)...(9223372036854775807) +// MARK: Int: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt32.test("FromInt(-9223372036854775808)_AlwaysTraps") { - let input = getInt(-9223372036854775808) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromInt(-9223372036854775808)_AlwaysFails") { - let input = getInt(-9223372036854775808) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromInt(-2147483649)_AlwaysTraps") { - let input = getInt(-2147483649) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromInt(-2147483649)_AlwaysFails") { - let input = getInt(-2147483649) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromInt(-2147483648)_NeverTraps") { - let input = getInt(-2147483648) - let actual = Int32(input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromInt(-2147483648)_NeverFails") { - let input = getInt(-2147483648) - let actual = Int32(exactly: input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromInt(0)_NeverTraps") { - let input = getInt(0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromInt(0)_NeverFails") { - let input = getInt(0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromInt(2147483647)_NeverTraps") { - let input = getInt(2147483647) - let actual = Int32(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromInt(2147483647)_NeverFails") { - let input = getInt(2147483647) - let actual = Int32(exactly: input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromInt(2147483648)_AlwaysTraps") { - let input = getInt(2147483648) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromInt(2147483648)_AlwaysFails") { - let input = getInt(2147483648) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromInt(9223372036854775807)_AlwaysTraps") { - let input = getInt(9223372036854775807) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromInt(9223372036854775807)_AlwaysFails") { - let input = getInt(9223372036854775807) - let actual = Int32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt32 +.test("FromInt_NeverTraps") +.forEach(in: [ + (getInt32(-2147483648), getInt(-2147483648)), + (getInt32(+0), getInt(+0)), + (getInt32(+2147483647), getInt(+2147483647)), +]) { + expectEqual($0.0, Int32($0.1)) +} + +FixedPointConversion_Debug64_ToInt32 +.test("FromInt_NeverFails") +.forEach(in: [ + (getInt32(-2147483648), getInt(-2147483648)), + (getInt32(+0), getInt(+0)), + (getInt32(+2147483647), getInt(+2147483647)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToInt32 +.test("FromInt_AlwaysTraps") +.forEach(in: [ + getInt(-9223372036854775808), + getInt(-2147483649), + getInt(+2147483648), + getInt(+9223372036854775807), +]) { + expectCrashLater() + _blackHole(Int32($0)) +} + +FixedPointConversion_Debug64_ToInt32 +.test("FromInt_AlwaysFails") +.forEach(in: [ + getInt(-9223372036854775808), + getInt(-2147483649), + getInt(+2147483648), + getInt(+9223372036854775807), +]) { + expectNil(Int32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float16: (-2047)...(2047) +// MARK: Float16: (-2047)...(+2047) //===----------------------------------------------------------------------===// #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -FixedPointConversion_Debug64_ToInt32.test("FromFloat16(-2047)_NeverTraps") { - let input = getFloat16(-2047) - let actual = Int32(input) - expectEqual(-2047, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat16(-2047)_NeverFails") { - let input = getFloat16(-2047) - let actual = Int32(exactly: input) - expectEqual(-2047, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat16(-128.5)_NeverTraps") { - let input = getFloat16(-128.5) - let actual = Int32(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat16(-128.5)_AlwaysFails") { - let input = getFloat16(-128.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat16(-0.5)_NeverTraps") { - let input = getFloat16(-0.5) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat16(-0.5)_AlwaysFails") { - let input = getFloat16(-0.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat16(-0.0)_NeverTraps") { - let input = getFloat16(-0.0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat16(-0.0)_NeverFails") { - let input = getFloat16(-0.0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat16(0.0)_NeverTraps") { - let input = getFloat16(0.0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat16(0.0)_NeverFails") { - let input = getFloat16(0.0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat16(0.5)_NeverTraps") { - let input = getFloat16(0.5) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat16(0.5)_AlwaysFails") { - let input = getFloat16(0.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat16(127.5)_NeverTraps") { - let input = getFloat16(127.5) - let actual = Int32(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat16(127.5)_AlwaysFails") { - let input = getFloat16(127.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat16(255.5)_NeverTraps") { - let input = getFloat16(255.5) - let actual = Int32(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat16(255.5)_AlwaysFails") { - let input = getFloat16(255.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat16(2047)_NeverTraps") { - let input = getFloat16(2047) - let actual = Int32(input) - expectEqual(2047, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat16(2047)_NeverFails") { - let input = getFloat16(2047) - let actual = Int32(exactly: input) - expectEqual(2047, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat16(-.infinity)_AlwaysTraps") { - let input = getFloat16(-.infinity) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat16(-.infinity)_AlwaysFails") { - let input = getFloat16(-.infinity) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat16(+.infinity)_AlwaysTraps") { - let input = getFloat16(+.infinity) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat16(+.infinity)_AlwaysFails") { - let input = getFloat16(+.infinity) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat16(-.nan)_AlwaysTraps") { - let input = getFloat16(-.nan) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat16(-.nan)_AlwaysFails") { - let input = getFloat16(-.nan) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat16(+.nan)_AlwaysTraps") { - let input = getFloat16(+.nan) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat16(+.nan)_AlwaysFails") { - let input = getFloat16(+.nan) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat16(-.signalingNaN)_AlwaysTraps") { - let input = getFloat16(-.signalingNaN) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat16(-.signalingNaN)_AlwaysFails") { - let input = getFloat16(-.signalingNaN) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat16(+.signalingNaN)_AlwaysTraps") { - let input = getFloat16(+.signalingNaN) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat16(+.signalingNaN)_AlwaysFails") { - let input = getFloat16(+.signalingNaN) - let actual = Int32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt32 +.test("FromFloat16_NeverTraps") +.forEach(in: [ + (getInt32(-2047), getFloat16(-2047)), + (getInt32(-128), getFloat16(-128.5)), + (getInt32(+0), getFloat16(-0.5)), + (getInt32(+0), getFloat16(+0)), + (getInt32(+0), getFloat16(-0)), + (getInt32(+0), getFloat16(+0.5)), + (getInt32(+127), getFloat16(+127.5)), + (getInt32(+255), getFloat16(+255.5)), + (getInt32(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, Int32($0.1)) +} + +FixedPointConversion_Debug64_ToInt32 +.test("FromFloat16_NeverFails") +.forEach(in: [ + (getInt32(-2047), getFloat16(-2047)), + (getInt32(+0), getFloat16(+0)), + (getInt32(+0), getFloat16(-0)), + (getInt32(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToInt32 +.test("FromFloat16_AlwaysTraps") +.forEach(in: [ + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int32($0)) +} + +FixedPointConversion_Debug64_ToInt32 +.test("FromFloat16_AlwaysFails") +.forEach(in: [ + getFloat16(-128.5), + getFloat16(-0.5), + getFloat16(+0.5), + getFloat16(+127.5), + getFloat16(+255.5), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectNil(Int32(exactly: $0)) } } #endif // Float16 //===----------------------------------------------------------------------===// -// MARK: Float32: (-16777215)...(16777215) +// MARK: Float32: (-16777215)...(+16777215) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt32.test("FromFloat32(-16777215)_NeverTraps") { - let input = getFloat32(-16777215) - let actual = Int32(input) - expectEqual(-16777215, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat32(-16777215)_NeverFails") { - let input = getFloat32(-16777215) - let actual = Int32(exactly: input) - expectEqual(-16777215, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat32(-32768.5)_NeverTraps") { - let input = getFloat32(-32768.5) - let actual = Int32(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat32(-32768.5)_AlwaysFails") { - let input = getFloat32(-32768.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat32(-128.5)_NeverTraps") { - let input = getFloat32(-128.5) - let actual = Int32(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat32(-128.5)_AlwaysFails") { - let input = getFloat32(-128.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat32(-0.5)_NeverTraps") { - let input = getFloat32(-0.5) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat32(-0.5)_AlwaysFails") { - let input = getFloat32(-0.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat32(-0.0)_NeverTraps") { - let input = getFloat32(-0.0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat32(-0.0)_NeverFails") { - let input = getFloat32(-0.0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat32(0.0)_NeverTraps") { - let input = getFloat32(0.0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat32(0.0)_NeverFails") { - let input = getFloat32(0.0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat32(0.5)_NeverTraps") { - let input = getFloat32(0.5) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat32(0.5)_AlwaysFails") { - let input = getFloat32(0.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat32(127.5)_NeverTraps") { - let input = getFloat32(127.5) - let actual = Int32(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat32(127.5)_AlwaysFails") { - let input = getFloat32(127.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat32(255.5)_NeverTraps") { - let input = getFloat32(255.5) - let actual = Int32(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat32(255.5)_AlwaysFails") { - let input = getFloat32(255.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat32(32767.5)_NeverTraps") { - let input = getFloat32(32767.5) - let actual = Int32(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat32(32767.5)_AlwaysFails") { - let input = getFloat32(32767.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat32(65535.5)_NeverTraps") { - let input = getFloat32(65535.5) - let actual = Int32(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat32(65535.5)_AlwaysFails") { - let input = getFloat32(65535.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat32(16777215)_NeverTraps") { - let input = getFloat32(16777215) - let actual = Int32(input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat32(16777215)_NeverFails") { - let input = getFloat32(16777215) - let actual = Int32(exactly: input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat32(-.infinity)_AlwaysTraps") { - let input = getFloat32(-.infinity) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat32(-.infinity)_AlwaysFails") { - let input = getFloat32(-.infinity) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat32(+.infinity)_AlwaysTraps") { - let input = getFloat32(+.infinity) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat32(+.infinity)_AlwaysFails") { - let input = getFloat32(+.infinity) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat32(-.nan)_AlwaysTraps") { - let input = getFloat32(-.nan) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat32(-.nan)_AlwaysFails") { - let input = getFloat32(-.nan) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat32(+.nan)_AlwaysTraps") { - let input = getFloat32(+.nan) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat32(+.nan)_AlwaysFails") { - let input = getFloat32(+.nan) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat32(-.signalingNaN)_AlwaysTraps") { - let input = getFloat32(-.signalingNaN) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat32(-.signalingNaN)_AlwaysFails") { - let input = getFloat32(-.signalingNaN) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat32(+.signalingNaN)_AlwaysTraps") { - let input = getFloat32(+.signalingNaN) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat32(+.signalingNaN)_AlwaysFails") { - let input = getFloat32(+.signalingNaN) - let actual = Int32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt32 +.test("FromFloat32_NeverTraps") +.forEach(in: [ + (getInt32(-16777215), getFloat32(-16777215)), + (getInt32(-32768), getFloat32(-32768.5)), + (getInt32(-128), getFloat32(-128.5)), + (getInt32(+0), getFloat32(-0.5)), + (getInt32(+0), getFloat32(+0)), + (getInt32(+0), getFloat32(-0)), + (getInt32(+0), getFloat32(+0.5)), + (getInt32(+127), getFloat32(+127.5)), + (getInt32(+255), getFloat32(+255.5)), + (getInt32(+32767), getFloat32(+32767.5)), + (getInt32(+65535), getFloat32(+65535.5)), + (getInt32(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, Int32($0.1)) +} + +FixedPointConversion_Debug64_ToInt32 +.test("FromFloat32_NeverFails") +.forEach(in: [ + (getInt32(-16777215), getFloat32(-16777215)), + (getInt32(+0), getFloat32(+0)), + (getInt32(+0), getFloat32(-0)), + (getInt32(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToInt32 +.test("FromFloat32_AlwaysTraps") +.forEach(in: [ + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int32($0)) +} + +FixedPointConversion_Debug64_ToInt32 +.test("FromFloat32_AlwaysFails") +.forEach(in: [ + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-0.5), + getFloat32(+0.5), + getFloat32(+127.5), + getFloat32(+255.5), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectNil(Int32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float64: (-9007199254740991)...(9007199254740991) +// MARK: Float64: (-9007199254740991)...(+9007199254740991) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(-9007199254740991)_AlwaysTraps") { - let input = getFloat64(-9007199254740991) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(-9007199254740991)_AlwaysFails") { - let input = getFloat64(-9007199254740991) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(-2147483649)_AlwaysTraps") { - let input = getFloat64(-2147483649) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(-2147483649)_AlwaysFails") { - let input = getFloat64(-2147483649) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(-2147483648)_NeverTraps") { - let input = getFloat64(-2147483648) - let actual = Int32(input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(-2147483648)_NeverFails") { - let input = getFloat64(-2147483648) - let actual = Int32(exactly: input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(-32768.5)_NeverTraps") { - let input = getFloat64(-32768.5) - let actual = Int32(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(-32768.5)_AlwaysFails") { - let input = getFloat64(-32768.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(-128.5)_NeverTraps") { - let input = getFloat64(-128.5) - let actual = Int32(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(-128.5)_AlwaysFails") { - let input = getFloat64(-128.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(-0.5)_NeverTraps") { - let input = getFloat64(-0.5) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(-0.5)_AlwaysFails") { - let input = getFloat64(-0.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(-0.0)_NeverTraps") { - let input = getFloat64(-0.0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(-0.0)_NeverFails") { - let input = getFloat64(-0.0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(0.0)_NeverTraps") { - let input = getFloat64(0.0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(0.0)_NeverFails") { - let input = getFloat64(0.0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(0.5)_NeverTraps") { - let input = getFloat64(0.5) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(0.5)_AlwaysFails") { - let input = getFloat64(0.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(127.5)_NeverTraps") { - let input = getFloat64(127.5) - let actual = Int32(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(127.5)_AlwaysFails") { - let input = getFloat64(127.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(255.5)_NeverTraps") { - let input = getFloat64(255.5) - let actual = Int32(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(255.5)_AlwaysFails") { - let input = getFloat64(255.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(32767.5)_NeverTraps") { - let input = getFloat64(32767.5) - let actual = Int32(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(32767.5)_AlwaysFails") { - let input = getFloat64(32767.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(65535.5)_NeverTraps") { - let input = getFloat64(65535.5) - let actual = Int32(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(65535.5)_AlwaysFails") { - let input = getFloat64(65535.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(2147483647)_NeverTraps") { - let input = getFloat64(2147483647) - let actual = Int32(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(2147483647)_NeverFails") { - let input = getFloat64(2147483647) - let actual = Int32(exactly: input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(2147483648)_AlwaysTraps") { - let input = getFloat64(2147483648) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(2147483648)_AlwaysFails") { - let input = getFloat64(2147483648) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(9007199254740991)_AlwaysTraps") { - let input = getFloat64(9007199254740991) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(9007199254740991)_AlwaysFails") { - let input = getFloat64(9007199254740991) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(-.infinity)_AlwaysTraps") { - let input = getFloat64(-.infinity) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(-.infinity)_AlwaysFails") { - let input = getFloat64(-.infinity) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(+.infinity)_AlwaysTraps") { - let input = getFloat64(+.infinity) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(+.infinity)_AlwaysFails") { - let input = getFloat64(+.infinity) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(-.nan)_AlwaysTraps") { - let input = getFloat64(-.nan) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(-.nan)_AlwaysFails") { - let input = getFloat64(-.nan) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(+.nan)_AlwaysTraps") { - let input = getFloat64(+.nan) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(+.nan)_AlwaysFails") { - let input = getFloat64(+.nan) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(-.signalingNaN)_AlwaysTraps") { - let input = getFloat64(-.signalingNaN) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(-.signalingNaN)_AlwaysFails") { - let input = getFloat64(-.signalingNaN) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(+.signalingNaN)_AlwaysTraps") { - let input = getFloat64(+.signalingNaN) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat64(+.signalingNaN)_AlwaysFails") { - let input = getFloat64(+.signalingNaN) - let actual = Int32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt32 +.test("FromFloat64_NeverTraps") +.forEach(in: [ + (getInt32(-2147483648), getFloat64(-2147483648)), + (getInt32(-32768), getFloat64(-32768.5)), + (getInt32(-128), getFloat64(-128.5)), + (getInt32(+0), getFloat64(-0.5)), + (getInt32(+0), getFloat64(-0)), + (getInt32(+0), getFloat64(+0)), + (getInt32(+0), getFloat64(+0.5)), + (getInt32(+127), getFloat64(+127.5)), + (getInt32(+255), getFloat64(+255.5)), + (getInt32(+32767), getFloat64(+32767.5)), + (getInt32(+65535), getFloat64(+65535.5)), + (getInt32(+2147483647), getFloat64(+2147483647)), +]) { + expectEqual($0.0, Int32($0.1)) +} + +FixedPointConversion_Debug64_ToInt32 +.test("FromFloat64_NeverFails") +.forEach(in: [ + (getInt32(-2147483648), getFloat64(-2147483648)), + (getInt32(+0), getFloat64(-0)), + (getInt32(+0), getFloat64(+0)), + (getInt32(+2147483647), getFloat64(+2147483647)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToInt32 +.test("FromFloat64_AlwaysTraps") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-2147483649), + getFloat64(+2147483648), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int32($0)) +} + +FixedPointConversion_Debug64_ToInt32 +.test("FromFloat64_AlwaysFails") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-2147483649), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-0.5), + getFloat64(+0.5), + getFloat64(+127.5), + getFloat64(+255.5), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(+2147483648), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectNil(Int32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float80: (-18446744073709551615)...(18446744073709551615) +// MARK: Float80: (-18446744073709551615)...(+18446744073709551615) //===----------------------------------------------------------------------===// #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(-18446744073709551615)_AlwaysTraps") { - let input = getFloat80(-18446744073709551615) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(-18446744073709551615)_AlwaysFails") { - let input = getFloat80(-18446744073709551615) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(-2147483649)_AlwaysTraps") { - let input = getFloat80(-2147483649) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(-2147483649)_AlwaysFails") { - let input = getFloat80(-2147483649) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(-2147483648)_NeverTraps") { - let input = getFloat80(-2147483648) - let actual = Int32(input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(-2147483648)_NeverFails") { - let input = getFloat80(-2147483648) - let actual = Int32(exactly: input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(-32768.5)_NeverTraps") { - let input = getFloat80(-32768.5) - let actual = Int32(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(-32768.5)_AlwaysFails") { - let input = getFloat80(-32768.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(-128.5)_NeverTraps") { - let input = getFloat80(-128.5) - let actual = Int32(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(-128.5)_AlwaysFails") { - let input = getFloat80(-128.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(-0.5)_NeverTraps") { - let input = getFloat80(-0.5) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(-0.5)_AlwaysFails") { - let input = getFloat80(-0.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(-0.0)_NeverTraps") { - let input = getFloat80(-0.0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(-0.0)_NeverFails") { - let input = getFloat80(-0.0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(0.0)_NeverTraps") { - let input = getFloat80(0.0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(0.0)_NeverFails") { - let input = getFloat80(0.0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(0.5)_NeverTraps") { - let input = getFloat80(0.5) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(0.5)_AlwaysFails") { - let input = getFloat80(0.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(127.5)_NeverTraps") { - let input = getFloat80(127.5) - let actual = Int32(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(127.5)_AlwaysFails") { - let input = getFloat80(127.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(255.5)_NeverTraps") { - let input = getFloat80(255.5) - let actual = Int32(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(255.5)_AlwaysFails") { - let input = getFloat80(255.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(32767.5)_NeverTraps") { - let input = getFloat80(32767.5) - let actual = Int32(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(32767.5)_AlwaysFails") { - let input = getFloat80(32767.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(65535.5)_NeverTraps") { - let input = getFloat80(65535.5) - let actual = Int32(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(65535.5)_AlwaysFails") { - let input = getFloat80(65535.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(2147483647)_NeverTraps") { - let input = getFloat80(2147483647) - let actual = Int32(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(2147483647)_NeverFails") { - let input = getFloat80(2147483647) - let actual = Int32(exactly: input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(2147483648)_AlwaysTraps") { - let input = getFloat80(2147483648) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(2147483648)_AlwaysFails") { - let input = getFloat80(2147483648) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(18446744073709551615)_AlwaysTraps") { - let input = getFloat80(18446744073709551615) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(18446744073709551615)_AlwaysFails") { - let input = getFloat80(18446744073709551615) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(-.infinity)_AlwaysTraps") { - let input = getFloat80(-.infinity) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(-.infinity)_AlwaysFails") { - let input = getFloat80(-.infinity) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(+.infinity)_AlwaysTraps") { - let input = getFloat80(+.infinity) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(+.infinity)_AlwaysFails") { - let input = getFloat80(+.infinity) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(-.nan)_AlwaysTraps") { - let input = getFloat80(-.nan) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(-.nan)_AlwaysFails") { - let input = getFloat80(-.nan) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(+.nan)_AlwaysTraps") { - let input = getFloat80(+.nan) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(+.nan)_AlwaysFails") { - let input = getFloat80(+.nan) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(-.signalingNaN)_AlwaysTraps") { - let input = getFloat80(-.signalingNaN) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(-.signalingNaN)_AlwaysFails") { - let input = getFloat80(-.signalingNaN) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(+.signalingNaN)_AlwaysTraps") { - let input = getFloat80(+.signalingNaN) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt32.test("FromFloat80(+.signalingNaN)_AlwaysFails") { - let input = getFloat80(+.signalingNaN) - let actual = Int32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt32 +.test("FromFloat80_NeverTraps") +.forEach(in: [ + (getInt32(-2147483648), getFloat80(-2147483648)), + (getInt32(-32768), getFloat80(-32768.5)), + (getInt32(-128), getFloat80(-128.5)), + (getInt32(+0), getFloat80(-0.5)), + (getInt32(+0), getFloat80(-0)), + (getInt32(+0), getFloat80(+0)), + (getInt32(+0), getFloat80(+0.5)), + (getInt32(+127), getFloat80(+127.5)), + (getInt32(+255), getFloat80(+255.5)), + (getInt32(+32767), getFloat80(+32767.5)), + (getInt32(+65535), getFloat80(+65535.5)), + (getInt32(+2147483647), getFloat80(+2147483647)), +]) { + expectEqual($0.0, Int32($0.1)) +} + +FixedPointConversion_Debug64_ToInt32 +.test("FromFloat80_NeverFails") +.forEach(in: [ + (getInt32(-2147483648), getFloat80(-2147483648)), + (getInt32(+0), getFloat80(-0)), + (getInt32(+0), getFloat80(+0)), + (getInt32(+2147483647), getFloat80(+2147483647)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToInt32 +.test("FromFloat80_AlwaysTraps") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-2147483649), + getFloat80(+2147483648), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int32($0)) +} + +FixedPointConversion_Debug64_ToInt32 +.test("FromFloat80_AlwaysFails") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-2147483649), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-0.5), + getFloat80(+0.5), + getFloat80(+127.5), + getFloat80(+255.5), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(+2147483648), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectNil(Int32(exactly: $0)) } #endif // Float80 diff --git a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug64_ToInt64.swift b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug64_ToInt64.swift index ea98c46852dac..8cec72ee87e27 100644 --- a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug64_ToInt64.swift +++ b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug64_ToInt64.swift @@ -14,1358 +14,562 @@ import StdlibUnittest -let FixedPointConversion_Debug64_ToInt64 = TestSuite("FixedPointConversion_Debug64_ToInt64") +let FixedPointConversion_Debug64_ToInt64 = TestSuite( + "FixedPointConversion_Debug64_ToInt64" +) //===----------------------------------------------------------------------===// -// MARK: UInt8: (0)...(255) +// MARK: UInt8: (+0)...(+255) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt64.test("FromUInt8(0)_NeverTraps") { - let input = getUInt8(0) - let actual = Int64(input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToInt64 +.test("FromUInt8_NeverTraps") +.forEach(in: [ + (getInt64(+0), getUInt8(+0)), + (getInt64(+255), getUInt8(+255)), +]) { + expectEqual($0.0, Int64($0.1)) } -FixedPointConversion_Debug64_ToInt64.test("FromUInt8(0)_NeverFails") { - let input = getUInt8(0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromUInt8(255)_NeverTraps") { - let input = getUInt8(255) - let actual = Int64(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromUInt8(255)_NeverFails") { - let input = getUInt8(255) - let actual = Int64(exactly: input) - expectEqual(255, actual) +FixedPointConversion_Debug64_ToInt64 +.test("FromUInt8_NeverFails") +.forEach(in: [ + (getInt64(+0), getUInt8(+0)), + (getInt64(+255), getUInt8(+255)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int8: (-128)...(127) +// MARK: Int8: (-128)...(+127) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt64.test("FromInt8(-128)_NeverTraps") { - let input = getInt8(-128) - let actual = Int64(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromInt8(-128)_NeverFails") { - let input = getInt8(-128) - let actual = Int64(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromInt8(0)_NeverTraps") { - let input = getInt8(0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromInt8(0)_NeverFails") { - let input = getInt8(0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromInt8(127)_NeverTraps") { - let input = getInt8(127) - let actual = Int64(input) - expectEqual(127, actual) +FixedPointConversion_Debug64_ToInt64 +.test("FromInt8_NeverTraps") +.forEach(in: [ + (getInt64(-128), getInt8(-128)), + (getInt64(+0), getInt8(+0)), + (getInt64(+127), getInt8(+127)), +]) { + expectEqual($0.0, Int64($0.1)) } -FixedPointConversion_Debug64_ToInt64.test("FromInt8(127)_NeverFails") { - let input = getInt8(127) - let actual = Int64(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Debug64_ToInt64 +.test("FromInt8_NeverFails") +.forEach(in: [ + (getInt64(-128), getInt8(-128)), + (getInt64(+0), getInt8(+0)), + (getInt64(+127), getInt8(+127)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt16: (0)...(65535) +// MARK: UInt16: (+0)...(+65535) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt64.test("FromUInt16(0)_NeverTraps") { - let input = getUInt16(0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromUInt16(0)_NeverFails") { - let input = getUInt16(0) - let actual = Int64(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToInt64 +.test("FromUInt16_NeverTraps") +.forEach(in: [ + (getInt64(+0), getUInt16(+0)), + (getInt64(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, Int64($0.1)) } -FixedPointConversion_Debug64_ToInt64.test("FromUInt16(65535)_NeverTraps") { - let input = getUInt16(65535) - let actual = Int64(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromUInt16(65535)_NeverFails") { - let input = getUInt16(65535) - let actual = Int64(exactly: input) - expectEqual(65535, actual) +FixedPointConversion_Debug64_ToInt64 +.test("FromUInt16_NeverFails") +.forEach(in: [ + (getInt64(+0), getUInt16(+0)), + (getInt64(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int16: (-32768)...(32767) +// MARK: Int16: (-32768)...(+32767) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt64.test("FromInt16(-32768)_NeverTraps") { - let input = getInt16(-32768) - let actual = Int64(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromInt16(-32768)_NeverFails") { - let input = getInt16(-32768) - let actual = Int64(exactly: input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromInt16(0)_NeverTraps") { - let input = getInt16(0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromInt16(0)_NeverFails") { - let input = getInt16(0) - let actual = Int64(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToInt64 +.test("FromInt16_NeverTraps") +.forEach(in: [ + (getInt64(-32768), getInt16(-32768)), + (getInt64(+0), getInt16(+0)), + (getInt64(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, Int64($0.1)) } -FixedPointConversion_Debug64_ToInt64.test("FromInt16(32767)_NeverTraps") { - let input = getInt16(32767) - let actual = Int64(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromInt16(32767)_NeverFails") { - let input = getInt16(32767) - let actual = Int64(exactly: input) - expectEqual(32767, actual) +FixedPointConversion_Debug64_ToInt64 +.test("FromInt16_NeverFails") +.forEach(in: [ + (getInt64(-32768), getInt16(-32768)), + (getInt64(+0), getInt16(+0)), + (getInt64(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt32: (0)...(4294967295) +// MARK: UInt32: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt64.test("FromUInt32(0)_NeverTraps") { - let input = getUInt32(0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromUInt32(0)_NeverFails") { - let input = getUInt32(0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromUInt32(4294967295)_NeverTraps") { - let input = getUInt32(4294967295) - let actual = Int64(input) - expectEqual(4294967295, actual) +FixedPointConversion_Debug64_ToInt64 +.test("FromUInt32_NeverTraps") +.forEach(in: [ + (getInt64(+0), getUInt32(+0)), + (getInt64(+4294967295), getUInt32(+4294967295)), +]) { + expectEqual($0.0, Int64($0.1)) } -FixedPointConversion_Debug64_ToInt64.test("FromUInt32(4294967295)_NeverFails") { - let input = getUInt32(4294967295) - let actual = Int64(exactly: input) - expectEqual(4294967295, actual) +FixedPointConversion_Debug64_ToInt64 +.test("FromUInt32_NeverFails") +.forEach(in: [ + (getInt64(+0), getUInt32(+0)), + (getInt64(+4294967295), getUInt32(+4294967295)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int32: (-2147483648)...(2147483647) +// MARK: Int32: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt64.test("FromInt32(-2147483648)_NeverTraps") { - let input = getInt32(-2147483648) - let actual = Int64(input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromInt32(-2147483648)_NeverFails") { - let input = getInt32(-2147483648) - let actual = Int64(exactly: input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromInt32(0)_NeverTraps") { - let input = getInt32(0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromInt32(0)_NeverFails") { - let input = getInt32(0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromInt32(2147483647)_NeverTraps") { - let input = getInt32(2147483647) - let actual = Int64(input) - expectEqual(2147483647, actual) +FixedPointConversion_Debug64_ToInt64 +.test("FromInt32_NeverTraps") +.forEach(in: [ + (getInt64(-2147483648), getInt32(-2147483648)), + (getInt64(+0), getInt32(+0)), + (getInt64(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, Int64($0.1)) } -FixedPointConversion_Debug64_ToInt64.test("FromInt32(2147483647)_NeverFails") { - let input = getInt32(2147483647) - let actual = Int64(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Debug64_ToInt64 +.test("FromInt32_NeverFails") +.forEach(in: [ + (getInt64(-2147483648), getInt32(-2147483648)), + (getInt64(+0), getInt32(+0)), + (getInt64(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt64: (0)...(18446744073709551615) +// MARK: UInt64: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt64.test("FromUInt64(0)_NeverTraps") { - let input = getUInt64(0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromUInt64(0)_NeverFails") { - let input = getUInt64(0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromUInt64(9223372036854775807)_NeverTraps") { - let input = getUInt64(9223372036854775807) - let actual = Int64(input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromUInt64(9223372036854775807)_NeverFails") { - let input = getUInt64(9223372036854775807) - let actual = Int64(exactly: input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromUInt64(9223372036854775808)_AlwaysTraps") { - let input = getUInt64(9223372036854775808) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } +FixedPointConversion_Debug64_ToInt64 +.test("FromUInt64_NeverTraps") +.forEach(in: [ + (getInt64(+0), getUInt64(+0)), + (getInt64(+9223372036854775807), getUInt64(+9223372036854775807)), +]) { + expectEqual($0.0, Int64($0.1)) } -FixedPointConversion_Debug64_ToInt64.test("FromUInt64(9223372036854775808)_AlwaysFails") { - let input = getUInt64(9223372036854775808) - let actual = Int64(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt64 +.test("FromUInt64_NeverFails") +.forEach(in: [ + (getInt64(+0), getUInt64(+0)), + (getInt64(+9223372036854775807), getUInt64(+9223372036854775807)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) } -FixedPointConversion_Debug64_ToInt64.test("FromUInt64(18446744073709551615)_AlwaysTraps") { - let input = getUInt64(18446744073709551615) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } +FixedPointConversion_Debug64_ToInt64 +.test("FromUInt64_AlwaysTraps") +.forEach(in: [ + getUInt64(+9223372036854775808), + getUInt64(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(Int64($0)) } -FixedPointConversion_Debug64_ToInt64.test("FromUInt64(18446744073709551615)_AlwaysFails") { - let input = getUInt64(18446744073709551615) - let actual = Int64(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt64 +.test("FromUInt64_AlwaysFails") +.forEach(in: [ + getUInt64(+9223372036854775808), + getUInt64(+18446744073709551615), +]) { + expectNil(Int64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int64: (-9223372036854775808)...(9223372036854775807) +// MARK: Int64: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt64.test("FromInt64(-9223372036854775808)_NeverTraps") { - let input = getInt64(-9223372036854775808) - let actual = Int64(input) - expectEqual(-9223372036854775808, actual) +FixedPointConversion_Debug64_ToInt64 +.test("FromInt64_NeverTraps") +.forEach(in: [ + (getInt64(-9223372036854775808), getInt64(-9223372036854775808)), + (getInt64(+0), getInt64(+0)), + (getInt64(+9223372036854775807), getInt64(+9223372036854775807)), +]) { + expectEqual($0.0, Int64($0.1)) } -FixedPointConversion_Debug64_ToInt64.test("FromInt64(-9223372036854775808)_NeverFails") { - let input = getInt64(-9223372036854775808) - let actual = Int64(exactly: input) - expectEqual(-9223372036854775808, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromInt64(0)_NeverTraps") { - let input = getInt64(0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromInt64(0)_NeverFails") { - let input = getInt64(0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromInt64(9223372036854775807)_NeverTraps") { - let input = getInt64(9223372036854775807) - let actual = Int64(input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromInt64(9223372036854775807)_NeverFails") { - let input = getInt64(9223372036854775807) - let actual = Int64(exactly: input) - expectEqual(9223372036854775807, actual) +FixedPointConversion_Debug64_ToInt64 +.test("FromInt64_NeverFails") +.forEach(in: [ + (getInt64(-9223372036854775808), getInt64(-9223372036854775808)), + (getInt64(+0), getInt64(+0)), + (getInt64(+9223372036854775807), getInt64(+9223372036854775807)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt: (0)...(18446744073709551615) +// MARK: UInt: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt64.test("FromUInt(0)_NeverTraps") { - let input = getUInt(0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromUInt(0)_NeverFails") { - let input = getUInt(0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromUInt(9223372036854775807)_NeverTraps") { - let input = getUInt(9223372036854775807) - let actual = Int64(input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromUInt(9223372036854775807)_NeverFails") { - let input = getUInt(9223372036854775807) - let actual = Int64(exactly: input) - expectEqual(9223372036854775807, actual) +FixedPointConversion_Debug64_ToInt64 +.test("FromUInt_NeverTraps") +.forEach(in: [ + (getInt64(+0), getUInt(+0)), + (getInt64(+9223372036854775807), getUInt(+9223372036854775807)), +]) { + expectEqual($0.0, Int64($0.1)) } -FixedPointConversion_Debug64_ToInt64.test("FromUInt(9223372036854775808)_AlwaysTraps") { - let input = getUInt(9223372036854775808) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } +FixedPointConversion_Debug64_ToInt64 +.test("FromUInt_NeverFails") +.forEach(in: [ + (getInt64(+0), getUInt(+0)), + (getInt64(+9223372036854775807), getUInt(+9223372036854775807)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) } -FixedPointConversion_Debug64_ToInt64.test("FromUInt(9223372036854775808)_AlwaysFails") { - let input = getUInt(9223372036854775808) - let actual = Int64(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt64 +.test("FromUInt_AlwaysTraps") +.forEach(in: [ + getUInt(+9223372036854775808), + getUInt(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(Int64($0)) } -FixedPointConversion_Debug64_ToInt64.test("FromUInt(18446744073709551615)_AlwaysTraps") { - let input = getUInt(18446744073709551615) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt64.test("FromUInt(18446744073709551615)_AlwaysFails") { - let input = getUInt(18446744073709551615) - let actual = Int64(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt64 +.test("FromUInt_AlwaysFails") +.forEach(in: [ + getUInt(+9223372036854775808), + getUInt(+18446744073709551615), +]) { + expectNil(Int64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int: (-9223372036854775808)...(9223372036854775807) +// MARK: Int: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt64.test("FromInt(-9223372036854775808)_NeverTraps") { - let input = getInt(-9223372036854775808) - let actual = Int64(input) - expectEqual(-9223372036854775808, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromInt(-9223372036854775808)_NeverFails") { - let input = getInt(-9223372036854775808) - let actual = Int64(exactly: input) - expectEqual(-9223372036854775808, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromInt(0)_NeverTraps") { - let input = getInt(0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromInt(0)_NeverFails") { - let input = getInt(0) - let actual = Int64(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToInt64 +.test("FromInt_NeverTraps") +.forEach(in: [ + (getInt64(-9223372036854775808), getInt(-9223372036854775808)), + (getInt64(+0), getInt(+0)), + (getInt64(+9223372036854775807), getInt(+9223372036854775807)), +]) { + expectEqual($0.0, Int64($0.1)) } -FixedPointConversion_Debug64_ToInt64.test("FromInt(9223372036854775807)_NeverTraps") { - let input = getInt(9223372036854775807) - let actual = Int64(input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromInt(9223372036854775807)_NeverFails") { - let input = getInt(9223372036854775807) - let actual = Int64(exactly: input) - expectEqual(9223372036854775807, actual) +FixedPointConversion_Debug64_ToInt64 +.test("FromInt_NeverFails") +.forEach(in: [ + (getInt64(-9223372036854775808), getInt(-9223372036854775808)), + (getInt64(+0), getInt(+0)), + (getInt64(+9223372036854775807), getInt(+9223372036854775807)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Float16: (-2047)...(2047) +// MARK: Float16: (-2047)...(+2047) //===----------------------------------------------------------------------===// #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -FixedPointConversion_Debug64_ToInt64.test("FromFloat16(-2047)_NeverTraps") { - let input = getFloat16(-2047) - let actual = Int64(input) - expectEqual(-2047, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat16(-2047)_NeverFails") { - let input = getFloat16(-2047) - let actual = Int64(exactly: input) - expectEqual(-2047, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat16(-128.5)_NeverTraps") { - let input = getFloat16(-128.5) - let actual = Int64(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat16(-128.5)_AlwaysFails") { - let input = getFloat16(-128.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat16(-0.5)_NeverTraps") { - let input = getFloat16(-0.5) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat16(-0.5)_AlwaysFails") { - let input = getFloat16(-0.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat16(-0.0)_NeverTraps") { - let input = getFloat16(-0.0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat16(-0.0)_NeverFails") { - let input = getFloat16(-0.0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat16(0.0)_NeverTraps") { - let input = getFloat16(0.0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat16(0.0)_NeverFails") { - let input = getFloat16(0.0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat16(0.5)_NeverTraps") { - let input = getFloat16(0.5) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat16(0.5)_AlwaysFails") { - let input = getFloat16(0.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat16(127.5)_NeverTraps") { - let input = getFloat16(127.5) - let actual = Int64(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat16(127.5)_AlwaysFails") { - let input = getFloat16(127.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat16(255.5)_NeverTraps") { - let input = getFloat16(255.5) - let actual = Int64(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat16(255.5)_AlwaysFails") { - let input = getFloat16(255.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat16(2047)_NeverTraps") { - let input = getFloat16(2047) - let actual = Int64(input) - expectEqual(2047, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat16(2047)_NeverFails") { - let input = getFloat16(2047) - let actual = Int64(exactly: input) - expectEqual(2047, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat16(-.infinity)_AlwaysTraps") { - let input = getFloat16(-.infinity) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat16(-.infinity)_AlwaysFails") { - let input = getFloat16(-.infinity) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat16(+.infinity)_AlwaysTraps") { - let input = getFloat16(+.infinity) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat16(+.infinity)_AlwaysFails") { - let input = getFloat16(+.infinity) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat16(-.nan)_AlwaysTraps") { - let input = getFloat16(-.nan) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat16(-.nan)_AlwaysFails") { - let input = getFloat16(-.nan) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat16(+.nan)_AlwaysTraps") { - let input = getFloat16(+.nan) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat16(+.nan)_AlwaysFails") { - let input = getFloat16(+.nan) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat16(-.signalingNaN)_AlwaysTraps") { - let input = getFloat16(-.signalingNaN) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat16(-.signalingNaN)_AlwaysFails") { - let input = getFloat16(-.signalingNaN) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat16(+.signalingNaN)_AlwaysTraps") { - let input = getFloat16(+.signalingNaN) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat16(+.signalingNaN)_AlwaysFails") { - let input = getFloat16(+.signalingNaN) - let actual = Int64(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt64 +.test("FromFloat16_NeverTraps") +.forEach(in: [ + (getInt64(-2047), getFloat16(-2047)), + (getInt64(-128), getFloat16(-128.5)), + (getInt64(+0), getFloat16(-0.5)), + (getInt64(+0), getFloat16(+0)), + (getInt64(+0), getFloat16(-0)), + (getInt64(+0), getFloat16(+0.5)), + (getInt64(+127), getFloat16(+127.5)), + (getInt64(+255), getFloat16(+255.5)), + (getInt64(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, Int64($0.1)) +} + +FixedPointConversion_Debug64_ToInt64 +.test("FromFloat16_NeverFails") +.forEach(in: [ + (getInt64(-2047), getFloat16(-2047)), + (getInt64(+0), getFloat16(+0)), + (getInt64(+0), getFloat16(-0)), + (getInt64(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToInt64 +.test("FromFloat16_AlwaysTraps") +.forEach(in: [ + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int64($0)) +} + +FixedPointConversion_Debug64_ToInt64 +.test("FromFloat16_AlwaysFails") +.forEach(in: [ + getFloat16(-128.5), + getFloat16(-0.5), + getFloat16(+0.5), + getFloat16(+127.5), + getFloat16(+255.5), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectNil(Int64(exactly: $0)) } } #endif // Float16 //===----------------------------------------------------------------------===// -// MARK: Float32: (-16777215)...(16777215) +// MARK: Float32: (-16777215)...(+16777215) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt64.test("FromFloat32(-16777215)_NeverTraps") { - let input = getFloat32(-16777215) - let actual = Int64(input) - expectEqual(-16777215, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat32(-16777215)_NeverFails") { - let input = getFloat32(-16777215) - let actual = Int64(exactly: input) - expectEqual(-16777215, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat32(-32768.5)_NeverTraps") { - let input = getFloat32(-32768.5) - let actual = Int64(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat32(-32768.5)_AlwaysFails") { - let input = getFloat32(-32768.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat32(-128.5)_NeverTraps") { - let input = getFloat32(-128.5) - let actual = Int64(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat32(-128.5)_AlwaysFails") { - let input = getFloat32(-128.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat32(-0.5)_NeverTraps") { - let input = getFloat32(-0.5) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat32(-0.5)_AlwaysFails") { - let input = getFloat32(-0.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat32(-0.0)_NeverTraps") { - let input = getFloat32(-0.0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat32(-0.0)_NeverFails") { - let input = getFloat32(-0.0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat32(0.0)_NeverTraps") { - let input = getFloat32(0.0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat32(0.0)_NeverFails") { - let input = getFloat32(0.0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat32(0.5)_NeverTraps") { - let input = getFloat32(0.5) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat32(0.5)_AlwaysFails") { - let input = getFloat32(0.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat32(127.5)_NeverTraps") { - let input = getFloat32(127.5) - let actual = Int64(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat32(127.5)_AlwaysFails") { - let input = getFloat32(127.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat32(255.5)_NeverTraps") { - let input = getFloat32(255.5) - let actual = Int64(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat32(255.5)_AlwaysFails") { - let input = getFloat32(255.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat32(32767.5)_NeverTraps") { - let input = getFloat32(32767.5) - let actual = Int64(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat32(32767.5)_AlwaysFails") { - let input = getFloat32(32767.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat32(65535.5)_NeverTraps") { - let input = getFloat32(65535.5) - let actual = Int64(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat32(65535.5)_AlwaysFails") { - let input = getFloat32(65535.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat32(16777215)_NeverTraps") { - let input = getFloat32(16777215) - let actual = Int64(input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat32(16777215)_NeverFails") { - let input = getFloat32(16777215) - let actual = Int64(exactly: input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat32(-.infinity)_AlwaysTraps") { - let input = getFloat32(-.infinity) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat32(-.infinity)_AlwaysFails") { - let input = getFloat32(-.infinity) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat32(+.infinity)_AlwaysTraps") { - let input = getFloat32(+.infinity) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat32(+.infinity)_AlwaysFails") { - let input = getFloat32(+.infinity) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat32(-.nan)_AlwaysTraps") { - let input = getFloat32(-.nan) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat32(-.nan)_AlwaysFails") { - let input = getFloat32(-.nan) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat32(+.nan)_AlwaysTraps") { - let input = getFloat32(+.nan) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat32(+.nan)_AlwaysFails") { - let input = getFloat32(+.nan) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat32(-.signalingNaN)_AlwaysTraps") { - let input = getFloat32(-.signalingNaN) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat32(-.signalingNaN)_AlwaysFails") { - let input = getFloat32(-.signalingNaN) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat32(+.signalingNaN)_AlwaysTraps") { - let input = getFloat32(+.signalingNaN) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat32(+.signalingNaN)_AlwaysFails") { - let input = getFloat32(+.signalingNaN) - let actual = Int64(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt64 +.test("FromFloat32_NeverTraps") +.forEach(in: [ + (getInt64(-16777215), getFloat32(-16777215)), + (getInt64(-32768), getFloat32(-32768.5)), + (getInt64(-128), getFloat32(-128.5)), + (getInt64(+0), getFloat32(-0.5)), + (getInt64(+0), getFloat32(+0)), + (getInt64(+0), getFloat32(-0)), + (getInt64(+0), getFloat32(+0.5)), + (getInt64(+127), getFloat32(+127.5)), + (getInt64(+255), getFloat32(+255.5)), + (getInt64(+32767), getFloat32(+32767.5)), + (getInt64(+65535), getFloat32(+65535.5)), + (getInt64(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, Int64($0.1)) +} + +FixedPointConversion_Debug64_ToInt64 +.test("FromFloat32_NeverFails") +.forEach(in: [ + (getInt64(-16777215), getFloat32(-16777215)), + (getInt64(+0), getFloat32(+0)), + (getInt64(+0), getFloat32(-0)), + (getInt64(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToInt64 +.test("FromFloat32_AlwaysTraps") +.forEach(in: [ + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int64($0)) +} + +FixedPointConversion_Debug64_ToInt64 +.test("FromFloat32_AlwaysFails") +.forEach(in: [ + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-0.5), + getFloat32(+0.5), + getFloat32(+127.5), + getFloat32(+255.5), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectNil(Int64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float64: (-9007199254740991)...(9007199254740991) +// MARK: Float64: (-9007199254740991)...(+9007199254740991) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt64.test("FromFloat64(-9007199254740991)_NeverTraps") { - let input = getFloat64(-9007199254740991) - let actual = Int64(input) - expectEqual(-9007199254740991, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat64(-9007199254740991)_NeverFails") { - let input = getFloat64(-9007199254740991) - let actual = Int64(exactly: input) - expectEqual(-9007199254740991, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat64(-32768.5)_NeverTraps") { - let input = getFloat64(-32768.5) - let actual = Int64(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat64(-32768.5)_AlwaysFails") { - let input = getFloat64(-32768.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat64(-128.5)_NeverTraps") { - let input = getFloat64(-128.5) - let actual = Int64(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat64(-128.5)_AlwaysFails") { - let input = getFloat64(-128.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat64(-0.5)_NeverTraps") { - let input = getFloat64(-0.5) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat64(-0.5)_AlwaysFails") { - let input = getFloat64(-0.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat64(-0.0)_NeverTraps") { - let input = getFloat64(-0.0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat64(-0.0)_NeverFails") { - let input = getFloat64(-0.0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat64(0.0)_NeverTraps") { - let input = getFloat64(0.0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat64(0.0)_NeverFails") { - let input = getFloat64(0.0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat64(0.5)_NeverTraps") { - let input = getFloat64(0.5) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat64(0.5)_AlwaysFails") { - let input = getFloat64(0.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat64(127.5)_NeverTraps") { - let input = getFloat64(127.5) - let actual = Int64(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat64(127.5)_AlwaysFails") { - let input = getFloat64(127.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat64(255.5)_NeverTraps") { - let input = getFloat64(255.5) - let actual = Int64(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat64(255.5)_AlwaysFails") { - let input = getFloat64(255.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat64(32767.5)_NeverTraps") { - let input = getFloat64(32767.5) - let actual = Int64(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat64(32767.5)_AlwaysFails") { - let input = getFloat64(32767.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat64(65535.5)_NeverTraps") { - let input = getFloat64(65535.5) - let actual = Int64(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat64(65535.5)_AlwaysFails") { - let input = getFloat64(65535.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat64(9007199254740991)_NeverTraps") { - let input = getFloat64(9007199254740991) - let actual = Int64(input) - expectEqual(9007199254740991, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat64(9007199254740991)_NeverFails") { - let input = getFloat64(9007199254740991) - let actual = Int64(exactly: input) - expectEqual(9007199254740991, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat64(-.infinity)_AlwaysTraps") { - let input = getFloat64(-.infinity) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat64(-.infinity)_AlwaysFails") { - let input = getFloat64(-.infinity) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat64(+.infinity)_AlwaysTraps") { - let input = getFloat64(+.infinity) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat64(+.infinity)_AlwaysFails") { - let input = getFloat64(+.infinity) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat64(-.nan)_AlwaysTraps") { - let input = getFloat64(-.nan) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat64(-.nan)_AlwaysFails") { - let input = getFloat64(-.nan) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat64(+.nan)_AlwaysTraps") { - let input = getFloat64(+.nan) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat64(+.nan)_AlwaysFails") { - let input = getFloat64(+.nan) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat64(-.signalingNaN)_AlwaysTraps") { - let input = getFloat64(-.signalingNaN) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat64(-.signalingNaN)_AlwaysFails") { - let input = getFloat64(-.signalingNaN) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat64(+.signalingNaN)_AlwaysTraps") { - let input = getFloat64(+.signalingNaN) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat64(+.signalingNaN)_AlwaysFails") { - let input = getFloat64(+.signalingNaN) - let actual = Int64(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt64 +.test("FromFloat64_NeverTraps") +.forEach(in: [ + (getInt64(-9007199254740991), getFloat64(-9007199254740991)), + (getInt64(-32768), getFloat64(-32768.5)), + (getInt64(-128), getFloat64(-128.5)), + (getInt64(+0), getFloat64(-0.5)), + (getInt64(+0), getFloat64(+0)), + (getInt64(+0), getFloat64(-0)), + (getInt64(+0), getFloat64(+0.5)), + (getInt64(+127), getFloat64(+127.5)), + (getInt64(+255), getFloat64(+255.5)), + (getInt64(+32767), getFloat64(+32767.5)), + (getInt64(+65535), getFloat64(+65535.5)), + (getInt64(+9007199254740991), getFloat64(+9007199254740991)), +]) { + expectEqual($0.0, Int64($0.1)) +} + +FixedPointConversion_Debug64_ToInt64 +.test("FromFloat64_NeverFails") +.forEach(in: [ + (getInt64(-9007199254740991), getFloat64(-9007199254740991)), + (getInt64(+0), getFloat64(+0)), + (getInt64(+0), getFloat64(-0)), + (getInt64(+9007199254740991), getFloat64(+9007199254740991)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToInt64 +.test("FromFloat64_AlwaysTraps") +.forEach(in: [ + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int64($0)) +} + +FixedPointConversion_Debug64_ToInt64 +.test("FromFloat64_AlwaysFails") +.forEach(in: [ + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-0.5), + getFloat64(+0.5), + getFloat64(+127.5), + getFloat64(+255.5), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectNil(Int64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float80: (-18446744073709551615)...(18446744073709551615) +// MARK: Float80: (-18446744073709551615)...(+18446744073709551615) //===----------------------------------------------------------------------===// #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(-18446744073709551615)_AlwaysTraps") { - let input = getFloat80(-18446744073709551615) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(-18446744073709551615)_AlwaysFails") { - let input = getFloat80(-18446744073709551615) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(-9223372036854775809)_AlwaysTraps") { - let input = getFloat80(-9223372036854775809) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(-9223372036854775809)_AlwaysFails") { - let input = getFloat80(-9223372036854775809) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(-9223372036854775808)_NeverTraps") { - let input = getFloat80(-9223372036854775808) - let actual = Int64(input) - expectEqual(-9223372036854775808, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(-9223372036854775808)_NeverFails") { - let input = getFloat80(-9223372036854775808) - let actual = Int64(exactly: input) - expectEqual(-9223372036854775808, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(-32768.5)_NeverTraps") { - let input = getFloat80(-32768.5) - let actual = Int64(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(-32768.5)_AlwaysFails") { - let input = getFloat80(-32768.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(-128.5)_NeverTraps") { - let input = getFloat80(-128.5) - let actual = Int64(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(-128.5)_AlwaysFails") { - let input = getFloat80(-128.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(-0.5)_NeverTraps") { - let input = getFloat80(-0.5) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(-0.5)_AlwaysFails") { - let input = getFloat80(-0.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(-0.0)_NeverTraps") { - let input = getFloat80(-0.0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(-0.0)_NeverFails") { - let input = getFloat80(-0.0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(0.0)_NeverTraps") { - let input = getFloat80(0.0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(0.0)_NeverFails") { - let input = getFloat80(0.0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(0.5)_NeverTraps") { - let input = getFloat80(0.5) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(0.5)_AlwaysFails") { - let input = getFloat80(0.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(127.5)_NeverTraps") { - let input = getFloat80(127.5) - let actual = Int64(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(127.5)_AlwaysFails") { - let input = getFloat80(127.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(255.5)_NeverTraps") { - let input = getFloat80(255.5) - let actual = Int64(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(255.5)_AlwaysFails") { - let input = getFloat80(255.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(32767.5)_NeverTraps") { - let input = getFloat80(32767.5) - let actual = Int64(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(32767.5)_AlwaysFails") { - let input = getFloat80(32767.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(65535.5)_NeverTraps") { - let input = getFloat80(65535.5) - let actual = Int64(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(65535.5)_AlwaysFails") { - let input = getFloat80(65535.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(9223372036854775807)_NeverTraps") { - let input = getFloat80(9223372036854775807) - let actual = Int64(input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(9223372036854775807)_NeverFails") { - let input = getFloat80(9223372036854775807) - let actual = Int64(exactly: input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(9223372036854775808)_AlwaysTraps") { - let input = getFloat80(9223372036854775808) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(9223372036854775808)_AlwaysFails") { - let input = getFloat80(9223372036854775808) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(18446744073709551615)_AlwaysTraps") { - let input = getFloat80(18446744073709551615) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(18446744073709551615)_AlwaysFails") { - let input = getFloat80(18446744073709551615) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(-.infinity)_AlwaysTraps") { - let input = getFloat80(-.infinity) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(-.infinity)_AlwaysFails") { - let input = getFloat80(-.infinity) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(+.infinity)_AlwaysTraps") { - let input = getFloat80(+.infinity) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(+.infinity)_AlwaysFails") { - let input = getFloat80(+.infinity) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(-.nan)_AlwaysTraps") { - let input = getFloat80(-.nan) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(-.nan)_AlwaysFails") { - let input = getFloat80(-.nan) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(+.nan)_AlwaysTraps") { - let input = getFloat80(+.nan) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(+.nan)_AlwaysFails") { - let input = getFloat80(+.nan) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(-.signalingNaN)_AlwaysTraps") { - let input = getFloat80(-.signalingNaN) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(-.signalingNaN)_AlwaysFails") { - let input = getFloat80(-.signalingNaN) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(+.signalingNaN)_AlwaysTraps") { - let input = getFloat80(+.signalingNaN) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt64.test("FromFloat80(+.signalingNaN)_AlwaysFails") { - let input = getFloat80(+.signalingNaN) - let actual = Int64(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt64 +.test("FromFloat80_NeverTraps") +.forEach(in: [ + (getInt64(-9223372036854775808), getFloat80(-9223372036854775808)), + (getInt64(-32768), getFloat80(-32768.5)), + (getInt64(-128), getFloat80(-128.5)), + (getInt64(+0), getFloat80(-0.5)), + (getInt64(+0), getFloat80(-0)), + (getInt64(+0), getFloat80(+0)), + (getInt64(+0), getFloat80(+0.5)), + (getInt64(+127), getFloat80(+127.5)), + (getInt64(+255), getFloat80(+255.5)), + (getInt64(+32767), getFloat80(+32767.5)), + (getInt64(+65535), getFloat80(+65535.5)), + (getInt64(+9223372036854775807), getFloat80(+9223372036854775807)), +]) { + expectEqual($0.0, Int64($0.1)) +} + +FixedPointConversion_Debug64_ToInt64 +.test("FromFloat80_NeverFails") +.forEach(in: [ + (getInt64(-9223372036854775808), getFloat80(-9223372036854775808)), + (getInt64(+0), getFloat80(-0)), + (getInt64(+0), getFloat80(+0)), + (getInt64(+9223372036854775807), getFloat80(+9223372036854775807)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToInt64 +.test("FromFloat80_AlwaysTraps") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-9223372036854775809), + getFloat80(+9223372036854775808), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int64($0)) +} + +FixedPointConversion_Debug64_ToInt64 +.test("FromFloat80_AlwaysFails") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-9223372036854775809), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-0.5), + getFloat80(+0.5), + getFloat80(+127.5), + getFloat80(+255.5), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(+9223372036854775808), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectNil(Int64(exactly: $0)) } #endif // Float80 diff --git a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug64_ToInt8.swift b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug64_ToInt8.swift index b09a002397989..2dd877e561a4c 100644 --- a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug64_ToInt8.swift +++ b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug64_ToInt8.swift @@ -14,1860 +14,735 @@ import StdlibUnittest -let FixedPointConversion_Debug64_ToInt8 = TestSuite("FixedPointConversion_Debug64_ToInt8") +let FixedPointConversion_Debug64_ToInt8 = TestSuite( + "FixedPointConversion_Debug64_ToInt8" +) //===----------------------------------------------------------------------===// -// MARK: UInt8: (0)...(255) +// MARK: UInt8: (+0)...(+255) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt8.test("FromUInt8(0)_NeverTraps") { - let input = getUInt8(0) - let actual = Int8(input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToInt8 +.test("FromUInt8_NeverTraps") +.forEach(in: [ + (getInt8(+0), getUInt8(+0)), + (getInt8(+127), getUInt8(+127)), +]) { + expectEqual($0.0, Int8($0.1)) } -FixedPointConversion_Debug64_ToInt8.test("FromUInt8(0)_NeverFails") { - let input = getUInt8(0) - let actual = Int8(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToInt8 +.test("FromUInt8_NeverFails") +.forEach(in: [ + (getInt8(+0), getUInt8(+0)), + (getInt8(+127), getUInt8(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) } -FixedPointConversion_Debug64_ToInt8.test("FromUInt8(127)_NeverTraps") { - let input = getUInt8(127) - let actual = Int8(input) - expectEqual(127, actual) +FixedPointConversion_Debug64_ToInt8 +.test("FromUInt8_AlwaysTraps") +.forEach(in: [ + getUInt8(+128), + getUInt8(+255), +]) { + expectCrashLater() + _blackHole(Int8($0)) } -FixedPointConversion_Debug64_ToInt8.test("FromUInt8(127)_NeverFails") { - let input = getUInt8(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromUInt8(128)_AlwaysTraps") { - let input = getUInt8(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromUInt8(128)_AlwaysFails") { - let input = getUInt8(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromUInt8(255)_AlwaysTraps") { - let input = getUInt8(255) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromUInt8(255)_AlwaysFails") { - let input = getUInt8(255) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt8 +.test("FromUInt8_AlwaysFails") +.forEach(in: [ + getUInt8(+128), + getUInt8(+255), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int8: (-128)...(127) +// MARK: Int8: (-128)...(+127) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt8.test("FromInt8(-128)_NeverTraps") { - let input = getInt8(-128) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt8(-128)_NeverFails") { - let input = getInt8(-128) - let actual = Int8(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt8(0)_NeverTraps") { - let input = getInt8(0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt8(0)_NeverFails") { - let input = getInt8(0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt8(127)_NeverTraps") { - let input = getInt8(127) - let actual = Int8(input) - expectEqual(127, actual) +FixedPointConversion_Debug64_ToInt8 +.test("FromInt8_NeverTraps") +.forEach(in: [ + (getInt8(-128), getInt8(-128)), + (getInt8(+0), getInt8(+0)), + (getInt8(+127), getInt8(+127)), +]) { + expectEqual($0.0, Int8($0.1)) } -FixedPointConversion_Debug64_ToInt8.test("FromInt8(127)_NeverFails") { - let input = getInt8(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Debug64_ToInt8 +.test("FromInt8_NeverFails") +.forEach(in: [ + (getInt8(-128), getInt8(-128)), + (getInt8(+0), getInt8(+0)), + (getInt8(+127), getInt8(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt16: (0)...(65535) +// MARK: UInt16: (+0)...(+65535) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt8.test("FromUInt16(0)_NeverTraps") { - let input = getUInt16(0) - let actual = Int8(input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToInt8 +.test("FromUInt16_NeverTraps") +.forEach(in: [ + (getInt8(+0), getUInt16(+0)), + (getInt8(+127), getUInt16(+127)), +]) { + expectEqual($0.0, Int8($0.1)) } -FixedPointConversion_Debug64_ToInt8.test("FromUInt16(0)_NeverFails") { - let input = getUInt16(0) - let actual = Int8(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToInt8 +.test("FromUInt16_NeverFails") +.forEach(in: [ + (getInt8(+0), getUInt16(+0)), + (getInt8(+127), getUInt16(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) } -FixedPointConversion_Debug64_ToInt8.test("FromUInt16(127)_NeverTraps") { - let input = getUInt16(127) - let actual = Int8(input) - expectEqual(127, actual) +FixedPointConversion_Debug64_ToInt8 +.test("FromUInt16_AlwaysTraps") +.forEach(in: [ + getUInt16(+128), + getUInt16(+65535), +]) { + expectCrashLater() + _blackHole(Int8($0)) } -FixedPointConversion_Debug64_ToInt8.test("FromUInt16(127)_NeverFails") { - let input = getUInt16(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromUInt16(128)_AlwaysTraps") { - let input = getUInt16(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromUInt16(128)_AlwaysFails") { - let input = getUInt16(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromUInt16(65535)_AlwaysTraps") { - let input = getUInt16(65535) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromUInt16(65535)_AlwaysFails") { - let input = getUInt16(65535) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt8 +.test("FromUInt16_AlwaysFails") +.forEach(in: [ + getUInt16(+128), + getUInt16(+65535), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int16: (-32768)...(32767) +// MARK: Int16: (-32768)...(+32767) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt8.test("FromInt16(-32768)_AlwaysTraps") { - let input = getInt16(-32768) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt16(-32768)_AlwaysFails") { - let input = getInt16(-32768) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt16(-129)_AlwaysTraps") { - let input = getInt16(-129) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt16(-129)_AlwaysFails") { - let input = getInt16(-129) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt16(-128)_NeverTraps") { - let input = getInt16(-128) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt16(-128)_NeverFails") { - let input = getInt16(-128) - let actual = Int8(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt16(0)_NeverTraps") { - let input = getInt16(0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt16(0)_NeverFails") { - let input = getInt16(0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt16(127)_NeverTraps") { - let input = getInt16(127) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt16(127)_NeverFails") { - let input = getInt16(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt16(128)_AlwaysTraps") { - let input = getInt16(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt16(128)_AlwaysFails") { - let input = getInt16(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt16(32767)_AlwaysTraps") { - let input = getInt16(32767) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt16(32767)_AlwaysFails") { - let input = getInt16(32767) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt8 +.test("FromInt16_NeverTraps") +.forEach(in: [ + (getInt8(-128), getInt16(-128)), + (getInt8(+0), getInt16(+0)), + (getInt8(+127), getInt16(+127)), +]) { + expectEqual($0.0, Int8($0.1)) +} + +FixedPointConversion_Debug64_ToInt8 +.test("FromInt16_NeverFails") +.forEach(in: [ + (getInt8(-128), getInt16(-128)), + (getInt8(+0), getInt16(+0)), + (getInt8(+127), getInt16(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToInt8 +.test("FromInt16_AlwaysTraps") +.forEach(in: [ + getInt16(-32768), + getInt16(-129), + getInt16(+128), + getInt16(+32767), +]) { + expectCrashLater() + _blackHole(Int8($0)) +} + +FixedPointConversion_Debug64_ToInt8 +.test("FromInt16_AlwaysFails") +.forEach(in: [ + getInt16(-32768), + getInt16(-129), + getInt16(+128), + getInt16(+32767), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt32: (0)...(4294967295) +// MARK: UInt32: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt8.test("FromUInt32(0)_NeverTraps") { - let input = getUInt32(0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromUInt32(0)_NeverFails") { - let input = getUInt32(0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromUInt32(127)_NeverTraps") { - let input = getUInt32(127) - let actual = Int8(input) - expectEqual(127, actual) +FixedPointConversion_Debug64_ToInt8 +.test("FromUInt32_NeverTraps") +.forEach(in: [ + (getInt8(+0), getUInt32(+0)), + (getInt8(+127), getUInt32(+127)), +]) { + expectEqual($0.0, Int8($0.1)) } -FixedPointConversion_Debug64_ToInt8.test("FromUInt32(127)_NeverFails") { - let input = getUInt32(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Debug64_ToInt8 +.test("FromUInt32_NeverFails") +.forEach(in: [ + (getInt8(+0), getUInt32(+0)), + (getInt8(+127), getUInt32(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) } -FixedPointConversion_Debug64_ToInt8.test("FromUInt32(128)_AlwaysTraps") { - let input = getUInt32(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } +FixedPointConversion_Debug64_ToInt8 +.test("FromUInt32_AlwaysTraps") +.forEach(in: [ + getUInt32(+128), + getUInt32(+4294967295), +]) { + expectCrashLater() + _blackHole(Int8($0)) } -FixedPointConversion_Debug64_ToInt8.test("FromUInt32(128)_AlwaysFails") { - let input = getUInt32(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromUInt32(4294967295)_AlwaysTraps") { - let input = getUInt32(4294967295) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromUInt32(4294967295)_AlwaysFails") { - let input = getUInt32(4294967295) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt8 +.test("FromUInt32_AlwaysFails") +.forEach(in: [ + getUInt32(+128), + getUInt32(+4294967295), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int32: (-2147483648)...(2147483647) +// MARK: Int32: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt8.test("FromInt32(-2147483648)_AlwaysTraps") { - let input = getInt32(-2147483648) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt32(-2147483648)_AlwaysFails") { - let input = getInt32(-2147483648) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt32(-129)_AlwaysTraps") { - let input = getInt32(-129) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt32(-129)_AlwaysFails") { - let input = getInt32(-129) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt32(-128)_NeverTraps") { - let input = getInt32(-128) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt32(-128)_NeverFails") { - let input = getInt32(-128) - let actual = Int8(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt32(0)_NeverTraps") { - let input = getInt32(0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt32(0)_NeverFails") { - let input = getInt32(0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt32(127)_NeverTraps") { - let input = getInt32(127) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt32(127)_NeverFails") { - let input = getInt32(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt32(128)_AlwaysTraps") { - let input = getInt32(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt32(128)_AlwaysFails") { - let input = getInt32(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt32(2147483647)_AlwaysTraps") { - let input = getInt32(2147483647) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt32(2147483647)_AlwaysFails") { - let input = getInt32(2147483647) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt8 +.test("FromInt32_NeverTraps") +.forEach(in: [ + (getInt8(-128), getInt32(-128)), + (getInt8(+0), getInt32(+0)), + (getInt8(+127), getInt32(+127)), +]) { + expectEqual($0.0, Int8($0.1)) +} + +FixedPointConversion_Debug64_ToInt8 +.test("FromInt32_NeverFails") +.forEach(in: [ + (getInt8(-128), getInt32(-128)), + (getInt8(+0), getInt32(+0)), + (getInt8(+127), getInt32(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToInt8 +.test("FromInt32_AlwaysTraps") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-129), + getInt32(+128), + getInt32(+2147483647), +]) { + expectCrashLater() + _blackHole(Int8($0)) +} + +FixedPointConversion_Debug64_ToInt8 +.test("FromInt32_AlwaysFails") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-129), + getInt32(+128), + getInt32(+2147483647), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt64: (0)...(18446744073709551615) +// MARK: UInt64: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt8.test("FromUInt64(0)_NeverTraps") { - let input = getUInt64(0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromUInt64(0)_NeverFails") { - let input = getUInt64(0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromUInt64(127)_NeverTraps") { - let input = getUInt64(127) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromUInt64(127)_NeverFails") { - let input = getUInt64(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromUInt64(128)_AlwaysTraps") { - let input = getUInt64(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } +FixedPointConversion_Debug64_ToInt8 +.test("FromUInt64_NeverTraps") +.forEach(in: [ + (getInt8(+0), getUInt64(+0)), + (getInt8(+127), getUInt64(+127)), +]) { + expectEqual($0.0, Int8($0.1)) } -FixedPointConversion_Debug64_ToInt8.test("FromUInt64(128)_AlwaysFails") { - let input = getUInt64(128) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt8 +.test("FromUInt64_NeverFails") +.forEach(in: [ + (getInt8(+0), getUInt64(+0)), + (getInt8(+127), getUInt64(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) } -FixedPointConversion_Debug64_ToInt8.test("FromUInt64(18446744073709551615)_AlwaysTraps") { - let input = getUInt64(18446744073709551615) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } +FixedPointConversion_Debug64_ToInt8 +.test("FromUInt64_AlwaysTraps") +.forEach(in: [ + getUInt64(+128), + getUInt64(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(Int8($0)) } -FixedPointConversion_Debug64_ToInt8.test("FromUInt64(18446744073709551615)_AlwaysFails") { - let input = getUInt64(18446744073709551615) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt8 +.test("FromUInt64_AlwaysFails") +.forEach(in: [ + getUInt64(+128), + getUInt64(+18446744073709551615), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int64: (-9223372036854775808)...(9223372036854775807) +// MARK: Int64: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt8.test("FromInt64(-9223372036854775808)_AlwaysTraps") { - let input = getInt64(-9223372036854775808) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt64(-9223372036854775808)_AlwaysFails") { - let input = getInt64(-9223372036854775808) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt64(-129)_AlwaysTraps") { - let input = getInt64(-129) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt64(-129)_AlwaysFails") { - let input = getInt64(-129) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt64(-128)_NeverTraps") { - let input = getInt64(-128) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt64(-128)_NeverFails") { - let input = getInt64(-128) - let actual = Int8(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt64(0)_NeverTraps") { - let input = getInt64(0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt64(0)_NeverFails") { - let input = getInt64(0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt64(127)_NeverTraps") { - let input = getInt64(127) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt64(127)_NeverFails") { - let input = getInt64(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt64(128)_AlwaysTraps") { - let input = getInt64(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt64(128)_AlwaysFails") { - let input = getInt64(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt64(9223372036854775807)_AlwaysTraps") { - let input = getInt64(9223372036854775807) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt64(9223372036854775807)_AlwaysFails") { - let input = getInt64(9223372036854775807) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt8 +.test("FromInt64_NeverTraps") +.forEach(in: [ + (getInt8(-128), getInt64(-128)), + (getInt8(+0), getInt64(+0)), + (getInt8(+127), getInt64(+127)), +]) { + expectEqual($0.0, Int8($0.1)) +} + +FixedPointConversion_Debug64_ToInt8 +.test("FromInt64_NeverFails") +.forEach(in: [ + (getInt8(-128), getInt64(-128)), + (getInt8(+0), getInt64(+0)), + (getInt8(+127), getInt64(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToInt8 +.test("FromInt64_AlwaysTraps") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-129), + getInt64(+128), + getInt64(+9223372036854775807), +]) { + expectCrashLater() + _blackHole(Int8($0)) +} + +FixedPointConversion_Debug64_ToInt8 +.test("FromInt64_AlwaysFails") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-129), + getInt64(+128), + getInt64(+9223372036854775807), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt: (0)...(18446744073709551615) +// MARK: UInt: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt8.test("FromUInt(0)_NeverTraps") { - let input = getUInt(0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromUInt(0)_NeverFails") { - let input = getUInt(0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromUInt(127)_NeverTraps") { - let input = getUInt(127) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromUInt(127)_NeverFails") { - let input = getUInt(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromUInt(128)_AlwaysTraps") { - let input = getUInt(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } +FixedPointConversion_Debug64_ToInt8 +.test("FromUInt_NeverTraps") +.forEach(in: [ + (getInt8(+0), getUInt(+0)), + (getInt8(+127), getUInt(+127)), +]) { + expectEqual($0.0, Int8($0.1)) } -FixedPointConversion_Debug64_ToInt8.test("FromUInt(128)_AlwaysFails") { - let input = getUInt(128) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt8 +.test("FromUInt_NeverFails") +.forEach(in: [ + (getInt8(+0), getUInt(+0)), + (getInt8(+127), getUInt(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) } -FixedPointConversion_Debug64_ToInt8.test("FromUInt(18446744073709551615)_AlwaysTraps") { - let input = getUInt(18446744073709551615) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } +FixedPointConversion_Debug64_ToInt8 +.test("FromUInt_AlwaysTraps") +.forEach(in: [ + getUInt(+128), + getUInt(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(Int8($0)) } -FixedPointConversion_Debug64_ToInt8.test("FromUInt(18446744073709551615)_AlwaysFails") { - let input = getUInt(18446744073709551615) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt8 +.test("FromUInt_AlwaysFails") +.forEach(in: [ + getUInt(+128), + getUInt(+18446744073709551615), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int: (-9223372036854775808)...(9223372036854775807) +// MARK: Int: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt8.test("FromInt(-9223372036854775808)_AlwaysTraps") { - let input = getInt(-9223372036854775808) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt(-9223372036854775808)_AlwaysFails") { - let input = getInt(-9223372036854775808) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt(-129)_AlwaysTraps") { - let input = getInt(-129) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt(-129)_AlwaysFails") { - let input = getInt(-129) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt(-128)_NeverTraps") { - let input = getInt(-128) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt(-128)_NeverFails") { - let input = getInt(-128) - let actual = Int8(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt(0)_NeverTraps") { - let input = getInt(0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt(0)_NeverFails") { - let input = getInt(0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt(127)_NeverTraps") { - let input = getInt(127) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt(127)_NeverFails") { - let input = getInt(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt(128)_AlwaysTraps") { - let input = getInt(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt(128)_AlwaysFails") { - let input = getInt(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt(9223372036854775807)_AlwaysTraps") { - let input = getInt(9223372036854775807) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromInt(9223372036854775807)_AlwaysFails") { - let input = getInt(9223372036854775807) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt8 +.test("FromInt_NeverTraps") +.forEach(in: [ + (getInt8(-128), getInt(-128)), + (getInt8(+0), getInt(+0)), + (getInt8(+127), getInt(+127)), +]) { + expectEqual($0.0, Int8($0.1)) +} + +FixedPointConversion_Debug64_ToInt8 +.test("FromInt_NeverFails") +.forEach(in: [ + (getInt8(-128), getInt(-128)), + (getInt8(+0), getInt(+0)), + (getInt8(+127), getInt(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToInt8 +.test("FromInt_AlwaysTraps") +.forEach(in: [ + getInt(-9223372036854775808), + getInt(-129), + getInt(+128), + getInt(+9223372036854775807), +]) { + expectCrashLater() + _blackHole(Int8($0)) +} + +FixedPointConversion_Debug64_ToInt8 +.test("FromInt_AlwaysFails") +.forEach(in: [ + getInt(-9223372036854775808), + getInt(-129), + getInt(+128), + getInt(+9223372036854775807), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float16: (-2047)...(2047) +// MARK: Float16: (-2047)...(+2047) //===----------------------------------------------------------------------===// #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -FixedPointConversion_Debug64_ToInt8.test("FromFloat16(-2047)_AlwaysTraps") { - let input = getFloat16(-2047) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat16(-2047)_AlwaysFails") { - let input = getFloat16(-2047) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat16(-129)_AlwaysTraps") { - let input = getFloat16(-129) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat16(-129)_AlwaysFails") { - let input = getFloat16(-129) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat16(-128.5)_NeverTraps") { - let input = getFloat16(-128.5) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat16(-128.5)_AlwaysFails") { - let input = getFloat16(-128.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat16(-128)_NeverTraps") { - let input = getFloat16(-128) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat16(-128)_NeverFails") { - let input = getFloat16(-128) - let actual = Int8(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat16(-0.5)_NeverTraps") { - let input = getFloat16(-0.5) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat16(-0.5)_AlwaysFails") { - let input = getFloat16(-0.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat16(-0.0)_NeverTraps") { - let input = getFloat16(-0.0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat16(-0.0)_NeverFails") { - let input = getFloat16(-0.0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat16(0.0)_NeverTraps") { - let input = getFloat16(0.0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat16(0.0)_NeverFails") { - let input = getFloat16(0.0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat16(0.5)_NeverTraps") { - let input = getFloat16(0.5) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat16(0.5)_AlwaysFails") { - let input = getFloat16(0.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat16(127)_NeverTraps") { - let input = getFloat16(127) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat16(127)_NeverFails") { - let input = getFloat16(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat16(127.5)_NeverTraps") { - let input = getFloat16(127.5) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat16(127.5)_AlwaysFails") { - let input = getFloat16(127.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat16(128)_AlwaysTraps") { - let input = getFloat16(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat16(128)_AlwaysFails") { - let input = getFloat16(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat16(255.5)_AlwaysTraps") { - let input = getFloat16(255.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat16(255.5)_AlwaysFails") { - let input = getFloat16(255.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat16(2047)_AlwaysTraps") { - let input = getFloat16(2047) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat16(2047)_AlwaysFails") { - let input = getFloat16(2047) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat16(-.infinity)_AlwaysTraps") { - let input = getFloat16(-.infinity) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat16(-.infinity)_AlwaysFails") { - let input = getFloat16(-.infinity) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat16(+.infinity)_AlwaysTraps") { - let input = getFloat16(+.infinity) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat16(+.infinity)_AlwaysFails") { - let input = getFloat16(+.infinity) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat16(-.nan)_AlwaysTraps") { - let input = getFloat16(-.nan) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat16(-.nan)_AlwaysFails") { - let input = getFloat16(-.nan) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat16(+.nan)_AlwaysTraps") { - let input = getFloat16(+.nan) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat16(+.nan)_AlwaysFails") { - let input = getFloat16(+.nan) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat16(-.signalingNaN)_AlwaysTraps") { - let input = getFloat16(-.signalingNaN) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat16(-.signalingNaN)_AlwaysFails") { - let input = getFloat16(-.signalingNaN) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat16(+.signalingNaN)_AlwaysTraps") { - let input = getFloat16(+.signalingNaN) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat16(+.signalingNaN)_AlwaysFails") { - let input = getFloat16(+.signalingNaN) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt8 +.test("FromFloat16_NeverTraps") +.forEach(in: [ + (getInt8(-128), getFloat16(-128.5)), + (getInt8(-128), getFloat16(-128)), + (getInt8(+0), getFloat16(-0.5)), + (getInt8(+0), getFloat16(-0)), + (getInt8(+0), getFloat16(+0)), + (getInt8(+0), getFloat16(+0.5)), + (getInt8(+127), getFloat16(+127)), + (getInt8(+127), getFloat16(+127.5)), +]) { + expectEqual($0.0, Int8($0.1)) +} + +FixedPointConversion_Debug64_ToInt8 +.test("FromFloat16_NeverFails") +.forEach(in: [ + (getInt8(-128), getFloat16(-128)), + (getInt8(+0), getFloat16(-0)), + (getInt8(+0), getFloat16(+0)), + (getInt8(+127), getFloat16(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToInt8 +.test("FromFloat16_AlwaysTraps") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-129), + getFloat16(+128), + getFloat16(+255.5), + getFloat16(+2047), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int8($0)) +} + +FixedPointConversion_Debug64_ToInt8 +.test("FromFloat16_AlwaysFails") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-129), + getFloat16(-128.5), + getFloat16(-0.5), + getFloat16(+0.5), + getFloat16(+127.5), + getFloat16(+128), + getFloat16(+255.5), + getFloat16(+2047), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectNil(Int8(exactly: $0)) } } #endif // Float16 //===----------------------------------------------------------------------===// -// MARK: Float32: (-16777215)...(16777215) +// MARK: Float32: (-16777215)...(+16777215) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(-16777215)_AlwaysTraps") { - let input = getFloat32(-16777215) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(-16777215)_AlwaysFails") { - let input = getFloat32(-16777215) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(-32768.5)_AlwaysTraps") { - let input = getFloat32(-32768.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(-32768.5)_AlwaysFails") { - let input = getFloat32(-32768.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(-129)_AlwaysTraps") { - let input = getFloat32(-129) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(-129)_AlwaysFails") { - let input = getFloat32(-129) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(-128.5)_NeverTraps") { - let input = getFloat32(-128.5) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(-128.5)_AlwaysFails") { - let input = getFloat32(-128.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(-128)_NeverTraps") { - let input = getFloat32(-128) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(-128)_NeverFails") { - let input = getFloat32(-128) - let actual = Int8(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(-0.5)_NeverTraps") { - let input = getFloat32(-0.5) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(-0.5)_AlwaysFails") { - let input = getFloat32(-0.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(-0.0)_NeverTraps") { - let input = getFloat32(-0.0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(-0.0)_NeverFails") { - let input = getFloat32(-0.0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(0.0)_NeverTraps") { - let input = getFloat32(0.0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(0.0)_NeverFails") { - let input = getFloat32(0.0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(0.5)_NeverTraps") { - let input = getFloat32(0.5) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(0.5)_AlwaysFails") { - let input = getFloat32(0.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(127)_NeverTraps") { - let input = getFloat32(127) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(127)_NeverFails") { - let input = getFloat32(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(127.5)_NeverTraps") { - let input = getFloat32(127.5) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(127.5)_AlwaysFails") { - let input = getFloat32(127.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(128)_AlwaysTraps") { - let input = getFloat32(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(128)_AlwaysFails") { - let input = getFloat32(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(255.5)_AlwaysTraps") { - let input = getFloat32(255.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(255.5)_AlwaysFails") { - let input = getFloat32(255.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(32767.5)_AlwaysTraps") { - let input = getFloat32(32767.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(32767.5)_AlwaysFails") { - let input = getFloat32(32767.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(65535.5)_AlwaysTraps") { - let input = getFloat32(65535.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(65535.5)_AlwaysFails") { - let input = getFloat32(65535.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(16777215)_AlwaysTraps") { - let input = getFloat32(16777215) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(16777215)_AlwaysFails") { - let input = getFloat32(16777215) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(-.infinity)_AlwaysTraps") { - let input = getFloat32(-.infinity) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(-.infinity)_AlwaysFails") { - let input = getFloat32(-.infinity) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(+.infinity)_AlwaysTraps") { - let input = getFloat32(+.infinity) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(+.infinity)_AlwaysFails") { - let input = getFloat32(+.infinity) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(-.nan)_AlwaysTraps") { - let input = getFloat32(-.nan) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(-.nan)_AlwaysFails") { - let input = getFloat32(-.nan) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(+.nan)_AlwaysTraps") { - let input = getFloat32(+.nan) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(+.nan)_AlwaysFails") { - let input = getFloat32(+.nan) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(-.signalingNaN)_AlwaysTraps") { - let input = getFloat32(-.signalingNaN) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(-.signalingNaN)_AlwaysFails") { - let input = getFloat32(-.signalingNaN) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(+.signalingNaN)_AlwaysTraps") { - let input = getFloat32(+.signalingNaN) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat32(+.signalingNaN)_AlwaysFails") { - let input = getFloat32(+.signalingNaN) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt8 +.test("FromFloat32_NeverTraps") +.forEach(in: [ + (getInt8(-128), getFloat32(-128.5)), + (getInt8(-128), getFloat32(-128)), + (getInt8(+0), getFloat32(-0.5)), + (getInt8(+0), getFloat32(+0)), + (getInt8(+0), getFloat32(-0)), + (getInt8(+0), getFloat32(+0.5)), + (getInt8(+127), getFloat32(+127)), + (getInt8(+127), getFloat32(+127.5)), +]) { + expectEqual($0.0, Int8($0.1)) +} + +FixedPointConversion_Debug64_ToInt8 +.test("FromFloat32_NeverFails") +.forEach(in: [ + (getInt8(-128), getFloat32(-128)), + (getInt8(+0), getFloat32(+0)), + (getInt8(+0), getFloat32(-0)), + (getInt8(+127), getFloat32(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToInt8 +.test("FromFloat32_AlwaysTraps") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-129), + getFloat32(+128), + getFloat32(+255.5), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(+16777215), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int8($0)) +} + +FixedPointConversion_Debug64_ToInt8 +.test("FromFloat32_AlwaysFails") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-129), + getFloat32(-128.5), + getFloat32(-0.5), + getFloat32(+0.5), + getFloat32(+127.5), + getFloat32(+128), + getFloat32(+255.5), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(+16777215), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float64: (-9007199254740991)...(9007199254740991) +// MARK: Float64: (-9007199254740991)...(+9007199254740991) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(-9007199254740991)_AlwaysTraps") { - let input = getFloat64(-9007199254740991) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(-9007199254740991)_AlwaysFails") { - let input = getFloat64(-9007199254740991) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(-32768.5)_AlwaysTraps") { - let input = getFloat64(-32768.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(-32768.5)_AlwaysFails") { - let input = getFloat64(-32768.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(-129)_AlwaysTraps") { - let input = getFloat64(-129) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(-129)_AlwaysFails") { - let input = getFloat64(-129) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(-128.5)_NeverTraps") { - let input = getFloat64(-128.5) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(-128.5)_AlwaysFails") { - let input = getFloat64(-128.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(-128)_NeverTraps") { - let input = getFloat64(-128) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(-128)_NeverFails") { - let input = getFloat64(-128) - let actual = Int8(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(-0.5)_NeverTraps") { - let input = getFloat64(-0.5) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(-0.5)_AlwaysFails") { - let input = getFloat64(-0.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(-0.0)_NeverTraps") { - let input = getFloat64(-0.0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(-0.0)_NeverFails") { - let input = getFloat64(-0.0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(0.0)_NeverTraps") { - let input = getFloat64(0.0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(0.0)_NeverFails") { - let input = getFloat64(0.0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(0.5)_NeverTraps") { - let input = getFloat64(0.5) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(0.5)_AlwaysFails") { - let input = getFloat64(0.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(127)_NeverTraps") { - let input = getFloat64(127) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(127)_NeverFails") { - let input = getFloat64(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(127.5)_NeverTraps") { - let input = getFloat64(127.5) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(127.5)_AlwaysFails") { - let input = getFloat64(127.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(128)_AlwaysTraps") { - let input = getFloat64(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(128)_AlwaysFails") { - let input = getFloat64(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(255.5)_AlwaysTraps") { - let input = getFloat64(255.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(255.5)_AlwaysFails") { - let input = getFloat64(255.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(32767.5)_AlwaysTraps") { - let input = getFloat64(32767.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(32767.5)_AlwaysFails") { - let input = getFloat64(32767.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(65535.5)_AlwaysTraps") { - let input = getFloat64(65535.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(65535.5)_AlwaysFails") { - let input = getFloat64(65535.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(9007199254740991)_AlwaysTraps") { - let input = getFloat64(9007199254740991) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(9007199254740991)_AlwaysFails") { - let input = getFloat64(9007199254740991) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(-.infinity)_AlwaysTraps") { - let input = getFloat64(-.infinity) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(-.infinity)_AlwaysFails") { - let input = getFloat64(-.infinity) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(+.infinity)_AlwaysTraps") { - let input = getFloat64(+.infinity) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(+.infinity)_AlwaysFails") { - let input = getFloat64(+.infinity) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(-.nan)_AlwaysTraps") { - let input = getFloat64(-.nan) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(-.nan)_AlwaysFails") { - let input = getFloat64(-.nan) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(+.nan)_AlwaysTraps") { - let input = getFloat64(+.nan) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(+.nan)_AlwaysFails") { - let input = getFloat64(+.nan) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(-.signalingNaN)_AlwaysTraps") { - let input = getFloat64(-.signalingNaN) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(-.signalingNaN)_AlwaysFails") { - let input = getFloat64(-.signalingNaN) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(+.signalingNaN)_AlwaysTraps") { - let input = getFloat64(+.signalingNaN) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat64(+.signalingNaN)_AlwaysFails") { - let input = getFloat64(+.signalingNaN) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt8 +.test("FromFloat64_NeverTraps") +.forEach(in: [ + (getInt8(-128), getFloat64(-128.5)), + (getInt8(-128), getFloat64(-128)), + (getInt8(+0), getFloat64(-0.5)), + (getInt8(+0), getFloat64(+0)), + (getInt8(+0), getFloat64(-0)), + (getInt8(+0), getFloat64(+0.5)), + (getInt8(+127), getFloat64(+127)), + (getInt8(+127), getFloat64(+127.5)), +]) { + expectEqual($0.0, Int8($0.1)) +} + +FixedPointConversion_Debug64_ToInt8 +.test("FromFloat64_NeverFails") +.forEach(in: [ + (getInt8(-128), getFloat64(-128)), + (getInt8(+0), getFloat64(+0)), + (getInt8(+0), getFloat64(-0)), + (getInt8(+127), getFloat64(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToInt8 +.test("FromFloat64_AlwaysTraps") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-129), + getFloat64(+128), + getFloat64(+255.5), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int8($0)) +} + +FixedPointConversion_Debug64_ToInt8 +.test("FromFloat64_AlwaysFails") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-129), + getFloat64(-128.5), + getFloat64(-0.5), + getFloat64(+0.5), + getFloat64(+127.5), + getFloat64(+128), + getFloat64(+255.5), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float80: (-18446744073709551615)...(18446744073709551615) +// MARK: Float80: (-18446744073709551615)...(+18446744073709551615) //===----------------------------------------------------------------------===// #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(-18446744073709551615)_AlwaysTraps") { - let input = getFloat80(-18446744073709551615) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(-18446744073709551615)_AlwaysFails") { - let input = getFloat80(-18446744073709551615) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(-32768.5)_AlwaysTraps") { - let input = getFloat80(-32768.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(-32768.5)_AlwaysFails") { - let input = getFloat80(-32768.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(-129)_AlwaysTraps") { - let input = getFloat80(-129) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(-129)_AlwaysFails") { - let input = getFloat80(-129) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(-128.5)_NeverTraps") { - let input = getFloat80(-128.5) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(-128.5)_AlwaysFails") { - let input = getFloat80(-128.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(-128)_NeverTraps") { - let input = getFloat80(-128) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(-128)_NeverFails") { - let input = getFloat80(-128) - let actual = Int8(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(-0.5)_NeverTraps") { - let input = getFloat80(-0.5) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(-0.5)_AlwaysFails") { - let input = getFloat80(-0.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(-0.0)_NeverTraps") { - let input = getFloat80(-0.0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(-0.0)_NeverFails") { - let input = getFloat80(-0.0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(0.0)_NeverTraps") { - let input = getFloat80(0.0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(0.0)_NeverFails") { - let input = getFloat80(0.0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(0.5)_NeverTraps") { - let input = getFloat80(0.5) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(0.5)_AlwaysFails") { - let input = getFloat80(0.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(127)_NeverTraps") { - let input = getFloat80(127) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(127)_NeverFails") { - let input = getFloat80(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(127.5)_NeverTraps") { - let input = getFloat80(127.5) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(127.5)_AlwaysFails") { - let input = getFloat80(127.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(128)_AlwaysTraps") { - let input = getFloat80(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(128)_AlwaysFails") { - let input = getFloat80(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(255.5)_AlwaysTraps") { - let input = getFloat80(255.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(255.5)_AlwaysFails") { - let input = getFloat80(255.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(32767.5)_AlwaysTraps") { - let input = getFloat80(32767.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(32767.5)_AlwaysFails") { - let input = getFloat80(32767.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(65535.5)_AlwaysTraps") { - let input = getFloat80(65535.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(65535.5)_AlwaysFails") { - let input = getFloat80(65535.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(18446744073709551615)_AlwaysTraps") { - let input = getFloat80(18446744073709551615) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(18446744073709551615)_AlwaysFails") { - let input = getFloat80(18446744073709551615) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(-.infinity)_AlwaysTraps") { - let input = getFloat80(-.infinity) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(-.infinity)_AlwaysFails") { - let input = getFloat80(-.infinity) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(+.infinity)_AlwaysTraps") { - let input = getFloat80(+.infinity) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(+.infinity)_AlwaysFails") { - let input = getFloat80(+.infinity) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(-.nan)_AlwaysTraps") { - let input = getFloat80(-.nan) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(-.nan)_AlwaysFails") { - let input = getFloat80(-.nan) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(+.nan)_AlwaysTraps") { - let input = getFloat80(+.nan) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(+.nan)_AlwaysFails") { - let input = getFloat80(+.nan) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(-.signalingNaN)_AlwaysTraps") { - let input = getFloat80(-.signalingNaN) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(-.signalingNaN)_AlwaysFails") { - let input = getFloat80(-.signalingNaN) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(+.signalingNaN)_AlwaysTraps") { - let input = getFloat80(+.signalingNaN) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToInt8.test("FromFloat80(+.signalingNaN)_AlwaysFails") { - let input = getFloat80(+.signalingNaN) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToInt8 +.test("FromFloat80_NeverTraps") +.forEach(in: [ + (getInt8(-128), getFloat80(-128.5)), + (getInt8(-128), getFloat80(-128)), + (getInt8(+0), getFloat80(-0.5)), + (getInt8(+0), getFloat80(-0)), + (getInt8(+0), getFloat80(+0)), + (getInt8(+0), getFloat80(+0.5)), + (getInt8(+127), getFloat80(+127)), + (getInt8(+127), getFloat80(+127.5)), +]) { + expectEqual($0.0, Int8($0.1)) +} + +FixedPointConversion_Debug64_ToInt8 +.test("FromFloat80_NeverFails") +.forEach(in: [ + (getInt8(-128), getFloat80(-128)), + (getInt8(+0), getFloat80(-0)), + (getInt8(+0), getFloat80(+0)), + (getInt8(+127), getFloat80(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToInt8 +.test("FromFloat80_AlwaysTraps") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-129), + getFloat80(+128), + getFloat80(+255.5), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int8($0)) +} + +FixedPointConversion_Debug64_ToInt8 +.test("FromFloat80_AlwaysFails") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-129), + getFloat80(-128.5), + getFloat80(-0.5), + getFloat80(+0.5), + getFloat80(+127.5), + getFloat80(+128), + getFloat80(+255.5), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectNil(Int8(exactly: $0)) } #endif // Float80 diff --git a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug64_ToUInt.swift b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug64_ToUInt.swift index 54f393206bd31..fb8567f2d7791 100644 --- a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug64_ToUInt.swift +++ b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug64_ToUInt.swift @@ -14,1464 +14,609 @@ import StdlibUnittest -let FixedPointConversion_Debug64_ToUInt = TestSuite("FixedPointConversion_Debug64_ToUInt") +let FixedPointConversion_Debug64_ToUInt = TestSuite( + "FixedPointConversion_Debug64_ToUInt" +) //===----------------------------------------------------------------------===// -// MARK: UInt8: (0)...(255) +// MARK: UInt8: (+0)...(+255) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt.test("FromUInt8(0)_NeverTraps") { - let input = getUInt8(0) - let actual = UInt(input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt +.test("FromUInt8_NeverTraps") +.forEach(in: [ + (getUInt(+0), getUInt8(+0)), + (getUInt(+255), getUInt8(+255)), +]) { + expectEqual($0.0, UInt($0.1)) } -FixedPointConversion_Debug64_ToUInt.test("FromUInt8(0)_NeverFails") { - let input = getUInt8(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromUInt8(255)_NeverTraps") { - let input = getUInt8(255) - let actual = UInt(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromUInt8(255)_NeverFails") { - let input = getUInt8(255) - let actual = UInt(exactly: input) - expectEqual(255, actual) +FixedPointConversion_Debug64_ToUInt +.test("FromUInt8_NeverFails") +.forEach(in: [ + (getUInt(+0), getUInt8(+0)), + (getUInt(+255), getUInt8(+255)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int8: (-128)...(127) +// MARK: Int8: (-128)...(+127) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt.test("FromInt8(-128)_AlwaysTraps") { - let input = getInt8(-128) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromInt8(-128)_AlwaysFails") { - let input = getInt8(-128) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromInt8(-1)_AlwaysTraps") { - let input = getInt8(-1) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromInt8(-1)_AlwaysFails") { - let input = getInt8(-1) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromInt8(0)_NeverTraps") { - let input = getInt8(0) - let actual = UInt(input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt +.test("FromInt8_NeverTraps") +.forEach(in: [ + (getUInt(+0), getInt8(+0)), + (getUInt(+127), getInt8(+127)), +]) { + expectEqual($0.0, UInt($0.1)) } -FixedPointConversion_Debug64_ToUInt.test("FromInt8(0)_NeverFails") { - let input = getInt8(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt +.test("FromInt8_NeverFails") +.forEach(in: [ + (getUInt(+0), getInt8(+0)), + (getUInt(+127), getInt8(+127)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) } -FixedPointConversion_Debug64_ToUInt.test("FromInt8(127)_NeverTraps") { - let input = getInt8(127) - let actual = UInt(input) - expectEqual(127, actual) +FixedPointConversion_Debug64_ToUInt +.test("FromInt8_AlwaysTraps") +.forEach(in: [ + getInt8(-128), + getInt8(-1), +]) { + expectCrashLater() + _blackHole(UInt($0)) } -FixedPointConversion_Debug64_ToUInt.test("FromInt8(127)_NeverFails") { - let input = getInt8(127) - let actual = UInt(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Debug64_ToUInt +.test("FromInt8_AlwaysFails") +.forEach(in: [ + getInt8(-128), + getInt8(-1), +]) { + expectNil(UInt(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt16: (0)...(65535) +// MARK: UInt16: (+0)...(+65535) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt.test("FromUInt16(0)_NeverTraps") { - let input = getUInt16(0) - let actual = UInt(input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt +.test("FromUInt16_NeverTraps") +.forEach(in: [ + (getUInt(+0), getUInt16(+0)), + (getUInt(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, UInt($0.1)) } -FixedPointConversion_Debug64_ToUInt.test("FromUInt16(0)_NeverFails") { - let input = getUInt16(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromUInt16(65535)_NeverTraps") { - let input = getUInt16(65535) - let actual = UInt(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromUInt16(65535)_NeverFails") { - let input = getUInt16(65535) - let actual = UInt(exactly: input) - expectEqual(65535, actual) +FixedPointConversion_Debug64_ToUInt +.test("FromUInt16_NeverFails") +.forEach(in: [ + (getUInt(+0), getUInt16(+0)), + (getUInt(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int16: (-32768)...(32767) +// MARK: Int16: (-32768)...(+32767) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt.test("FromInt16(-32768)_AlwaysTraps") { - let input = getInt16(-32768) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromInt16(-32768)_AlwaysFails") { - let input = getInt16(-32768) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromInt16(-1)_AlwaysTraps") { - let input = getInt16(-1) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromInt16(-1)_AlwaysFails") { - let input = getInt16(-1) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromInt16(0)_NeverTraps") { - let input = getInt16(0) - let actual = UInt(input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt +.test("FromInt16_NeverTraps") +.forEach(in: [ + (getUInt(+0), getInt16(+0)), + (getUInt(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, UInt($0.1)) } -FixedPointConversion_Debug64_ToUInt.test("FromInt16(0)_NeverFails") { - let input = getInt16(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt +.test("FromInt16_NeverFails") +.forEach(in: [ + (getUInt(+0), getInt16(+0)), + (getUInt(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) } -FixedPointConversion_Debug64_ToUInt.test("FromInt16(32767)_NeverTraps") { - let input = getInt16(32767) - let actual = UInt(input) - expectEqual(32767, actual) +FixedPointConversion_Debug64_ToUInt +.test("FromInt16_AlwaysTraps") +.forEach(in: [ + getInt16(-32768), + getInt16(-1), +]) { + expectCrashLater() + _blackHole(UInt($0)) } -FixedPointConversion_Debug64_ToUInt.test("FromInt16(32767)_NeverFails") { - let input = getInt16(32767) - let actual = UInt(exactly: input) - expectEqual(32767, actual) +FixedPointConversion_Debug64_ToUInt +.test("FromInt16_AlwaysFails") +.forEach(in: [ + getInt16(-32768), + getInt16(-1), +]) { + expectNil(UInt(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt32: (0)...(4294967295) +// MARK: UInt32: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt.test("FromUInt32(0)_NeverTraps") { - let input = getUInt32(0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromUInt32(0)_NeverFails") { - let input = getUInt32(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt +.test("FromUInt32_NeverTraps") +.forEach(in: [ + (getUInt(+0), getUInt32(+0)), + (getUInt(+4294967295), getUInt32(+4294967295)), +]) { + expectEqual($0.0, UInt($0.1)) } -FixedPointConversion_Debug64_ToUInt.test("FromUInt32(4294967295)_NeverTraps") { - let input = getUInt32(4294967295) - let actual = UInt(input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromUInt32(4294967295)_NeverFails") { - let input = getUInt32(4294967295) - let actual = UInt(exactly: input) - expectEqual(4294967295, actual) +FixedPointConversion_Debug64_ToUInt +.test("FromUInt32_NeverFails") +.forEach(in: [ + (getUInt(+0), getUInt32(+0)), + (getUInt(+4294967295), getUInt32(+4294967295)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int32: (-2147483648)...(2147483647) +// MARK: Int32: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt.test("FromInt32(-2147483648)_AlwaysTraps") { - let input = getInt32(-2147483648) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromInt32(-2147483648)_AlwaysFails") { - let input = getInt32(-2147483648) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromInt32(-1)_AlwaysTraps") { - let input = getInt32(-1) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } +FixedPointConversion_Debug64_ToUInt +.test("FromInt32_NeverTraps") +.forEach(in: [ + (getUInt(+0), getInt32(+0)), + (getUInt(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, UInt($0.1)) } -FixedPointConversion_Debug64_ToUInt.test("FromInt32(-1)_AlwaysFails") { - let input = getInt32(-1) - let actual = UInt(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt +.test("FromInt32_NeverFails") +.forEach(in: [ + (getUInt(+0), getInt32(+0)), + (getUInt(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) } -FixedPointConversion_Debug64_ToUInt.test("FromInt32(0)_NeverTraps") { - let input = getInt32(0) - let actual = UInt(input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt +.test("FromInt32_AlwaysTraps") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-1), +]) { + expectCrashLater() + _blackHole(UInt($0)) } -FixedPointConversion_Debug64_ToUInt.test("FromInt32(0)_NeverFails") { - let input = getInt32(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromInt32(2147483647)_NeverTraps") { - let input = getInt32(2147483647) - let actual = UInt(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromInt32(2147483647)_NeverFails") { - let input = getInt32(2147483647) - let actual = UInt(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Debug64_ToUInt +.test("FromInt32_AlwaysFails") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-1), +]) { + expectNil(UInt(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt64: (0)...(18446744073709551615) +// MARK: UInt64: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt.test("FromUInt64(0)_NeverTraps") { - let input = getUInt64(0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromUInt64(0)_NeverFails") { - let input = getUInt64(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt +.test("FromUInt64_NeverTraps") +.forEach(in: [ + (getUInt(+0), getUInt64(+0)), + (getUInt(+18446744073709551615), getUInt64(+18446744073709551615)), +]) { + expectEqual($0.0, UInt($0.1)) } -FixedPointConversion_Debug64_ToUInt.test("FromUInt64(18446744073709551615)_NeverTraps") { - let input = getUInt64(18446744073709551615) - let actual = UInt(input) - expectEqual(18446744073709551615, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromUInt64(18446744073709551615)_NeverFails") { - let input = getUInt64(18446744073709551615) - let actual = UInt(exactly: input) - expectEqual(18446744073709551615, actual) +FixedPointConversion_Debug64_ToUInt +.test("FromUInt64_NeverFails") +.forEach(in: [ + (getUInt(+0), getUInt64(+0)), + (getUInt(+18446744073709551615), getUInt64(+18446744073709551615)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int64: (-9223372036854775808)...(9223372036854775807) +// MARK: Int64: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt.test("FromInt64(-9223372036854775808)_AlwaysTraps") { - let input = getInt64(-9223372036854775808) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromInt64(-9223372036854775808)_AlwaysFails") { - let input = getInt64(-9223372036854775808) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromInt64(-1)_AlwaysTraps") { - let input = getInt64(-1) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromInt64(-1)_AlwaysFails") { - let input = getInt64(-1) - let actual = UInt(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt +.test("FromInt64_NeverTraps") +.forEach(in: [ + (getUInt(+0), getInt64(+0)), + (getUInt(+9223372036854775807), getInt64(+9223372036854775807)), +]) { + expectEqual($0.0, UInt($0.1)) } -FixedPointConversion_Debug64_ToUInt.test("FromInt64(0)_NeverTraps") { - let input = getInt64(0) - let actual = UInt(input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt +.test("FromInt64_NeverFails") +.forEach(in: [ + (getUInt(+0), getInt64(+0)), + (getUInt(+9223372036854775807), getInt64(+9223372036854775807)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) } -FixedPointConversion_Debug64_ToUInt.test("FromInt64(0)_NeverFails") { - let input = getInt64(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt +.test("FromInt64_AlwaysTraps") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-1), +]) { + expectCrashLater() + _blackHole(UInt($0)) } -FixedPointConversion_Debug64_ToUInt.test("FromInt64(9223372036854775807)_NeverTraps") { - let input = getInt64(9223372036854775807) - let actual = UInt(input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromInt64(9223372036854775807)_NeverFails") { - let input = getInt64(9223372036854775807) - let actual = UInt(exactly: input) - expectEqual(9223372036854775807, actual) +FixedPointConversion_Debug64_ToUInt +.test("FromInt64_AlwaysFails") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-1), +]) { + expectNil(UInt(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt: (0)...(18446744073709551615) +// MARK: UInt: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt.test("FromUInt(0)_NeverTraps") { - let input = getUInt(0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromUInt(0)_NeverFails") { - let input = getUInt(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromUInt(18446744073709551615)_NeverTraps") { - let input = getUInt(18446744073709551615) - let actual = UInt(input) - expectEqual(18446744073709551615, actual) +FixedPointConversion_Debug64_ToUInt +.test("FromUInt_NeverTraps") +.forEach(in: [ + (getUInt(+0), getUInt(+0)), + (getUInt(+18446744073709551615), getUInt(+18446744073709551615)), +]) { + expectEqual($0.0, UInt($0.1)) } -FixedPointConversion_Debug64_ToUInt.test("FromUInt(18446744073709551615)_NeverFails") { - let input = getUInt(18446744073709551615) - let actual = UInt(exactly: input) - expectEqual(18446744073709551615, actual) +FixedPointConversion_Debug64_ToUInt +.test("FromUInt_NeverFails") +.forEach(in: [ + (getUInt(+0), getUInt(+0)), + (getUInt(+18446744073709551615), getUInt(+18446744073709551615)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int: (-9223372036854775808)...(9223372036854775807) +// MARK: Int: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt.test("FromInt(-9223372036854775808)_AlwaysTraps") { - let input = getInt(-9223372036854775808) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromInt(-9223372036854775808)_AlwaysFails") { - let input = getInt(-9223372036854775808) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromInt(-1)_AlwaysTraps") { - let input = getInt(-1) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromInt(-1)_AlwaysFails") { - let input = getInt(-1) - let actual = UInt(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt +.test("FromInt_NeverTraps") +.forEach(in: [ + (getUInt(+0), getInt(+0)), + (getUInt(+9223372036854775807), getInt(+9223372036854775807)), +]) { + expectEqual($0.0, UInt($0.1)) } -FixedPointConversion_Debug64_ToUInt.test("FromInt(0)_NeverTraps") { - let input = getInt(0) - let actual = UInt(input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt +.test("FromInt_NeverFails") +.forEach(in: [ + (getUInt(+0), getInt(+0)), + (getUInt(+9223372036854775807), getInt(+9223372036854775807)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) } -FixedPointConversion_Debug64_ToUInt.test("FromInt(0)_NeverFails") { - let input = getInt(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt +.test("FromInt_AlwaysTraps") +.forEach(in: [ + getInt(-9223372036854775808), + getInt(-1), +]) { + expectCrashLater() + _blackHole(UInt($0)) } -FixedPointConversion_Debug64_ToUInt.test("FromInt(9223372036854775807)_NeverTraps") { - let input = getInt(9223372036854775807) - let actual = UInt(input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromInt(9223372036854775807)_NeverFails") { - let input = getInt(9223372036854775807) - let actual = UInt(exactly: input) - expectEqual(9223372036854775807, actual) +FixedPointConversion_Debug64_ToUInt +.test("FromInt_AlwaysFails") +.forEach(in: [ + getInt(-9223372036854775808), + getInt(-1), +]) { + expectNil(UInt(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float16: (-2047)...(2047) +// MARK: Float16: (-2047)...(+2047) //===----------------------------------------------------------------------===// #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -FixedPointConversion_Debug64_ToUInt.test("FromFloat16(-2047)_AlwaysTraps") { - let input = getFloat16(-2047) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat16(-2047)_AlwaysFails") { - let input = getFloat16(-2047) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat16(-128.5)_AlwaysTraps") { - let input = getFloat16(-128.5) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat16(-128.5)_AlwaysFails") { - let input = getFloat16(-128.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat16(-1)_AlwaysTraps") { - let input = getFloat16(-1) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat16(-1)_AlwaysFails") { - let input = getFloat16(-1) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat16(-0.5)_NeverTraps") { - let input = getFloat16(-0.5) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat16(-0.5)_AlwaysFails") { - let input = getFloat16(-0.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat16(0)_NeverTraps") { - let input = getFloat16(0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat16(0)_NeverFails") { - let input = getFloat16(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat16(-0.0)_NeverTraps") { - let input = getFloat16(-0.0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat16(-0.0)_NeverFails") { - let input = getFloat16(-0.0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat16(0.0)_NeverTraps") { - let input = getFloat16(0.0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat16(0.0)_NeverFails") { - let input = getFloat16(0.0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat16(0.5)_NeverTraps") { - let input = getFloat16(0.5) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat16(0.5)_AlwaysFails") { - let input = getFloat16(0.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat16(127.5)_NeverTraps") { - let input = getFloat16(127.5) - let actual = UInt(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat16(127.5)_AlwaysFails") { - let input = getFloat16(127.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat16(255.5)_NeverTraps") { - let input = getFloat16(255.5) - let actual = UInt(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat16(255.5)_AlwaysFails") { - let input = getFloat16(255.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat16(2047)_NeverTraps") { - let input = getFloat16(2047) - let actual = UInt(input) - expectEqual(2047, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat16(2047)_NeverFails") { - let input = getFloat16(2047) - let actual = UInt(exactly: input) - expectEqual(2047, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat16(-.infinity)_AlwaysTraps") { - let input = getFloat16(-.infinity) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat16(-.infinity)_AlwaysFails") { - let input = getFloat16(-.infinity) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat16(+.infinity)_AlwaysTraps") { - let input = getFloat16(+.infinity) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat16(+.infinity)_AlwaysFails") { - let input = getFloat16(+.infinity) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat16(-.nan)_AlwaysTraps") { - let input = getFloat16(-.nan) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat16(-.nan)_AlwaysFails") { - let input = getFloat16(-.nan) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat16(+.nan)_AlwaysTraps") { - let input = getFloat16(+.nan) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat16(+.nan)_AlwaysFails") { - let input = getFloat16(+.nan) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat16(-.signalingNaN)_AlwaysTraps") { - let input = getFloat16(-.signalingNaN) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat16(-.signalingNaN)_AlwaysFails") { - let input = getFloat16(-.signalingNaN) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat16(+.signalingNaN)_AlwaysTraps") { - let input = getFloat16(+.signalingNaN) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat16(+.signalingNaN)_AlwaysFails") { - let input = getFloat16(+.signalingNaN) - let actual = UInt(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt +.test("FromFloat16_NeverTraps") +.forEach(in: [ + (getUInt(+0), getFloat16(-0.5)), + (getUInt(+0), getFloat16(+0)), + (getUInt(+0), getFloat16(-0)), + (getUInt(+0), getFloat16(+0.5)), + (getUInt(+127), getFloat16(+127.5)), + (getUInt(+255), getFloat16(+255.5)), + (getUInt(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, UInt($0.1)) +} + +FixedPointConversion_Debug64_ToUInt +.test("FromFloat16_NeverFails") +.forEach(in: [ + (getUInt(+0), getFloat16(+0)), + (getUInt(+0), getFloat16(-0)), + (getUInt(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToUInt +.test("FromFloat16_AlwaysTraps") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-128.5), + getFloat16(-1), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt($0)) +} + +FixedPointConversion_Debug64_ToUInt +.test("FromFloat16_AlwaysFails") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-128.5), + getFloat16(-1), + getFloat16(-0.5), + getFloat16(+0.5), + getFloat16(+127.5), + getFloat16(+255.5), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectNil(UInt(exactly: $0)) } } #endif // Float16 //===----------------------------------------------------------------------===// -// MARK: Float32: (-16777215)...(16777215) +// MARK: Float32: (-16777215)...(+16777215) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt.test("FromFloat32(-16777215)_AlwaysTraps") { - let input = getFloat32(-16777215) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat32(-16777215)_AlwaysFails") { - let input = getFloat32(-16777215) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat32(-32768.5)_AlwaysTraps") { - let input = getFloat32(-32768.5) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat32(-32768.5)_AlwaysFails") { - let input = getFloat32(-32768.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat32(-128.5)_AlwaysTraps") { - let input = getFloat32(-128.5) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat32(-128.5)_AlwaysFails") { - let input = getFloat32(-128.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat32(-1)_AlwaysTraps") { - let input = getFloat32(-1) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat32(-1)_AlwaysFails") { - let input = getFloat32(-1) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat32(-0.5)_NeverTraps") { - let input = getFloat32(-0.5) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat32(-0.5)_AlwaysFails") { - let input = getFloat32(-0.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat32(0)_NeverTraps") { - let input = getFloat32(0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat32(0)_NeverFails") { - let input = getFloat32(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat32(-0.0)_NeverTraps") { - let input = getFloat32(-0.0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat32(-0.0)_NeverFails") { - let input = getFloat32(-0.0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat32(0.0)_NeverTraps") { - let input = getFloat32(0.0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat32(0.0)_NeverFails") { - let input = getFloat32(0.0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat32(0.5)_NeverTraps") { - let input = getFloat32(0.5) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat32(0.5)_AlwaysFails") { - let input = getFloat32(0.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat32(127.5)_NeverTraps") { - let input = getFloat32(127.5) - let actual = UInt(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat32(127.5)_AlwaysFails") { - let input = getFloat32(127.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat32(255.5)_NeverTraps") { - let input = getFloat32(255.5) - let actual = UInt(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat32(255.5)_AlwaysFails") { - let input = getFloat32(255.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat32(32767.5)_NeverTraps") { - let input = getFloat32(32767.5) - let actual = UInt(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat32(32767.5)_AlwaysFails") { - let input = getFloat32(32767.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat32(65535.5)_NeverTraps") { - let input = getFloat32(65535.5) - let actual = UInt(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat32(65535.5)_AlwaysFails") { - let input = getFloat32(65535.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat32(16777215)_NeverTraps") { - let input = getFloat32(16777215) - let actual = UInt(input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat32(16777215)_NeverFails") { - let input = getFloat32(16777215) - let actual = UInt(exactly: input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat32(-.infinity)_AlwaysTraps") { - let input = getFloat32(-.infinity) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat32(-.infinity)_AlwaysFails") { - let input = getFloat32(-.infinity) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat32(+.infinity)_AlwaysTraps") { - let input = getFloat32(+.infinity) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat32(+.infinity)_AlwaysFails") { - let input = getFloat32(+.infinity) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat32(-.nan)_AlwaysTraps") { - let input = getFloat32(-.nan) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat32(-.nan)_AlwaysFails") { - let input = getFloat32(-.nan) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat32(+.nan)_AlwaysTraps") { - let input = getFloat32(+.nan) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat32(+.nan)_AlwaysFails") { - let input = getFloat32(+.nan) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat32(-.signalingNaN)_AlwaysTraps") { - let input = getFloat32(-.signalingNaN) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat32(-.signalingNaN)_AlwaysFails") { - let input = getFloat32(-.signalingNaN) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat32(+.signalingNaN)_AlwaysTraps") { - let input = getFloat32(+.signalingNaN) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat32(+.signalingNaN)_AlwaysFails") { - let input = getFloat32(+.signalingNaN) - let actual = UInt(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt +.test("FromFloat32_NeverTraps") +.forEach(in: [ + (getUInt(+0), getFloat32(-0.5)), + (getUInt(+0), getFloat32(+0)), + (getUInt(+0), getFloat32(-0)), + (getUInt(+0), getFloat32(+0.5)), + (getUInt(+127), getFloat32(+127.5)), + (getUInt(+255), getFloat32(+255.5)), + (getUInt(+32767), getFloat32(+32767.5)), + (getUInt(+65535), getFloat32(+65535.5)), + (getUInt(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, UInt($0.1)) +} + +FixedPointConversion_Debug64_ToUInt +.test("FromFloat32_NeverFails") +.forEach(in: [ + (getUInt(+0), getFloat32(+0)), + (getUInt(+0), getFloat32(-0)), + (getUInt(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToUInt +.test("FromFloat32_AlwaysTraps") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-1), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt($0)) +} + +FixedPointConversion_Debug64_ToUInt +.test("FromFloat32_AlwaysFails") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-1), + getFloat32(-0.5), + getFloat32(+0.5), + getFloat32(+127.5), + getFloat32(+255.5), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectNil(UInt(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float64: (-9007199254740991)...(9007199254740991) +// MARK: Float64: (-9007199254740991)...(+9007199254740991) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt.test("FromFloat64(-9007199254740991)_AlwaysTraps") { - let input = getFloat64(-9007199254740991) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat64(-9007199254740991)_AlwaysFails") { - let input = getFloat64(-9007199254740991) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat64(-32768.5)_AlwaysTraps") { - let input = getFloat64(-32768.5) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat64(-32768.5)_AlwaysFails") { - let input = getFloat64(-32768.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat64(-128.5)_AlwaysTraps") { - let input = getFloat64(-128.5) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat64(-128.5)_AlwaysFails") { - let input = getFloat64(-128.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat64(-1)_AlwaysTraps") { - let input = getFloat64(-1) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat64(-1)_AlwaysFails") { - let input = getFloat64(-1) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat64(-0.5)_NeverTraps") { - let input = getFloat64(-0.5) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat64(-0.5)_AlwaysFails") { - let input = getFloat64(-0.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat64(0)_NeverTraps") { - let input = getFloat64(0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat64(0)_NeverFails") { - let input = getFloat64(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat64(-0.0)_NeverTraps") { - let input = getFloat64(-0.0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat64(-0.0)_NeverFails") { - let input = getFloat64(-0.0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat64(0.0)_NeverTraps") { - let input = getFloat64(0.0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat64(0.0)_NeverFails") { - let input = getFloat64(0.0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat64(0.5)_NeverTraps") { - let input = getFloat64(0.5) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat64(0.5)_AlwaysFails") { - let input = getFloat64(0.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat64(127.5)_NeverTraps") { - let input = getFloat64(127.5) - let actual = UInt(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat64(127.5)_AlwaysFails") { - let input = getFloat64(127.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat64(255.5)_NeverTraps") { - let input = getFloat64(255.5) - let actual = UInt(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat64(255.5)_AlwaysFails") { - let input = getFloat64(255.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat64(32767.5)_NeverTraps") { - let input = getFloat64(32767.5) - let actual = UInt(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat64(32767.5)_AlwaysFails") { - let input = getFloat64(32767.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat64(65535.5)_NeverTraps") { - let input = getFloat64(65535.5) - let actual = UInt(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat64(65535.5)_AlwaysFails") { - let input = getFloat64(65535.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat64(9007199254740991)_NeverTraps") { - let input = getFloat64(9007199254740991) - let actual = UInt(input) - expectEqual(9007199254740991, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat64(9007199254740991)_NeverFails") { - let input = getFloat64(9007199254740991) - let actual = UInt(exactly: input) - expectEqual(9007199254740991, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat64(-.infinity)_AlwaysTraps") { - let input = getFloat64(-.infinity) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat64(-.infinity)_AlwaysFails") { - let input = getFloat64(-.infinity) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat64(+.infinity)_AlwaysTraps") { - let input = getFloat64(+.infinity) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat64(+.infinity)_AlwaysFails") { - let input = getFloat64(+.infinity) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat64(-.nan)_AlwaysTraps") { - let input = getFloat64(-.nan) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat64(-.nan)_AlwaysFails") { - let input = getFloat64(-.nan) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat64(+.nan)_AlwaysTraps") { - let input = getFloat64(+.nan) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat64(+.nan)_AlwaysFails") { - let input = getFloat64(+.nan) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat64(-.signalingNaN)_AlwaysTraps") { - let input = getFloat64(-.signalingNaN) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat64(-.signalingNaN)_AlwaysFails") { - let input = getFloat64(-.signalingNaN) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat64(+.signalingNaN)_AlwaysTraps") { - let input = getFloat64(+.signalingNaN) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat64(+.signalingNaN)_AlwaysFails") { - let input = getFloat64(+.signalingNaN) - let actual = UInt(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt +.test("FromFloat64_NeverTraps") +.forEach(in: [ + (getUInt(+0), getFloat64(-0.5)), + (getUInt(+0), getFloat64(+0)), + (getUInt(+0), getFloat64(-0)), + (getUInt(+0), getFloat64(+0.5)), + (getUInt(+127), getFloat64(+127.5)), + (getUInt(+255), getFloat64(+255.5)), + (getUInt(+32767), getFloat64(+32767.5)), + (getUInt(+65535), getFloat64(+65535.5)), + (getUInt(+9007199254740991), getFloat64(+9007199254740991)), +]) { + expectEqual($0.0, UInt($0.1)) +} + +FixedPointConversion_Debug64_ToUInt +.test("FromFloat64_NeverFails") +.forEach(in: [ + (getUInt(+0), getFloat64(+0)), + (getUInt(+0), getFloat64(-0)), + (getUInt(+9007199254740991), getFloat64(+9007199254740991)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToUInt +.test("FromFloat64_AlwaysTraps") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-1), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt($0)) +} + +FixedPointConversion_Debug64_ToUInt +.test("FromFloat64_AlwaysFails") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-1), + getFloat64(-0.5), + getFloat64(+0.5), + getFloat64(+127.5), + getFloat64(+255.5), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectNil(UInt(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float80: (-18446744073709551615)...(18446744073709551615) +// MARK: Float80: (-18446744073709551615)...(+18446744073709551615) //===----------------------------------------------------------------------===// #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(-18446744073709551615)_AlwaysTraps") { - let input = getFloat80(-18446744073709551615) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(-18446744073709551615)_AlwaysFails") { - let input = getFloat80(-18446744073709551615) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(-32768.5)_AlwaysTraps") { - let input = getFloat80(-32768.5) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(-32768.5)_AlwaysFails") { - let input = getFloat80(-32768.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(-128.5)_AlwaysTraps") { - let input = getFloat80(-128.5) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(-128.5)_AlwaysFails") { - let input = getFloat80(-128.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(-1)_AlwaysTraps") { - let input = getFloat80(-1) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(-1)_AlwaysFails") { - let input = getFloat80(-1) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(-0.5)_NeverTraps") { - let input = getFloat80(-0.5) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(-0.5)_AlwaysFails") { - let input = getFloat80(-0.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(0)_NeverTraps") { - let input = getFloat80(0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(0)_NeverFails") { - let input = getFloat80(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(-0.0)_NeverTraps") { - let input = getFloat80(-0.0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(-0.0)_NeverFails") { - let input = getFloat80(-0.0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(0.0)_NeverTraps") { - let input = getFloat80(0.0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(0.0)_NeverFails") { - let input = getFloat80(0.0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(0.5)_NeverTraps") { - let input = getFloat80(0.5) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(0.5)_AlwaysFails") { - let input = getFloat80(0.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(127.5)_NeverTraps") { - let input = getFloat80(127.5) - let actual = UInt(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(127.5)_AlwaysFails") { - let input = getFloat80(127.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(255.5)_NeverTraps") { - let input = getFloat80(255.5) - let actual = UInt(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(255.5)_AlwaysFails") { - let input = getFloat80(255.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(32767.5)_NeverTraps") { - let input = getFloat80(32767.5) - let actual = UInt(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(32767.5)_AlwaysFails") { - let input = getFloat80(32767.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(65535.5)_NeverTraps") { - let input = getFloat80(65535.5) - let actual = UInt(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(65535.5)_AlwaysFails") { - let input = getFloat80(65535.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(18446744073709551615)_NeverTraps") { - let input = getFloat80(18446744073709551615) - let actual = UInt(input) - expectEqual(18446744073709551615, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(18446744073709551615)_NeverFails") { - let input = getFloat80(18446744073709551615) - let actual = UInt(exactly: input) - expectEqual(18446744073709551615, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(18446744073709551615)_NeverTraps") { - let input = getFloat80(18446744073709551615) - let actual = UInt(input) - expectEqual(18446744073709551615, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(18446744073709551615)_NeverFails") { - let input = getFloat80(18446744073709551615) - let actual = UInt(exactly: input) - expectEqual(18446744073709551615, actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(-.infinity)_AlwaysTraps") { - let input = getFloat80(-.infinity) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(-.infinity)_AlwaysFails") { - let input = getFloat80(-.infinity) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(+.infinity)_AlwaysTraps") { - let input = getFloat80(+.infinity) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(+.infinity)_AlwaysFails") { - let input = getFloat80(+.infinity) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(-.nan)_AlwaysTraps") { - let input = getFloat80(-.nan) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(-.nan)_AlwaysFails") { - let input = getFloat80(-.nan) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(+.nan)_AlwaysTraps") { - let input = getFloat80(+.nan) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(+.nan)_AlwaysFails") { - let input = getFloat80(+.nan) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(-.signalingNaN)_AlwaysTraps") { - let input = getFloat80(-.signalingNaN) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(-.signalingNaN)_AlwaysFails") { - let input = getFloat80(-.signalingNaN) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(+.signalingNaN)_AlwaysTraps") { - let input = getFloat80(+.signalingNaN) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt.test("FromFloat80(+.signalingNaN)_AlwaysFails") { - let input = getFloat80(+.signalingNaN) - let actual = UInt(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt +.test("FromFloat80_NeverTraps") +.forEach(in: [ + (getUInt(+0), getFloat80(-0.5)), + (getUInt(+0), getFloat80(+0)), + (getUInt(+0), getFloat80(-0)), + (getUInt(+0), getFloat80(+0.5)), + (getUInt(+127), getFloat80(+127.5)), + (getUInt(+255), getFloat80(+255.5)), + (getUInt(+32767), getFloat80(+32767.5)), + (getUInt(+65535), getFloat80(+65535.5)), + (getUInt(+18446744073709551615), getFloat80(+18446744073709551615)), +]) { + expectEqual($0.0, UInt($0.1)) +} + +FixedPointConversion_Debug64_ToUInt +.test("FromFloat80_NeverFails") +.forEach(in: [ + (getUInt(+0), getFloat80(+0)), + (getUInt(+0), getFloat80(-0)), + (getUInt(+18446744073709551615), getFloat80(+18446744073709551615)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToUInt +.test("FromFloat80_AlwaysTraps") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-1), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt($0)) +} + +FixedPointConversion_Debug64_ToUInt +.test("FromFloat80_AlwaysFails") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-1), + getFloat80(-0.5), + getFloat80(+0.5), + getFloat80(+127.5), + getFloat80(+255.5), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectNil(UInt(exactly: $0)) } #endif // Float80 diff --git a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug64_ToUInt16.swift b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug64_ToUInt16.swift index 1f2b3a2fe86b7..c7932e9f2c129 100644 --- a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug64_ToUInt16.swift +++ b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug64_ToUInt16.swift @@ -14,1704 +14,690 @@ import StdlibUnittest -let FixedPointConversion_Debug64_ToUInt16 = TestSuite("FixedPointConversion_Debug64_ToUInt16") +let FixedPointConversion_Debug64_ToUInt16 = TestSuite( + "FixedPointConversion_Debug64_ToUInt16" +) //===----------------------------------------------------------------------===// -// MARK: UInt8: (0)...(255) +// MARK: UInt8: (+0)...(+255) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt16.test("FromUInt8(0)_NeverTraps") { - let input = getUInt8(0) - let actual = UInt16(input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt16 +.test("FromUInt8_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getUInt8(+0)), + (getUInt16(+255), getUInt8(+255)), +]) { + expectEqual($0.0, UInt16($0.1)) } -FixedPointConversion_Debug64_ToUInt16.test("FromUInt8(0)_NeverFails") { - let input = getUInt8(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromUInt8(255)_NeverTraps") { - let input = getUInt8(255) - let actual = UInt16(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromUInt8(255)_NeverFails") { - let input = getUInt8(255) - let actual = UInt16(exactly: input) - expectEqual(255, actual) +FixedPointConversion_Debug64_ToUInt16 +.test("FromUInt8_NeverFails") +.forEach(in: [ + (getUInt16(+0), getUInt8(+0)), + (getUInt16(+255), getUInt8(+255)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int8: (-128)...(127) +// MARK: Int8: (-128)...(+127) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt16.test("FromInt8(-128)_AlwaysTraps") { - let input = getInt8(-128) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt8(-128)_AlwaysFails") { - let input = getInt8(-128) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt8(-1)_AlwaysTraps") { - let input = getInt8(-1) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt8(-1)_AlwaysFails") { - let input = getInt8(-1) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt16 +.test("FromInt8_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getInt8(+0)), + (getUInt16(+127), getInt8(+127)), +]) { + expectEqual($0.0, UInt16($0.1)) } -FixedPointConversion_Debug64_ToUInt16.test("FromInt8(0)_NeverTraps") { - let input = getInt8(0) - let actual = UInt16(input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt16 +.test("FromInt8_NeverFails") +.forEach(in: [ + (getUInt16(+0), getInt8(+0)), + (getUInt16(+127), getInt8(+127)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) } -FixedPointConversion_Debug64_ToUInt16.test("FromInt8(0)_NeverFails") { - let input = getInt8(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt16 +.test("FromInt8_AlwaysTraps") +.forEach(in: [ + getInt8(-128), + getInt8(-1), +]) { + expectCrashLater() + _blackHole(UInt16($0)) } -FixedPointConversion_Debug64_ToUInt16.test("FromInt8(127)_NeverTraps") { - let input = getInt8(127) - let actual = UInt16(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt8(127)_NeverFails") { - let input = getInt8(127) - let actual = UInt16(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Debug64_ToUInt16 +.test("FromInt8_AlwaysFails") +.forEach(in: [ + getInt8(-128), + getInt8(-1), +]) { + expectNil(UInt16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt16: (0)...(65535) +// MARK: UInt16: (+0)...(+65535) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt16.test("FromUInt16(0)_NeverTraps") { - let input = getUInt16(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromUInt16(0)_NeverFails") { - let input = getUInt16(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt16 +.test("FromUInt16_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getUInt16(+0)), + (getUInt16(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, UInt16($0.1)) } -FixedPointConversion_Debug64_ToUInt16.test("FromUInt16(65535)_NeverTraps") { - let input = getUInt16(65535) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromUInt16(65535)_NeverFails") { - let input = getUInt16(65535) - let actual = UInt16(exactly: input) - expectEqual(65535, actual) +FixedPointConversion_Debug64_ToUInt16 +.test("FromUInt16_NeverFails") +.forEach(in: [ + (getUInt16(+0), getUInt16(+0)), + (getUInt16(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int16: (-32768)...(32767) +// MARK: Int16: (-32768)...(+32767) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt16.test("FromInt16(-32768)_AlwaysTraps") { - let input = getInt16(-32768) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt16(-32768)_AlwaysFails") { - let input = getInt16(-32768) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt16(-1)_AlwaysTraps") { - let input = getInt16(-1) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt16(-1)_AlwaysFails") { - let input = getInt16(-1) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt16(0)_NeverTraps") { - let input = getInt16(0) - let actual = UInt16(input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt16 +.test("FromInt16_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getInt16(+0)), + (getUInt16(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, UInt16($0.1)) } -FixedPointConversion_Debug64_ToUInt16.test("FromInt16(0)_NeverFails") { - let input = getInt16(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt16 +.test("FromInt16_NeverFails") +.forEach(in: [ + (getUInt16(+0), getInt16(+0)), + (getUInt16(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) } -FixedPointConversion_Debug64_ToUInt16.test("FromInt16(32767)_NeverTraps") { - let input = getInt16(32767) - let actual = UInt16(input) - expectEqual(32767, actual) +FixedPointConversion_Debug64_ToUInt16 +.test("FromInt16_AlwaysTraps") +.forEach(in: [ + getInt16(-32768), + getInt16(-1), +]) { + expectCrashLater() + _blackHole(UInt16($0)) } -FixedPointConversion_Debug64_ToUInt16.test("FromInt16(32767)_NeverFails") { - let input = getInt16(32767) - let actual = UInt16(exactly: input) - expectEqual(32767, actual) +FixedPointConversion_Debug64_ToUInt16 +.test("FromInt16_AlwaysFails") +.forEach(in: [ + getInt16(-32768), + getInt16(-1), +]) { + expectNil(UInt16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt32: (0)...(4294967295) +// MARK: UInt32: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt16.test("FromUInt32(0)_NeverTraps") { - let input = getUInt32(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromUInt32(0)_NeverFails") { - let input = getUInt32(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromUInt32(65535)_NeverTraps") { - let input = getUInt32(65535) - let actual = UInt16(input) - expectEqual(65535, actual) +FixedPointConversion_Debug64_ToUInt16 +.test("FromUInt32_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getUInt32(+0)), + (getUInt16(+65535), getUInt32(+65535)), +]) { + expectEqual($0.0, UInt16($0.1)) } -FixedPointConversion_Debug64_ToUInt16.test("FromUInt32(65535)_NeverFails") { - let input = getUInt32(65535) - let actual = UInt16(exactly: input) - expectEqual(65535, actual) +FixedPointConversion_Debug64_ToUInt16 +.test("FromUInt32_NeverFails") +.forEach(in: [ + (getUInt16(+0), getUInt32(+0)), + (getUInt16(+65535), getUInt32(+65535)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) } -FixedPointConversion_Debug64_ToUInt16.test("FromUInt32(65536)_AlwaysTraps") { - let input = getUInt32(65536) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } +FixedPointConversion_Debug64_ToUInt16 +.test("FromUInt32_AlwaysTraps") +.forEach(in: [ + getUInt32(+65536), + getUInt32(+4294967295), +]) { + expectCrashLater() + _blackHole(UInt16($0)) } -FixedPointConversion_Debug64_ToUInt16.test("FromUInt32(65536)_AlwaysFails") { - let input = getUInt32(65536) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromUInt32(4294967295)_AlwaysTraps") { - let input = getUInt32(4294967295) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromUInt32(4294967295)_AlwaysFails") { - let input = getUInt32(4294967295) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt16 +.test("FromUInt32_AlwaysFails") +.forEach(in: [ + getUInt32(+65536), + getUInt32(+4294967295), +]) { + expectNil(UInt16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int32: (-2147483648)...(2147483647) +// MARK: Int32: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt16.test("FromInt32(-2147483648)_AlwaysTraps") { - let input = getInt32(-2147483648) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt32(-2147483648)_AlwaysFails") { - let input = getInt32(-2147483648) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt32(-1)_AlwaysTraps") { - let input = getInt32(-1) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt32(-1)_AlwaysFails") { - let input = getInt32(-1) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt32(0)_NeverTraps") { - let input = getInt32(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt32(0)_NeverFails") { - let input = getInt32(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt32(65535)_NeverTraps") { - let input = getInt32(65535) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt32(65535)_NeverFails") { - let input = getInt32(65535) - let actual = UInt16(exactly: input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt32(65536)_AlwaysTraps") { - let input = getInt32(65536) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt32(65536)_AlwaysFails") { - let input = getInt32(65536) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt32(2147483647)_AlwaysTraps") { - let input = getInt32(2147483647) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt32(2147483647)_AlwaysFails") { - let input = getInt32(2147483647) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt16 +.test("FromInt32_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getInt32(+0)), + (getUInt16(+65535), getInt32(+65535)), +]) { + expectEqual($0.0, UInt16($0.1)) +} + +FixedPointConversion_Debug64_ToUInt16 +.test("FromInt32_NeverFails") +.forEach(in: [ + (getUInt16(+0), getInt32(+0)), + (getUInt16(+65535), getInt32(+65535)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToUInt16 +.test("FromInt32_AlwaysTraps") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-1), + getInt32(+65536), + getInt32(+2147483647), +]) { + expectCrashLater() + _blackHole(UInt16($0)) +} + +FixedPointConversion_Debug64_ToUInt16 +.test("FromInt32_AlwaysFails") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-1), + getInt32(+65536), + getInt32(+2147483647), +]) { + expectNil(UInt16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt64: (0)...(18446744073709551615) +// MARK: UInt64: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt16.test("FromUInt64(0)_NeverTraps") { - let input = getUInt64(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromUInt64(0)_NeverFails") { - let input = getUInt64(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromUInt64(65535)_NeverTraps") { - let input = getUInt64(65535) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromUInt64(65535)_NeverFails") { - let input = getUInt64(65535) - let actual = UInt16(exactly: input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromUInt64(65536)_AlwaysTraps") { - let input = getUInt64(65536) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } +FixedPointConversion_Debug64_ToUInt16 +.test("FromUInt64_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getUInt64(+0)), + (getUInt16(+65535), getUInt64(+65535)), +]) { + expectEqual($0.0, UInt16($0.1)) } -FixedPointConversion_Debug64_ToUInt16.test("FromUInt64(65536)_AlwaysFails") { - let input = getUInt64(65536) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt16 +.test("FromUInt64_NeverFails") +.forEach(in: [ + (getUInt16(+0), getUInt64(+0)), + (getUInt16(+65535), getUInt64(+65535)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) } -FixedPointConversion_Debug64_ToUInt16.test("FromUInt64(18446744073709551615)_AlwaysTraps") { - let input = getUInt64(18446744073709551615) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } +FixedPointConversion_Debug64_ToUInt16 +.test("FromUInt64_AlwaysTraps") +.forEach(in: [ + getUInt64(+65536), + getUInt64(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(UInt16($0)) } -FixedPointConversion_Debug64_ToUInt16.test("FromUInt64(18446744073709551615)_AlwaysFails") { - let input = getUInt64(18446744073709551615) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt16 +.test("FromUInt64_AlwaysFails") +.forEach(in: [ + getUInt64(+65536), + getUInt64(+18446744073709551615), +]) { + expectNil(UInt16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int64: (-9223372036854775808)...(9223372036854775807) +// MARK: Int64: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt16.test("FromInt64(-9223372036854775808)_AlwaysTraps") { - let input = getInt64(-9223372036854775808) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt64(-9223372036854775808)_AlwaysFails") { - let input = getInt64(-9223372036854775808) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt64(-1)_AlwaysTraps") { - let input = getInt64(-1) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt64(-1)_AlwaysFails") { - let input = getInt64(-1) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt64(0)_NeverTraps") { - let input = getInt64(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt64(0)_NeverFails") { - let input = getInt64(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt64(65535)_NeverTraps") { - let input = getInt64(65535) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt64(65535)_NeverFails") { - let input = getInt64(65535) - let actual = UInt16(exactly: input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt64(65536)_AlwaysTraps") { - let input = getInt64(65536) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt64(65536)_AlwaysFails") { - let input = getInt64(65536) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt64(9223372036854775807)_AlwaysTraps") { - let input = getInt64(9223372036854775807) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt64(9223372036854775807)_AlwaysFails") { - let input = getInt64(9223372036854775807) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt16 +.test("FromInt64_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getInt64(+0)), + (getUInt16(+65535), getInt64(+65535)), +]) { + expectEqual($0.0, UInt16($0.1)) +} + +FixedPointConversion_Debug64_ToUInt16 +.test("FromInt64_NeverFails") +.forEach(in: [ + (getUInt16(+0), getInt64(+0)), + (getUInt16(+65535), getInt64(+65535)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToUInt16 +.test("FromInt64_AlwaysTraps") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-1), + getInt64(+65536), + getInt64(+9223372036854775807), +]) { + expectCrashLater() + _blackHole(UInt16($0)) +} + +FixedPointConversion_Debug64_ToUInt16 +.test("FromInt64_AlwaysFails") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-1), + getInt64(+65536), + getInt64(+9223372036854775807), +]) { + expectNil(UInt16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt: (0)...(18446744073709551615) +// MARK: UInt: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt16.test("FromUInt(0)_NeverTraps") { - let input = getUInt(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromUInt(0)_NeverFails") { - let input = getUInt(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromUInt(65535)_NeverTraps") { - let input = getUInt(65535) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromUInt(65535)_NeverFails") { - let input = getUInt(65535) - let actual = UInt16(exactly: input) - expectEqual(65535, actual) +FixedPointConversion_Debug64_ToUInt16 +.test("FromUInt_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getUInt(+0)), + (getUInt16(+65535), getUInt(+65535)), +]) { + expectEqual($0.0, UInt16($0.1)) } -FixedPointConversion_Debug64_ToUInt16.test("FromUInt(65536)_AlwaysTraps") { - let input = getUInt(65536) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } +FixedPointConversion_Debug64_ToUInt16 +.test("FromUInt_NeverFails") +.forEach(in: [ + (getUInt16(+0), getUInt(+0)), + (getUInt16(+65535), getUInt(+65535)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) } -FixedPointConversion_Debug64_ToUInt16.test("FromUInt(65536)_AlwaysFails") { - let input = getUInt(65536) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt16 +.test("FromUInt_AlwaysTraps") +.forEach(in: [ + getUInt(+65536), + getUInt(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(UInt16($0)) } -FixedPointConversion_Debug64_ToUInt16.test("FromUInt(18446744073709551615)_AlwaysTraps") { - let input = getUInt(18446744073709551615) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromUInt(18446744073709551615)_AlwaysFails") { - let input = getUInt(18446744073709551615) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt16 +.test("FromUInt_AlwaysFails") +.forEach(in: [ + getUInt(+65536), + getUInt(+18446744073709551615), +]) { + expectNil(UInt16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int: (-9223372036854775808)...(9223372036854775807) +// MARK: Int: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt16.test("FromInt(-9223372036854775808)_AlwaysTraps") { - let input = getInt(-9223372036854775808) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt(-9223372036854775808)_AlwaysFails") { - let input = getInt(-9223372036854775808) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt(-1)_AlwaysTraps") { - let input = getInt(-1) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt(-1)_AlwaysFails") { - let input = getInt(-1) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt(0)_NeverTraps") { - let input = getInt(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt(0)_NeverFails") { - let input = getInt(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt(65535)_NeverTraps") { - let input = getInt(65535) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt(65535)_NeverFails") { - let input = getInt(65535) - let actual = UInt16(exactly: input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt(65536)_AlwaysTraps") { - let input = getInt(65536) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt(65536)_AlwaysFails") { - let input = getInt(65536) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt(9223372036854775807)_AlwaysTraps") { - let input = getInt(9223372036854775807) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromInt(9223372036854775807)_AlwaysFails") { - let input = getInt(9223372036854775807) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt16 +.test("FromInt_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getInt(+0)), + (getUInt16(+65535), getInt(+65535)), +]) { + expectEqual($0.0, UInt16($0.1)) +} + +FixedPointConversion_Debug64_ToUInt16 +.test("FromInt_NeverFails") +.forEach(in: [ + (getUInt16(+0), getInt(+0)), + (getUInt16(+65535), getInt(+65535)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToUInt16 +.test("FromInt_AlwaysTraps") +.forEach(in: [ + getInt(-9223372036854775808), + getInt(-1), + getInt(+65536), + getInt(+9223372036854775807), +]) { + expectCrashLater() + _blackHole(UInt16($0)) +} + +FixedPointConversion_Debug64_ToUInt16 +.test("FromInt_AlwaysFails") +.forEach(in: [ + getInt(-9223372036854775808), + getInt(-1), + getInt(+65536), + getInt(+9223372036854775807), +]) { + expectNil(UInt16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float16: (-2047)...(2047) +// MARK: Float16: (-2047)...(+2047) //===----------------------------------------------------------------------===// #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -FixedPointConversion_Debug64_ToUInt16.test("FromFloat16(-2047)_AlwaysTraps") { - let input = getFloat16(-2047) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat16(-2047)_AlwaysFails") { - let input = getFloat16(-2047) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat16(-128.5)_AlwaysTraps") { - let input = getFloat16(-128.5) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat16(-128.5)_AlwaysFails") { - let input = getFloat16(-128.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat16(-1)_AlwaysTraps") { - let input = getFloat16(-1) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat16(-1)_AlwaysFails") { - let input = getFloat16(-1) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat16(-0.5)_NeverTraps") { - let input = getFloat16(-0.5) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat16(-0.5)_AlwaysFails") { - let input = getFloat16(-0.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat16(0)_NeverTraps") { - let input = getFloat16(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat16(0)_NeverFails") { - let input = getFloat16(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat16(-0.0)_NeverTraps") { - let input = getFloat16(-0.0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat16(-0.0)_NeverFails") { - let input = getFloat16(-0.0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat16(0.0)_NeverTraps") { - let input = getFloat16(0.0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat16(0.0)_NeverFails") { - let input = getFloat16(0.0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat16(0.5)_NeverTraps") { - let input = getFloat16(0.5) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat16(0.5)_AlwaysFails") { - let input = getFloat16(0.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat16(127.5)_NeverTraps") { - let input = getFloat16(127.5) - let actual = UInt16(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat16(127.5)_AlwaysFails") { - let input = getFloat16(127.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat16(255.5)_NeverTraps") { - let input = getFloat16(255.5) - let actual = UInt16(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat16(255.5)_AlwaysFails") { - let input = getFloat16(255.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat16(2047)_NeverTraps") { - let input = getFloat16(2047) - let actual = UInt16(input) - expectEqual(2047, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat16(2047)_NeverFails") { - let input = getFloat16(2047) - let actual = UInt16(exactly: input) - expectEqual(2047, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat16(-.infinity)_AlwaysTraps") { - let input = getFloat16(-.infinity) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat16(-.infinity)_AlwaysFails") { - let input = getFloat16(-.infinity) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat16(+.infinity)_AlwaysTraps") { - let input = getFloat16(+.infinity) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat16(+.infinity)_AlwaysFails") { - let input = getFloat16(+.infinity) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat16(-.nan)_AlwaysTraps") { - let input = getFloat16(-.nan) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat16(-.nan)_AlwaysFails") { - let input = getFloat16(-.nan) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat16(+.nan)_AlwaysTraps") { - let input = getFloat16(+.nan) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat16(+.nan)_AlwaysFails") { - let input = getFloat16(+.nan) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat16(-.signalingNaN)_AlwaysTraps") { - let input = getFloat16(-.signalingNaN) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat16(-.signalingNaN)_AlwaysFails") { - let input = getFloat16(-.signalingNaN) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat16(+.signalingNaN)_AlwaysTraps") { - let input = getFloat16(+.signalingNaN) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat16(+.signalingNaN)_AlwaysFails") { - let input = getFloat16(+.signalingNaN) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt16 +.test("FromFloat16_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getFloat16(-0.5)), + (getUInt16(+0), getFloat16(+0)), + (getUInt16(+0), getFloat16(-0)), + (getUInt16(+0), getFloat16(+0.5)), + (getUInt16(+127), getFloat16(+127.5)), + (getUInt16(+255), getFloat16(+255.5)), + (getUInt16(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, UInt16($0.1)) +} + +FixedPointConversion_Debug64_ToUInt16 +.test("FromFloat16_NeverFails") +.forEach(in: [ + (getUInt16(+0), getFloat16(+0)), + (getUInt16(+0), getFloat16(-0)), + (getUInt16(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToUInt16 +.test("FromFloat16_AlwaysTraps") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-128.5), + getFloat16(-1), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt16($0)) +} + +FixedPointConversion_Debug64_ToUInt16 +.test("FromFloat16_AlwaysFails") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-128.5), + getFloat16(-1), + getFloat16(-0.5), + getFloat16(+0.5), + getFloat16(+127.5), + getFloat16(+255.5), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectNil(UInt16(exactly: $0)) } } #endif // Float16 //===----------------------------------------------------------------------===// -// MARK: Float32: (-16777215)...(16777215) +// MARK: Float32: (-16777215)...(+16777215) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(-16777215)_AlwaysTraps") { - let input = getFloat32(-16777215) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(-16777215)_AlwaysFails") { - let input = getFloat32(-16777215) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(-32768.5)_AlwaysTraps") { - let input = getFloat32(-32768.5) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(-32768.5)_AlwaysFails") { - let input = getFloat32(-32768.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(-128.5)_AlwaysTraps") { - let input = getFloat32(-128.5) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(-128.5)_AlwaysFails") { - let input = getFloat32(-128.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(-1)_AlwaysTraps") { - let input = getFloat32(-1) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(-1)_AlwaysFails") { - let input = getFloat32(-1) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(-0.5)_NeverTraps") { - let input = getFloat32(-0.5) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(-0.5)_AlwaysFails") { - let input = getFloat32(-0.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(0)_NeverTraps") { - let input = getFloat32(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(0)_NeverFails") { - let input = getFloat32(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(-0.0)_NeverTraps") { - let input = getFloat32(-0.0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(-0.0)_NeverFails") { - let input = getFloat32(-0.0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(0.0)_NeverTraps") { - let input = getFloat32(0.0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(0.0)_NeverFails") { - let input = getFloat32(0.0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(0.5)_NeverTraps") { - let input = getFloat32(0.5) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(0.5)_AlwaysFails") { - let input = getFloat32(0.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(127.5)_NeverTraps") { - let input = getFloat32(127.5) - let actual = UInt16(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(127.5)_AlwaysFails") { - let input = getFloat32(127.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(255.5)_NeverTraps") { - let input = getFloat32(255.5) - let actual = UInt16(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(255.5)_AlwaysFails") { - let input = getFloat32(255.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(32767.5)_NeverTraps") { - let input = getFloat32(32767.5) - let actual = UInt16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(32767.5)_AlwaysFails") { - let input = getFloat32(32767.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(65535)_NeverTraps") { - let input = getFloat32(65535) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(65535)_NeverFails") { - let input = getFloat32(65535) - let actual = UInt16(exactly: input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(65535.5)_NeverTraps") { - let input = getFloat32(65535.5) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(65535.5)_AlwaysFails") { - let input = getFloat32(65535.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(65536)_AlwaysTraps") { - let input = getFloat32(65536) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(65536)_AlwaysFails") { - let input = getFloat32(65536) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(16777215)_AlwaysTraps") { - let input = getFloat32(16777215) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(16777215)_AlwaysFails") { - let input = getFloat32(16777215) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(-.infinity)_AlwaysTraps") { - let input = getFloat32(-.infinity) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(-.infinity)_AlwaysFails") { - let input = getFloat32(-.infinity) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(+.infinity)_AlwaysTraps") { - let input = getFloat32(+.infinity) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(+.infinity)_AlwaysFails") { - let input = getFloat32(+.infinity) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(-.nan)_AlwaysTraps") { - let input = getFloat32(-.nan) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(-.nan)_AlwaysFails") { - let input = getFloat32(-.nan) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(+.nan)_AlwaysTraps") { - let input = getFloat32(+.nan) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(+.nan)_AlwaysFails") { - let input = getFloat32(+.nan) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(-.signalingNaN)_AlwaysTraps") { - let input = getFloat32(-.signalingNaN) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(-.signalingNaN)_AlwaysFails") { - let input = getFloat32(-.signalingNaN) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(+.signalingNaN)_AlwaysTraps") { - let input = getFloat32(+.signalingNaN) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat32(+.signalingNaN)_AlwaysFails") { - let input = getFloat32(+.signalingNaN) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt16 +.test("FromFloat32_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getFloat32(-0.5)), + (getUInt16(+0), getFloat32(+0)), + (getUInt16(+0), getFloat32(-0)), + (getUInt16(+0), getFloat32(+0.5)), + (getUInt16(+127), getFloat32(+127.5)), + (getUInt16(+255), getFloat32(+255.5)), + (getUInt16(+32767), getFloat32(+32767.5)), + (getUInt16(+65535), getFloat32(+65535)), + (getUInt16(+65535), getFloat32(+65535.5)), +]) { + expectEqual($0.0, UInt16($0.1)) +} + +FixedPointConversion_Debug64_ToUInt16 +.test("FromFloat32_NeverFails") +.forEach(in: [ + (getUInt16(+0), getFloat32(+0)), + (getUInt16(+0), getFloat32(-0)), + (getUInt16(+65535), getFloat32(+65535)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToUInt16 +.test("FromFloat32_AlwaysTraps") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-1), + getFloat32(+65536), + getFloat32(+16777215), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt16($0)) +} + +FixedPointConversion_Debug64_ToUInt16 +.test("FromFloat32_AlwaysFails") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-1), + getFloat32(-0.5), + getFloat32(+0.5), + getFloat32(+127.5), + getFloat32(+255.5), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(+65536), + getFloat32(+16777215), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectNil(UInt16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float64: (-9007199254740991)...(9007199254740991) +// MARK: Float64: (-9007199254740991)...(+9007199254740991) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(-9007199254740991)_AlwaysTraps") { - let input = getFloat64(-9007199254740991) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(-9007199254740991)_AlwaysFails") { - let input = getFloat64(-9007199254740991) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(-32768.5)_AlwaysTraps") { - let input = getFloat64(-32768.5) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(-32768.5)_AlwaysFails") { - let input = getFloat64(-32768.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(-128.5)_AlwaysTraps") { - let input = getFloat64(-128.5) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(-128.5)_AlwaysFails") { - let input = getFloat64(-128.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(-1)_AlwaysTraps") { - let input = getFloat64(-1) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(-1)_AlwaysFails") { - let input = getFloat64(-1) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(-0.5)_NeverTraps") { - let input = getFloat64(-0.5) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(-0.5)_AlwaysFails") { - let input = getFloat64(-0.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(0)_NeverTraps") { - let input = getFloat64(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(0)_NeverFails") { - let input = getFloat64(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(-0.0)_NeverTraps") { - let input = getFloat64(-0.0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(-0.0)_NeverFails") { - let input = getFloat64(-0.0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(0.0)_NeverTraps") { - let input = getFloat64(0.0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(0.0)_NeverFails") { - let input = getFloat64(0.0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(0.5)_NeverTraps") { - let input = getFloat64(0.5) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(0.5)_AlwaysFails") { - let input = getFloat64(0.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(127.5)_NeverTraps") { - let input = getFloat64(127.5) - let actual = UInt16(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(127.5)_AlwaysFails") { - let input = getFloat64(127.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(255.5)_NeverTraps") { - let input = getFloat64(255.5) - let actual = UInt16(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(255.5)_AlwaysFails") { - let input = getFloat64(255.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(32767.5)_NeverTraps") { - let input = getFloat64(32767.5) - let actual = UInt16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(32767.5)_AlwaysFails") { - let input = getFloat64(32767.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(65535)_NeverTraps") { - let input = getFloat64(65535) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(65535)_NeverFails") { - let input = getFloat64(65535) - let actual = UInt16(exactly: input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(65535.5)_NeverTraps") { - let input = getFloat64(65535.5) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(65535.5)_AlwaysFails") { - let input = getFloat64(65535.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(65536)_AlwaysTraps") { - let input = getFloat64(65536) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(65536)_AlwaysFails") { - let input = getFloat64(65536) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(9007199254740991)_AlwaysTraps") { - let input = getFloat64(9007199254740991) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(9007199254740991)_AlwaysFails") { - let input = getFloat64(9007199254740991) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(-.infinity)_AlwaysTraps") { - let input = getFloat64(-.infinity) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(-.infinity)_AlwaysFails") { - let input = getFloat64(-.infinity) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(+.infinity)_AlwaysTraps") { - let input = getFloat64(+.infinity) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(+.infinity)_AlwaysFails") { - let input = getFloat64(+.infinity) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(-.nan)_AlwaysTraps") { - let input = getFloat64(-.nan) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(-.nan)_AlwaysFails") { - let input = getFloat64(-.nan) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(+.nan)_AlwaysTraps") { - let input = getFloat64(+.nan) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(+.nan)_AlwaysFails") { - let input = getFloat64(+.nan) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(-.signalingNaN)_AlwaysTraps") { - let input = getFloat64(-.signalingNaN) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(-.signalingNaN)_AlwaysFails") { - let input = getFloat64(-.signalingNaN) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(+.signalingNaN)_AlwaysTraps") { - let input = getFloat64(+.signalingNaN) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat64(+.signalingNaN)_AlwaysFails") { - let input = getFloat64(+.signalingNaN) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt16 +.test("FromFloat64_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getFloat64(-0.5)), + (getUInt16(+0), getFloat64(+0)), + (getUInt16(+0), getFloat64(-0)), + (getUInt16(+0), getFloat64(+0.5)), + (getUInt16(+127), getFloat64(+127.5)), + (getUInt16(+255), getFloat64(+255.5)), + (getUInt16(+32767), getFloat64(+32767.5)), + (getUInt16(+65535), getFloat64(+65535)), + (getUInt16(+65535), getFloat64(+65535.5)), +]) { + expectEqual($0.0, UInt16($0.1)) +} + +FixedPointConversion_Debug64_ToUInt16 +.test("FromFloat64_NeverFails") +.forEach(in: [ + (getUInt16(+0), getFloat64(+0)), + (getUInt16(+0), getFloat64(-0)), + (getUInt16(+65535), getFloat64(+65535)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToUInt16 +.test("FromFloat64_AlwaysTraps") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-1), + getFloat64(+65536), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt16($0)) +} + +FixedPointConversion_Debug64_ToUInt16 +.test("FromFloat64_AlwaysFails") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-1), + getFloat64(-0.5), + getFloat64(+0.5), + getFloat64(+127.5), + getFloat64(+255.5), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(+65536), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectNil(UInt16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float80: (-18446744073709551615)...(18446744073709551615) +// MARK: Float80: (-18446744073709551615)...(+18446744073709551615) //===----------------------------------------------------------------------===// #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(-18446744073709551615)_AlwaysTraps") { - let input = getFloat80(-18446744073709551615) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(-18446744073709551615)_AlwaysFails") { - let input = getFloat80(-18446744073709551615) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(-32768.5)_AlwaysTraps") { - let input = getFloat80(-32768.5) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(-32768.5)_AlwaysFails") { - let input = getFloat80(-32768.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(-128.5)_AlwaysTraps") { - let input = getFloat80(-128.5) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(-128.5)_AlwaysFails") { - let input = getFloat80(-128.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(-1)_AlwaysTraps") { - let input = getFloat80(-1) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(-1)_AlwaysFails") { - let input = getFloat80(-1) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(-0.5)_NeverTraps") { - let input = getFloat80(-0.5) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(-0.5)_AlwaysFails") { - let input = getFloat80(-0.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(0)_NeverTraps") { - let input = getFloat80(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(0)_NeverFails") { - let input = getFloat80(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(-0.0)_NeverTraps") { - let input = getFloat80(-0.0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(-0.0)_NeverFails") { - let input = getFloat80(-0.0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(0.0)_NeverTraps") { - let input = getFloat80(0.0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(0.0)_NeverFails") { - let input = getFloat80(0.0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(0.5)_NeverTraps") { - let input = getFloat80(0.5) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(0.5)_AlwaysFails") { - let input = getFloat80(0.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(127.5)_NeverTraps") { - let input = getFloat80(127.5) - let actual = UInt16(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(127.5)_AlwaysFails") { - let input = getFloat80(127.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(255.5)_NeverTraps") { - let input = getFloat80(255.5) - let actual = UInt16(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(255.5)_AlwaysFails") { - let input = getFloat80(255.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(32767.5)_NeverTraps") { - let input = getFloat80(32767.5) - let actual = UInt16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(32767.5)_AlwaysFails") { - let input = getFloat80(32767.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(65535)_NeverTraps") { - let input = getFloat80(65535) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(65535)_NeverFails") { - let input = getFloat80(65535) - let actual = UInt16(exactly: input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(65535.5)_NeverTraps") { - let input = getFloat80(65535.5) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(65535.5)_AlwaysFails") { - let input = getFloat80(65535.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(65536)_AlwaysTraps") { - let input = getFloat80(65536) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(65536)_AlwaysFails") { - let input = getFloat80(65536) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(18446744073709551615)_AlwaysTraps") { - let input = getFloat80(18446744073709551615) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(18446744073709551615)_AlwaysFails") { - let input = getFloat80(18446744073709551615) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(-.infinity)_AlwaysTraps") { - let input = getFloat80(-.infinity) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(-.infinity)_AlwaysFails") { - let input = getFloat80(-.infinity) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(+.infinity)_AlwaysTraps") { - let input = getFloat80(+.infinity) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(+.infinity)_AlwaysFails") { - let input = getFloat80(+.infinity) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(-.nan)_AlwaysTraps") { - let input = getFloat80(-.nan) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(-.nan)_AlwaysFails") { - let input = getFloat80(-.nan) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(+.nan)_AlwaysTraps") { - let input = getFloat80(+.nan) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(+.nan)_AlwaysFails") { - let input = getFloat80(+.nan) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(-.signalingNaN)_AlwaysTraps") { - let input = getFloat80(-.signalingNaN) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(-.signalingNaN)_AlwaysFails") { - let input = getFloat80(-.signalingNaN) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(+.signalingNaN)_AlwaysTraps") { - let input = getFloat80(+.signalingNaN) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt16.test("FromFloat80(+.signalingNaN)_AlwaysFails") { - let input = getFloat80(+.signalingNaN) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt16 +.test("FromFloat80_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getFloat80(-0.5)), + (getUInt16(+0), getFloat80(+0)), + (getUInt16(+0), getFloat80(-0)), + (getUInt16(+0), getFloat80(+0.5)), + (getUInt16(+127), getFloat80(+127.5)), + (getUInt16(+255), getFloat80(+255.5)), + (getUInt16(+32767), getFloat80(+32767.5)), + (getUInt16(+65535), getFloat80(+65535)), + (getUInt16(+65535), getFloat80(+65535.5)), +]) { + expectEqual($0.0, UInt16($0.1)) +} + +FixedPointConversion_Debug64_ToUInt16 +.test("FromFloat80_NeverFails") +.forEach(in: [ + (getUInt16(+0), getFloat80(+0)), + (getUInt16(+0), getFloat80(-0)), + (getUInt16(+65535), getFloat80(+65535)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToUInt16 +.test("FromFloat80_AlwaysTraps") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-1), + getFloat80(+65536), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt16($0)) +} + +FixedPointConversion_Debug64_ToUInt16 +.test("FromFloat80_AlwaysFails") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-1), + getFloat80(-0.5), + getFloat80(+0.5), + getFloat80(+127.5), + getFloat80(+255.5), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(+65536), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectNil(UInt16(exactly: $0)) } #endif // Float80 diff --git a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug64_ToUInt32.swift b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug64_ToUInt32.swift index 65e9e79869b8f..ca538a5cb893a 100644 --- a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug64_ToUInt32.swift +++ b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug64_ToUInt32.swift @@ -14,1620 +14,663 @@ import StdlibUnittest -let FixedPointConversion_Debug64_ToUInt32 = TestSuite("FixedPointConversion_Debug64_ToUInt32") +let FixedPointConversion_Debug64_ToUInt32 = TestSuite( + "FixedPointConversion_Debug64_ToUInt32" +) //===----------------------------------------------------------------------===// -// MARK: UInt8: (0)...(255) +// MARK: UInt8: (+0)...(+255) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt32.test("FromUInt8(0)_NeverTraps") { - let input = getUInt8(0) - let actual = UInt32(input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt32 +.test("FromUInt8_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getUInt8(+0)), + (getUInt32(+255), getUInt8(+255)), +]) { + expectEqual($0.0, UInt32($0.1)) } -FixedPointConversion_Debug64_ToUInt32.test("FromUInt8(0)_NeverFails") { - let input = getUInt8(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromUInt8(255)_NeverTraps") { - let input = getUInt8(255) - let actual = UInt32(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromUInt8(255)_NeverFails") { - let input = getUInt8(255) - let actual = UInt32(exactly: input) - expectEqual(255, actual) +FixedPointConversion_Debug64_ToUInt32 +.test("FromUInt8_NeverFails") +.forEach(in: [ + (getUInt32(+0), getUInt8(+0)), + (getUInt32(+255), getUInt8(+255)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int8: (-128)...(127) +// MARK: Int8: (-128)...(+127) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt32.test("FromInt8(-128)_AlwaysTraps") { - let input = getInt8(-128) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } +FixedPointConversion_Debug64_ToUInt32 +.test("FromInt8_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getInt8(+0)), + (getUInt32(+127), getInt8(+127)), +]) { + expectEqual($0.0, UInt32($0.1)) } -FixedPointConversion_Debug64_ToUInt32.test("FromInt8(-128)_AlwaysFails") { - let input = getInt8(-128) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt32 +.test("FromInt8_NeverFails") +.forEach(in: [ + (getUInt32(+0), getInt8(+0)), + (getUInt32(+127), getInt8(+127)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) } -FixedPointConversion_Debug64_ToUInt32.test("FromInt8(-1)_AlwaysTraps") { - let input = getInt8(-1) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } +FixedPointConversion_Debug64_ToUInt32 +.test("FromInt8_AlwaysTraps") +.forEach(in: [ + getInt8(-128), + getInt8(-1), +]) { + expectCrashLater() + _blackHole(UInt32($0)) } -FixedPointConversion_Debug64_ToUInt32.test("FromInt8(-1)_AlwaysFails") { - let input = getInt8(-1) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromInt8(0)_NeverTraps") { - let input = getInt8(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromInt8(0)_NeverFails") { - let input = getInt8(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromInt8(127)_NeverTraps") { - let input = getInt8(127) - let actual = UInt32(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromInt8(127)_NeverFails") { - let input = getInt8(127) - let actual = UInt32(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Debug64_ToUInt32 +.test("FromInt8_AlwaysFails") +.forEach(in: [ + getInt8(-128), + getInt8(-1), +]) { + expectNil(UInt32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt16: (0)...(65535) +// MARK: UInt16: (+0)...(+65535) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt32.test("FromUInt16(0)_NeverTraps") { - let input = getUInt16(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromUInt16(0)_NeverFails") { - let input = getUInt16(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromUInt16(65535)_NeverTraps") { - let input = getUInt16(65535) - let actual = UInt32(input) - expectEqual(65535, actual) +FixedPointConversion_Debug64_ToUInt32 +.test("FromUInt16_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getUInt16(+0)), + (getUInt32(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, UInt32($0.1)) } -FixedPointConversion_Debug64_ToUInt32.test("FromUInt16(65535)_NeverFails") { - let input = getUInt16(65535) - let actual = UInt32(exactly: input) - expectEqual(65535, actual) +FixedPointConversion_Debug64_ToUInt32 +.test("FromUInt16_NeverFails") +.forEach(in: [ + (getUInt32(+0), getUInt16(+0)), + (getUInt32(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int16: (-32768)...(32767) +// MARK: Int16: (-32768)...(+32767) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt32.test("FromInt16(-32768)_AlwaysTraps") { - let input = getInt16(-32768) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromInt16(-32768)_AlwaysFails") { - let input = getInt16(-32768) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromInt16(-1)_AlwaysTraps") { - let input = getInt16(-1) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } +FixedPointConversion_Debug64_ToUInt32 +.test("FromInt16_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getInt16(+0)), + (getUInt32(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, UInt32($0.1)) } -FixedPointConversion_Debug64_ToUInt32.test("FromInt16(-1)_AlwaysFails") { - let input = getInt16(-1) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt32 +.test("FromInt16_NeverFails") +.forEach(in: [ + (getUInt32(+0), getInt16(+0)), + (getUInt32(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) } -FixedPointConversion_Debug64_ToUInt32.test("FromInt16(0)_NeverTraps") { - let input = getInt16(0) - let actual = UInt32(input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt32 +.test("FromInt16_AlwaysTraps") +.forEach(in: [ + getInt16(-32768), + getInt16(-1), +]) { + expectCrashLater() + _blackHole(UInt32($0)) } -FixedPointConversion_Debug64_ToUInt32.test("FromInt16(0)_NeverFails") { - let input = getInt16(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromInt16(32767)_NeverTraps") { - let input = getInt16(32767) - let actual = UInt32(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromInt16(32767)_NeverFails") { - let input = getInt16(32767) - let actual = UInt32(exactly: input) - expectEqual(32767, actual) +FixedPointConversion_Debug64_ToUInt32 +.test("FromInt16_AlwaysFails") +.forEach(in: [ + getInt16(-32768), + getInt16(-1), +]) { + expectNil(UInt32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt32: (0)...(4294967295) +// MARK: UInt32: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt32.test("FromUInt32(0)_NeverTraps") { - let input = getUInt32(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromUInt32(0)_NeverFails") { - let input = getUInt32(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt32 +.test("FromUInt32_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getUInt32(+0)), + (getUInt32(+4294967295), getUInt32(+4294967295)), +]) { + expectEqual($0.0, UInt32($0.1)) } -FixedPointConversion_Debug64_ToUInt32.test("FromUInt32(4294967295)_NeverTraps") { - let input = getUInt32(4294967295) - let actual = UInt32(input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromUInt32(4294967295)_NeverFails") { - let input = getUInt32(4294967295) - let actual = UInt32(exactly: input) - expectEqual(4294967295, actual) +FixedPointConversion_Debug64_ToUInt32 +.test("FromUInt32_NeverFails") +.forEach(in: [ + (getUInt32(+0), getUInt32(+0)), + (getUInt32(+4294967295), getUInt32(+4294967295)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int32: (-2147483648)...(2147483647) +// MARK: Int32: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt32.test("FromInt32(-2147483648)_AlwaysTraps") { - let input = getInt32(-2147483648) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromInt32(-2147483648)_AlwaysFails") { - let input = getInt32(-2147483648) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt32 +.test("FromInt32_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getInt32(+0)), + (getUInt32(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, UInt32($0.1)) } -FixedPointConversion_Debug64_ToUInt32.test("FromInt32(-1)_AlwaysTraps") { - let input = getInt32(-1) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } +FixedPointConversion_Debug64_ToUInt32 +.test("FromInt32_NeverFails") +.forEach(in: [ + (getUInt32(+0), getInt32(+0)), + (getUInt32(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) } -FixedPointConversion_Debug64_ToUInt32.test("FromInt32(-1)_AlwaysFails") { - let input = getInt32(-1) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt32 +.test("FromInt32_AlwaysTraps") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-1), +]) { + expectCrashLater() + _blackHole(UInt32($0)) } -FixedPointConversion_Debug64_ToUInt32.test("FromInt32(0)_NeverTraps") { - let input = getInt32(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromInt32(0)_NeverFails") { - let input = getInt32(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromInt32(2147483647)_NeverTraps") { - let input = getInt32(2147483647) - let actual = UInt32(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromInt32(2147483647)_NeverFails") { - let input = getInt32(2147483647) - let actual = UInt32(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Debug64_ToUInt32 +.test("FromInt32_AlwaysFails") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-1), +]) { + expectNil(UInt32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt64: (0)...(18446744073709551615) +// MARK: UInt64: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt32.test("FromUInt64(0)_NeverTraps") { - let input = getUInt64(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromUInt64(0)_NeverFails") { - let input = getUInt64(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromUInt64(4294967295)_NeverTraps") { - let input = getUInt64(4294967295) - let actual = UInt32(input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromUInt64(4294967295)_NeverFails") { - let input = getUInt64(4294967295) - let actual = UInt32(exactly: input) - expectEqual(4294967295, actual) +FixedPointConversion_Debug64_ToUInt32 +.test("FromUInt64_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getUInt64(+0)), + (getUInt32(+4294967295), getUInt64(+4294967295)), +]) { + expectEqual($0.0, UInt32($0.1)) } -FixedPointConversion_Debug64_ToUInt32.test("FromUInt64(4294967296)_AlwaysTraps") { - let input = getUInt64(4294967296) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } +FixedPointConversion_Debug64_ToUInt32 +.test("FromUInt64_NeverFails") +.forEach(in: [ + (getUInt32(+0), getUInt64(+0)), + (getUInt32(+4294967295), getUInt64(+4294967295)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) } -FixedPointConversion_Debug64_ToUInt32.test("FromUInt64(4294967296)_AlwaysFails") { - let input = getUInt64(4294967296) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt32 +.test("FromUInt64_AlwaysTraps") +.forEach(in: [ + getUInt64(+4294967296), + getUInt64(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(UInt32($0)) } -FixedPointConversion_Debug64_ToUInt32.test("FromUInt64(18446744073709551615)_AlwaysTraps") { - let input = getUInt64(18446744073709551615) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromUInt64(18446744073709551615)_AlwaysFails") { - let input = getUInt64(18446744073709551615) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt32 +.test("FromUInt64_AlwaysFails") +.forEach(in: [ + getUInt64(+4294967296), + getUInt64(+18446744073709551615), +]) { + expectNil(UInt32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int64: (-9223372036854775808)...(9223372036854775807) +// MARK: Int64: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt32.test("FromInt64(-9223372036854775808)_AlwaysTraps") { - let input = getInt64(-9223372036854775808) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromInt64(-9223372036854775808)_AlwaysFails") { - let input = getInt64(-9223372036854775808) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromInt64(-1)_AlwaysTraps") { - let input = getInt64(-1) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromInt64(-1)_AlwaysFails") { - let input = getInt64(-1) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromInt64(0)_NeverTraps") { - let input = getInt64(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromInt64(0)_NeverFails") { - let input = getInt64(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromInt64(4294967295)_NeverTraps") { - let input = getInt64(4294967295) - let actual = UInt32(input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromInt64(4294967295)_NeverFails") { - let input = getInt64(4294967295) - let actual = UInt32(exactly: input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromInt64(4294967296)_AlwaysTraps") { - let input = getInt64(4294967296) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromInt64(4294967296)_AlwaysFails") { - let input = getInt64(4294967296) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromInt64(9223372036854775807)_AlwaysTraps") { - let input = getInt64(9223372036854775807) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromInt64(9223372036854775807)_AlwaysFails") { - let input = getInt64(9223372036854775807) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt32 +.test("FromInt64_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getInt64(+0)), + (getUInt32(+4294967295), getInt64(+4294967295)), +]) { + expectEqual($0.0, UInt32($0.1)) +} + +FixedPointConversion_Debug64_ToUInt32 +.test("FromInt64_NeverFails") +.forEach(in: [ + (getUInt32(+0), getInt64(+0)), + (getUInt32(+4294967295), getInt64(+4294967295)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToUInt32 +.test("FromInt64_AlwaysTraps") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-1), + getInt64(+4294967296), + getInt64(+9223372036854775807), +]) { + expectCrashLater() + _blackHole(UInt32($0)) +} + +FixedPointConversion_Debug64_ToUInt32 +.test("FromInt64_AlwaysFails") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-1), + getInt64(+4294967296), + getInt64(+9223372036854775807), +]) { + expectNil(UInt32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt: (0)...(18446744073709551615) +// MARK: UInt: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt32.test("FromUInt(0)_NeverTraps") { - let input = getUInt(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromUInt(0)_NeverFails") { - let input = getUInt(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromUInt(4294967295)_NeverTraps") { - let input = getUInt(4294967295) - let actual = UInt32(input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromUInt(4294967295)_NeverFails") { - let input = getUInt(4294967295) - let actual = UInt32(exactly: input) - expectEqual(4294967295, actual) +FixedPointConversion_Debug64_ToUInt32 +.test("FromUInt_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getUInt(+0)), + (getUInt32(+4294967295), getUInt(+4294967295)), +]) { + expectEqual($0.0, UInt32($0.1)) } -FixedPointConversion_Debug64_ToUInt32.test("FromUInt(4294967296)_AlwaysTraps") { - let input = getUInt(4294967296) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } +FixedPointConversion_Debug64_ToUInt32 +.test("FromUInt_NeverFails") +.forEach(in: [ + (getUInt32(+0), getUInt(+0)), + (getUInt32(+4294967295), getUInt(+4294967295)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) } -FixedPointConversion_Debug64_ToUInt32.test("FromUInt(4294967296)_AlwaysFails") { - let input = getUInt(4294967296) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt32 +.test("FromUInt_AlwaysTraps") +.forEach(in: [ + getUInt(+4294967296), + getUInt(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(UInt32($0)) } -FixedPointConversion_Debug64_ToUInt32.test("FromUInt(18446744073709551615)_AlwaysTraps") { - let input = getUInt(18446744073709551615) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromUInt(18446744073709551615)_AlwaysFails") { - let input = getUInt(18446744073709551615) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt32 +.test("FromUInt_AlwaysFails") +.forEach(in: [ + getUInt(+4294967296), + getUInt(+18446744073709551615), +]) { + expectNil(UInt32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int: (-9223372036854775808)...(9223372036854775807) +// MARK: Int: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt32.test("FromInt(-9223372036854775808)_AlwaysTraps") { - let input = getInt(-9223372036854775808) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromInt(-9223372036854775808)_AlwaysFails") { - let input = getInt(-9223372036854775808) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromInt(-1)_AlwaysTraps") { - let input = getInt(-1) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromInt(-1)_AlwaysFails") { - let input = getInt(-1) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromInt(0)_NeverTraps") { - let input = getInt(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromInt(0)_NeverFails") { - let input = getInt(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromInt(4294967295)_NeverTraps") { - let input = getInt(4294967295) - let actual = UInt32(input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromInt(4294967295)_NeverFails") { - let input = getInt(4294967295) - let actual = UInt32(exactly: input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromInt(4294967296)_AlwaysTraps") { - let input = getInt(4294967296) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromInt(4294967296)_AlwaysFails") { - let input = getInt(4294967296) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromInt(9223372036854775807)_AlwaysTraps") { - let input = getInt(9223372036854775807) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromInt(9223372036854775807)_AlwaysFails") { - let input = getInt(9223372036854775807) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt32 +.test("FromInt_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getInt(+0)), + (getUInt32(+4294967295), getInt(+4294967295)), +]) { + expectEqual($0.0, UInt32($0.1)) +} + +FixedPointConversion_Debug64_ToUInt32 +.test("FromInt_NeverFails") +.forEach(in: [ + (getUInt32(+0), getInt(+0)), + (getUInt32(+4294967295), getInt(+4294967295)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToUInt32 +.test("FromInt_AlwaysTraps") +.forEach(in: [ + getInt(-9223372036854775808), + getInt(-1), + getInt(+4294967296), + getInt(+9223372036854775807), +]) { + expectCrashLater() + _blackHole(UInt32($0)) +} + +FixedPointConversion_Debug64_ToUInt32 +.test("FromInt_AlwaysFails") +.forEach(in: [ + getInt(-9223372036854775808), + getInt(-1), + getInt(+4294967296), + getInt(+9223372036854775807), +]) { + expectNil(UInt32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float16: (-2047)...(2047) +// MARK: Float16: (-2047)...(+2047) //===----------------------------------------------------------------------===// #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -FixedPointConversion_Debug64_ToUInt32.test("FromFloat16(-2047)_AlwaysTraps") { - let input = getFloat16(-2047) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat16(-2047)_AlwaysFails") { - let input = getFloat16(-2047) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat16(-128.5)_AlwaysTraps") { - let input = getFloat16(-128.5) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat16(-128.5)_AlwaysFails") { - let input = getFloat16(-128.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat16(-1)_AlwaysTraps") { - let input = getFloat16(-1) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat16(-1)_AlwaysFails") { - let input = getFloat16(-1) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat16(-0.5)_NeverTraps") { - let input = getFloat16(-0.5) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat16(-0.5)_AlwaysFails") { - let input = getFloat16(-0.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat16(0)_NeverTraps") { - let input = getFloat16(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat16(0)_NeverFails") { - let input = getFloat16(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat16(-0.0)_NeverTraps") { - let input = getFloat16(-0.0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat16(-0.0)_NeverFails") { - let input = getFloat16(-0.0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat16(0.0)_NeverTraps") { - let input = getFloat16(0.0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat16(0.0)_NeverFails") { - let input = getFloat16(0.0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat16(0.5)_NeverTraps") { - let input = getFloat16(0.5) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat16(0.5)_AlwaysFails") { - let input = getFloat16(0.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat16(127.5)_NeverTraps") { - let input = getFloat16(127.5) - let actual = UInt32(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat16(127.5)_AlwaysFails") { - let input = getFloat16(127.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat16(255.5)_NeverTraps") { - let input = getFloat16(255.5) - let actual = UInt32(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat16(255.5)_AlwaysFails") { - let input = getFloat16(255.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat16(2047)_NeverTraps") { - let input = getFloat16(2047) - let actual = UInt32(input) - expectEqual(2047, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat16(2047)_NeverFails") { - let input = getFloat16(2047) - let actual = UInt32(exactly: input) - expectEqual(2047, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat16(-.infinity)_AlwaysTraps") { - let input = getFloat16(-.infinity) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat16(-.infinity)_AlwaysFails") { - let input = getFloat16(-.infinity) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat16(+.infinity)_AlwaysTraps") { - let input = getFloat16(+.infinity) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat16(+.infinity)_AlwaysFails") { - let input = getFloat16(+.infinity) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat16(-.nan)_AlwaysTraps") { - let input = getFloat16(-.nan) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat16(-.nan)_AlwaysFails") { - let input = getFloat16(-.nan) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat16(+.nan)_AlwaysTraps") { - let input = getFloat16(+.nan) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat16(+.nan)_AlwaysFails") { - let input = getFloat16(+.nan) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat16(-.signalingNaN)_AlwaysTraps") { - let input = getFloat16(-.signalingNaN) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat16(-.signalingNaN)_AlwaysFails") { - let input = getFloat16(-.signalingNaN) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat16(+.signalingNaN)_AlwaysTraps") { - let input = getFloat16(+.signalingNaN) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat16(+.signalingNaN)_AlwaysFails") { - let input = getFloat16(+.signalingNaN) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt32 +.test("FromFloat16_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getFloat16(-0.5)), + (getUInt32(+0), getFloat16(+0)), + (getUInt32(+0), getFloat16(-0)), + (getUInt32(+0), getFloat16(+0.5)), + (getUInt32(+127), getFloat16(+127.5)), + (getUInt32(+255), getFloat16(+255.5)), + (getUInt32(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, UInt32($0.1)) +} + +FixedPointConversion_Debug64_ToUInt32 +.test("FromFloat16_NeverFails") +.forEach(in: [ + (getUInt32(+0), getFloat16(+0)), + (getUInt32(+0), getFloat16(-0)), + (getUInt32(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToUInt32 +.test("FromFloat16_AlwaysTraps") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-128.5), + getFloat16(-1), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt32($0)) +} + +FixedPointConversion_Debug64_ToUInt32 +.test("FromFloat16_AlwaysFails") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-128.5), + getFloat16(-1), + getFloat16(-0.5), + getFloat16(+0.5), + getFloat16(+127.5), + getFloat16(+255.5), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectNil(UInt32(exactly: $0)) } } #endif // Float16 //===----------------------------------------------------------------------===// -// MARK: Float32: (-16777215)...(16777215) +// MARK: Float32: (-16777215)...(+16777215) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt32.test("FromFloat32(-16777215)_AlwaysTraps") { - let input = getFloat32(-16777215) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat32(-16777215)_AlwaysFails") { - let input = getFloat32(-16777215) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat32(-32768.5)_AlwaysTraps") { - let input = getFloat32(-32768.5) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat32(-32768.5)_AlwaysFails") { - let input = getFloat32(-32768.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat32(-128.5)_AlwaysTraps") { - let input = getFloat32(-128.5) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat32(-128.5)_AlwaysFails") { - let input = getFloat32(-128.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat32(-1)_AlwaysTraps") { - let input = getFloat32(-1) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat32(-1)_AlwaysFails") { - let input = getFloat32(-1) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat32(-0.5)_NeverTraps") { - let input = getFloat32(-0.5) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat32(-0.5)_AlwaysFails") { - let input = getFloat32(-0.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat32(0)_NeverTraps") { - let input = getFloat32(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat32(0)_NeverFails") { - let input = getFloat32(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat32(-0.0)_NeverTraps") { - let input = getFloat32(-0.0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat32(-0.0)_NeverFails") { - let input = getFloat32(-0.0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat32(0.0)_NeverTraps") { - let input = getFloat32(0.0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat32(0.0)_NeverFails") { - let input = getFloat32(0.0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat32(0.5)_NeverTraps") { - let input = getFloat32(0.5) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat32(0.5)_AlwaysFails") { - let input = getFloat32(0.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat32(127.5)_NeverTraps") { - let input = getFloat32(127.5) - let actual = UInt32(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat32(127.5)_AlwaysFails") { - let input = getFloat32(127.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat32(255.5)_NeverTraps") { - let input = getFloat32(255.5) - let actual = UInt32(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat32(255.5)_AlwaysFails") { - let input = getFloat32(255.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat32(32767.5)_NeverTraps") { - let input = getFloat32(32767.5) - let actual = UInt32(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat32(32767.5)_AlwaysFails") { - let input = getFloat32(32767.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat32(65535.5)_NeverTraps") { - let input = getFloat32(65535.5) - let actual = UInt32(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat32(65535.5)_AlwaysFails") { - let input = getFloat32(65535.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat32(16777215)_NeverTraps") { - let input = getFloat32(16777215) - let actual = UInt32(input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat32(16777215)_NeverFails") { - let input = getFloat32(16777215) - let actual = UInt32(exactly: input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat32(-.infinity)_AlwaysTraps") { - let input = getFloat32(-.infinity) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat32(-.infinity)_AlwaysFails") { - let input = getFloat32(-.infinity) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat32(+.infinity)_AlwaysTraps") { - let input = getFloat32(+.infinity) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat32(+.infinity)_AlwaysFails") { - let input = getFloat32(+.infinity) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat32(-.nan)_AlwaysTraps") { - let input = getFloat32(-.nan) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat32(-.nan)_AlwaysFails") { - let input = getFloat32(-.nan) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat32(+.nan)_AlwaysTraps") { - let input = getFloat32(+.nan) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat32(+.nan)_AlwaysFails") { - let input = getFloat32(+.nan) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat32(-.signalingNaN)_AlwaysTraps") { - let input = getFloat32(-.signalingNaN) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat32(-.signalingNaN)_AlwaysFails") { - let input = getFloat32(-.signalingNaN) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat32(+.signalingNaN)_AlwaysTraps") { - let input = getFloat32(+.signalingNaN) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat32(+.signalingNaN)_AlwaysFails") { - let input = getFloat32(+.signalingNaN) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt32 +.test("FromFloat32_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getFloat32(-0.5)), + (getUInt32(+0), getFloat32(+0)), + (getUInt32(+0), getFloat32(-0)), + (getUInt32(+0), getFloat32(+0.5)), + (getUInt32(+127), getFloat32(+127.5)), + (getUInt32(+255), getFloat32(+255.5)), + (getUInt32(+32767), getFloat32(+32767.5)), + (getUInt32(+65535), getFloat32(+65535.5)), + (getUInt32(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, UInt32($0.1)) +} + +FixedPointConversion_Debug64_ToUInt32 +.test("FromFloat32_NeverFails") +.forEach(in: [ + (getUInt32(+0), getFloat32(+0)), + (getUInt32(+0), getFloat32(-0)), + (getUInt32(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToUInt32 +.test("FromFloat32_AlwaysTraps") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-1), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt32($0)) +} + +FixedPointConversion_Debug64_ToUInt32 +.test("FromFloat32_AlwaysFails") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-1), + getFloat32(-0.5), + getFloat32(+0.5), + getFloat32(+127.5), + getFloat32(+255.5), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectNil(UInt32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float64: (-9007199254740991)...(9007199254740991) +// MARK: Float64: (-9007199254740991)...(+9007199254740991) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(-9007199254740991)_AlwaysTraps") { - let input = getFloat64(-9007199254740991) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(-9007199254740991)_AlwaysFails") { - let input = getFloat64(-9007199254740991) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(-32768.5)_AlwaysTraps") { - let input = getFloat64(-32768.5) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(-32768.5)_AlwaysFails") { - let input = getFloat64(-32768.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(-128.5)_AlwaysTraps") { - let input = getFloat64(-128.5) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(-128.5)_AlwaysFails") { - let input = getFloat64(-128.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(-1)_AlwaysTraps") { - let input = getFloat64(-1) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(-1)_AlwaysFails") { - let input = getFloat64(-1) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(-0.5)_NeverTraps") { - let input = getFloat64(-0.5) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(-0.5)_AlwaysFails") { - let input = getFloat64(-0.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(0)_NeverTraps") { - let input = getFloat64(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(0)_NeverFails") { - let input = getFloat64(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(-0.0)_NeverTraps") { - let input = getFloat64(-0.0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(-0.0)_NeverFails") { - let input = getFloat64(-0.0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(0.0)_NeverTraps") { - let input = getFloat64(0.0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(0.0)_NeverFails") { - let input = getFloat64(0.0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(0.5)_NeverTraps") { - let input = getFloat64(0.5) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(0.5)_AlwaysFails") { - let input = getFloat64(0.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(127.5)_NeverTraps") { - let input = getFloat64(127.5) - let actual = UInt32(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(127.5)_AlwaysFails") { - let input = getFloat64(127.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(255.5)_NeverTraps") { - let input = getFloat64(255.5) - let actual = UInt32(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(255.5)_AlwaysFails") { - let input = getFloat64(255.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(32767.5)_NeverTraps") { - let input = getFloat64(32767.5) - let actual = UInt32(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(32767.5)_AlwaysFails") { - let input = getFloat64(32767.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(65535.5)_NeverTraps") { - let input = getFloat64(65535.5) - let actual = UInt32(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(65535.5)_AlwaysFails") { - let input = getFloat64(65535.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(4294967295)_NeverTraps") { - let input = getFloat64(4294967295) - let actual = UInt32(input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(4294967295)_NeverFails") { - let input = getFloat64(4294967295) - let actual = UInt32(exactly: input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(4294967296)_AlwaysTraps") { - let input = getFloat64(4294967296) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(4294967296)_AlwaysFails") { - let input = getFloat64(4294967296) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(9007199254740991)_AlwaysTraps") { - let input = getFloat64(9007199254740991) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(9007199254740991)_AlwaysFails") { - let input = getFloat64(9007199254740991) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(-.infinity)_AlwaysTraps") { - let input = getFloat64(-.infinity) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(-.infinity)_AlwaysFails") { - let input = getFloat64(-.infinity) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(+.infinity)_AlwaysTraps") { - let input = getFloat64(+.infinity) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(+.infinity)_AlwaysFails") { - let input = getFloat64(+.infinity) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(-.nan)_AlwaysTraps") { - let input = getFloat64(-.nan) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(-.nan)_AlwaysFails") { - let input = getFloat64(-.nan) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(+.nan)_AlwaysTraps") { - let input = getFloat64(+.nan) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(+.nan)_AlwaysFails") { - let input = getFloat64(+.nan) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(-.signalingNaN)_AlwaysTraps") { - let input = getFloat64(-.signalingNaN) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(-.signalingNaN)_AlwaysFails") { - let input = getFloat64(-.signalingNaN) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(+.signalingNaN)_AlwaysTraps") { - let input = getFloat64(+.signalingNaN) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat64(+.signalingNaN)_AlwaysFails") { - let input = getFloat64(+.signalingNaN) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt32 +.test("FromFloat64_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getFloat64(-0.5)), + (getUInt32(+0), getFloat64(+0)), + (getUInt32(+0), getFloat64(-0)), + (getUInt32(+0), getFloat64(+0.5)), + (getUInt32(+127), getFloat64(+127.5)), + (getUInt32(+255), getFloat64(+255.5)), + (getUInt32(+32767), getFloat64(+32767.5)), + (getUInt32(+65535), getFloat64(+65535.5)), + (getUInt32(+4294967295), getFloat64(+4294967295)), +]) { + expectEqual($0.0, UInt32($0.1)) +} + +FixedPointConversion_Debug64_ToUInt32 +.test("FromFloat64_NeverFails") +.forEach(in: [ + (getUInt32(+0), getFloat64(+0)), + (getUInt32(+0), getFloat64(-0)), + (getUInt32(+4294967295), getFloat64(+4294967295)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToUInt32 +.test("FromFloat64_AlwaysTraps") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-1), + getFloat64(+4294967296), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt32($0)) +} + +FixedPointConversion_Debug64_ToUInt32 +.test("FromFloat64_AlwaysFails") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-1), + getFloat64(-0.5), + getFloat64(+0.5), + getFloat64(+127.5), + getFloat64(+255.5), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(+4294967296), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectNil(UInt32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float80: (-18446744073709551615)...(18446744073709551615) +// MARK: Float80: (-18446744073709551615)...(+18446744073709551615) //===----------------------------------------------------------------------===// #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(-18446744073709551615)_AlwaysTraps") { - let input = getFloat80(-18446744073709551615) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(-18446744073709551615)_AlwaysFails") { - let input = getFloat80(-18446744073709551615) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(-32768.5)_AlwaysTraps") { - let input = getFloat80(-32768.5) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(-32768.5)_AlwaysFails") { - let input = getFloat80(-32768.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(-128.5)_AlwaysTraps") { - let input = getFloat80(-128.5) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(-128.5)_AlwaysFails") { - let input = getFloat80(-128.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(-1)_AlwaysTraps") { - let input = getFloat80(-1) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(-1)_AlwaysFails") { - let input = getFloat80(-1) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(-0.5)_NeverTraps") { - let input = getFloat80(-0.5) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(-0.5)_AlwaysFails") { - let input = getFloat80(-0.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(0)_NeverTraps") { - let input = getFloat80(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(0)_NeverFails") { - let input = getFloat80(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(-0.0)_NeverTraps") { - let input = getFloat80(-0.0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(-0.0)_NeverFails") { - let input = getFloat80(-0.0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(0.0)_NeverTraps") { - let input = getFloat80(0.0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(0.0)_NeverFails") { - let input = getFloat80(0.0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(0.5)_NeverTraps") { - let input = getFloat80(0.5) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(0.5)_AlwaysFails") { - let input = getFloat80(0.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(127.5)_NeverTraps") { - let input = getFloat80(127.5) - let actual = UInt32(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(127.5)_AlwaysFails") { - let input = getFloat80(127.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(255.5)_NeverTraps") { - let input = getFloat80(255.5) - let actual = UInt32(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(255.5)_AlwaysFails") { - let input = getFloat80(255.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(32767.5)_NeverTraps") { - let input = getFloat80(32767.5) - let actual = UInt32(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(32767.5)_AlwaysFails") { - let input = getFloat80(32767.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(65535.5)_NeverTraps") { - let input = getFloat80(65535.5) - let actual = UInt32(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(65535.5)_AlwaysFails") { - let input = getFloat80(65535.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(4294967295)_NeverTraps") { - let input = getFloat80(4294967295) - let actual = UInt32(input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(4294967295)_NeverFails") { - let input = getFloat80(4294967295) - let actual = UInt32(exactly: input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(4294967296)_AlwaysTraps") { - let input = getFloat80(4294967296) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(4294967296)_AlwaysFails") { - let input = getFloat80(4294967296) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(18446744073709551615)_AlwaysTraps") { - let input = getFloat80(18446744073709551615) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(18446744073709551615)_AlwaysFails") { - let input = getFloat80(18446744073709551615) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(-.infinity)_AlwaysTraps") { - let input = getFloat80(-.infinity) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(-.infinity)_AlwaysFails") { - let input = getFloat80(-.infinity) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(+.infinity)_AlwaysTraps") { - let input = getFloat80(+.infinity) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(+.infinity)_AlwaysFails") { - let input = getFloat80(+.infinity) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(-.nan)_AlwaysTraps") { - let input = getFloat80(-.nan) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(-.nan)_AlwaysFails") { - let input = getFloat80(-.nan) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(+.nan)_AlwaysTraps") { - let input = getFloat80(+.nan) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(+.nan)_AlwaysFails") { - let input = getFloat80(+.nan) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(-.signalingNaN)_AlwaysTraps") { - let input = getFloat80(-.signalingNaN) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(-.signalingNaN)_AlwaysFails") { - let input = getFloat80(-.signalingNaN) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(+.signalingNaN)_AlwaysTraps") { - let input = getFloat80(+.signalingNaN) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt32.test("FromFloat80(+.signalingNaN)_AlwaysFails") { - let input = getFloat80(+.signalingNaN) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt32 +.test("FromFloat80_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getFloat80(-0.5)), + (getUInt32(+0), getFloat80(+0)), + (getUInt32(+0), getFloat80(-0)), + (getUInt32(+0), getFloat80(+0.5)), + (getUInt32(+127), getFloat80(+127.5)), + (getUInt32(+255), getFloat80(+255.5)), + (getUInt32(+32767), getFloat80(+32767.5)), + (getUInt32(+65535), getFloat80(+65535.5)), + (getUInt32(+4294967295), getFloat80(+4294967295)), +]) { + expectEqual($0.0, UInt32($0.1)) +} + +FixedPointConversion_Debug64_ToUInt32 +.test("FromFloat80_NeverFails") +.forEach(in: [ + (getUInt32(+0), getFloat80(+0)), + (getUInt32(+0), getFloat80(-0)), + (getUInt32(+4294967295), getFloat80(+4294967295)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToUInt32 +.test("FromFloat80_AlwaysTraps") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-1), + getFloat80(+4294967296), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt32($0)) +} + +FixedPointConversion_Debug64_ToUInt32 +.test("FromFloat80_AlwaysFails") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-1), + getFloat80(-0.5), + getFloat80(+0.5), + getFloat80(+127.5), + getFloat80(+255.5), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(+4294967296), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectNil(UInt32(exactly: $0)) } #endif // Float80 diff --git a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug64_ToUInt64.swift b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug64_ToUInt64.swift index 151f71c42df2f..9992477e2f844 100644 --- a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug64_ToUInt64.swift +++ b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug64_ToUInt64.swift @@ -14,1464 +14,609 @@ import StdlibUnittest -let FixedPointConversion_Debug64_ToUInt64 = TestSuite("FixedPointConversion_Debug64_ToUInt64") +let FixedPointConversion_Debug64_ToUInt64 = TestSuite( + "FixedPointConversion_Debug64_ToUInt64" +) //===----------------------------------------------------------------------===// -// MARK: UInt8: (0)...(255) +// MARK: UInt8: (+0)...(+255) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt64.test("FromUInt8(0)_NeverTraps") { - let input = getUInt8(0) - let actual = UInt64(input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt64 +.test("FromUInt8_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getUInt8(+0)), + (getUInt64(+255), getUInt8(+255)), +]) { + expectEqual($0.0, UInt64($0.1)) } -FixedPointConversion_Debug64_ToUInt64.test("FromUInt8(0)_NeverFails") { - let input = getUInt8(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromUInt8(255)_NeverTraps") { - let input = getUInt8(255) - let actual = UInt64(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromUInt8(255)_NeverFails") { - let input = getUInt8(255) - let actual = UInt64(exactly: input) - expectEqual(255, actual) +FixedPointConversion_Debug64_ToUInt64 +.test("FromUInt8_NeverFails") +.forEach(in: [ + (getUInt64(+0), getUInt8(+0)), + (getUInt64(+255), getUInt8(+255)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int8: (-128)...(127) +// MARK: Int8: (-128)...(+127) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt64.test("FromInt8(-128)_AlwaysTraps") { - let input = getInt8(-128) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromInt8(-128)_AlwaysFails") { - let input = getInt8(-128) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromInt8(-1)_AlwaysTraps") { - let input = getInt8(-1) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromInt8(-1)_AlwaysFails") { - let input = getInt8(-1) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromInt8(0)_NeverTraps") { - let input = getInt8(0) - let actual = UInt64(input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt64 +.test("FromInt8_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getInt8(+0)), + (getUInt64(+127), getInt8(+127)), +]) { + expectEqual($0.0, UInt64($0.1)) } -FixedPointConversion_Debug64_ToUInt64.test("FromInt8(0)_NeverFails") { - let input = getInt8(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt64 +.test("FromInt8_NeverFails") +.forEach(in: [ + (getUInt64(+0), getInt8(+0)), + (getUInt64(+127), getInt8(+127)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) } -FixedPointConversion_Debug64_ToUInt64.test("FromInt8(127)_NeverTraps") { - let input = getInt8(127) - let actual = UInt64(input) - expectEqual(127, actual) +FixedPointConversion_Debug64_ToUInt64 +.test("FromInt8_AlwaysTraps") +.forEach(in: [ + getInt8(-128), + getInt8(-1), +]) { + expectCrashLater() + _blackHole(UInt64($0)) } -FixedPointConversion_Debug64_ToUInt64.test("FromInt8(127)_NeverFails") { - let input = getInt8(127) - let actual = UInt64(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Debug64_ToUInt64 +.test("FromInt8_AlwaysFails") +.forEach(in: [ + getInt8(-128), + getInt8(-1), +]) { + expectNil(UInt64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt16: (0)...(65535) +// MARK: UInt16: (+0)...(+65535) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt64.test("FromUInt16(0)_NeverTraps") { - let input = getUInt16(0) - let actual = UInt64(input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt64 +.test("FromUInt16_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getUInt16(+0)), + (getUInt64(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, UInt64($0.1)) } -FixedPointConversion_Debug64_ToUInt64.test("FromUInt16(0)_NeverFails") { - let input = getUInt16(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromUInt16(65535)_NeverTraps") { - let input = getUInt16(65535) - let actual = UInt64(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromUInt16(65535)_NeverFails") { - let input = getUInt16(65535) - let actual = UInt64(exactly: input) - expectEqual(65535, actual) +FixedPointConversion_Debug64_ToUInt64 +.test("FromUInt16_NeverFails") +.forEach(in: [ + (getUInt64(+0), getUInt16(+0)), + (getUInt64(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int16: (-32768)...(32767) +// MARK: Int16: (-32768)...(+32767) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt64.test("FromInt16(-32768)_AlwaysTraps") { - let input = getInt16(-32768) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromInt16(-32768)_AlwaysFails") { - let input = getInt16(-32768) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromInt16(-1)_AlwaysTraps") { - let input = getInt16(-1) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromInt16(-1)_AlwaysFails") { - let input = getInt16(-1) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromInt16(0)_NeverTraps") { - let input = getInt16(0) - let actual = UInt64(input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt64 +.test("FromInt16_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getInt16(+0)), + (getUInt64(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, UInt64($0.1)) } -FixedPointConversion_Debug64_ToUInt64.test("FromInt16(0)_NeverFails") { - let input = getInt16(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt64 +.test("FromInt16_NeverFails") +.forEach(in: [ + (getUInt64(+0), getInt16(+0)), + (getUInt64(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) } -FixedPointConversion_Debug64_ToUInt64.test("FromInt16(32767)_NeverTraps") { - let input = getInt16(32767) - let actual = UInt64(input) - expectEqual(32767, actual) +FixedPointConversion_Debug64_ToUInt64 +.test("FromInt16_AlwaysTraps") +.forEach(in: [ + getInt16(-32768), + getInt16(-1), +]) { + expectCrashLater() + _blackHole(UInt64($0)) } -FixedPointConversion_Debug64_ToUInt64.test("FromInt16(32767)_NeverFails") { - let input = getInt16(32767) - let actual = UInt64(exactly: input) - expectEqual(32767, actual) +FixedPointConversion_Debug64_ToUInt64 +.test("FromInt16_AlwaysFails") +.forEach(in: [ + getInt16(-32768), + getInt16(-1), +]) { + expectNil(UInt64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt32: (0)...(4294967295) +// MARK: UInt32: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt64.test("FromUInt32(0)_NeverTraps") { - let input = getUInt32(0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromUInt32(0)_NeverFails") { - let input = getUInt32(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt64 +.test("FromUInt32_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getUInt32(+0)), + (getUInt64(+4294967295), getUInt32(+4294967295)), +]) { + expectEqual($0.0, UInt64($0.1)) } -FixedPointConversion_Debug64_ToUInt64.test("FromUInt32(4294967295)_NeverTraps") { - let input = getUInt32(4294967295) - let actual = UInt64(input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromUInt32(4294967295)_NeverFails") { - let input = getUInt32(4294967295) - let actual = UInt64(exactly: input) - expectEqual(4294967295, actual) +FixedPointConversion_Debug64_ToUInt64 +.test("FromUInt32_NeverFails") +.forEach(in: [ + (getUInt64(+0), getUInt32(+0)), + (getUInt64(+4294967295), getUInt32(+4294967295)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int32: (-2147483648)...(2147483647) +// MARK: Int32: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt64.test("FromInt32(-2147483648)_AlwaysTraps") { - let input = getInt32(-2147483648) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromInt32(-2147483648)_AlwaysFails") { - let input = getInt32(-2147483648) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromInt32(-1)_AlwaysTraps") { - let input = getInt32(-1) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } +FixedPointConversion_Debug64_ToUInt64 +.test("FromInt32_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getInt32(+0)), + (getUInt64(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, UInt64($0.1)) } -FixedPointConversion_Debug64_ToUInt64.test("FromInt32(-1)_AlwaysFails") { - let input = getInt32(-1) - let actual = UInt64(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt64 +.test("FromInt32_NeverFails") +.forEach(in: [ + (getUInt64(+0), getInt32(+0)), + (getUInt64(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) } -FixedPointConversion_Debug64_ToUInt64.test("FromInt32(0)_NeverTraps") { - let input = getInt32(0) - let actual = UInt64(input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt64 +.test("FromInt32_AlwaysTraps") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-1), +]) { + expectCrashLater() + _blackHole(UInt64($0)) } -FixedPointConversion_Debug64_ToUInt64.test("FromInt32(0)_NeverFails") { - let input = getInt32(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromInt32(2147483647)_NeverTraps") { - let input = getInt32(2147483647) - let actual = UInt64(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromInt32(2147483647)_NeverFails") { - let input = getInt32(2147483647) - let actual = UInt64(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Debug64_ToUInt64 +.test("FromInt32_AlwaysFails") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-1), +]) { + expectNil(UInt64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt64: (0)...(18446744073709551615) +// MARK: UInt64: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt64.test("FromUInt64(0)_NeverTraps") { - let input = getUInt64(0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromUInt64(0)_NeverFails") { - let input = getUInt64(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt64 +.test("FromUInt64_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getUInt64(+0)), + (getUInt64(+18446744073709551615), getUInt64(+18446744073709551615)), +]) { + expectEqual($0.0, UInt64($0.1)) } -FixedPointConversion_Debug64_ToUInt64.test("FromUInt64(18446744073709551615)_NeverTraps") { - let input = getUInt64(18446744073709551615) - let actual = UInt64(input) - expectEqual(18446744073709551615, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromUInt64(18446744073709551615)_NeverFails") { - let input = getUInt64(18446744073709551615) - let actual = UInt64(exactly: input) - expectEqual(18446744073709551615, actual) +FixedPointConversion_Debug64_ToUInt64 +.test("FromUInt64_NeverFails") +.forEach(in: [ + (getUInt64(+0), getUInt64(+0)), + (getUInt64(+18446744073709551615), getUInt64(+18446744073709551615)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int64: (-9223372036854775808)...(9223372036854775807) +// MARK: Int64: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt64.test("FromInt64(-9223372036854775808)_AlwaysTraps") { - let input = getInt64(-9223372036854775808) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromInt64(-9223372036854775808)_AlwaysFails") { - let input = getInt64(-9223372036854775808) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromInt64(-1)_AlwaysTraps") { - let input = getInt64(-1) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromInt64(-1)_AlwaysFails") { - let input = getInt64(-1) - let actual = UInt64(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt64 +.test("FromInt64_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getInt64(+0)), + (getUInt64(+9223372036854775807), getInt64(+9223372036854775807)), +]) { + expectEqual($0.0, UInt64($0.1)) } -FixedPointConversion_Debug64_ToUInt64.test("FromInt64(0)_NeverTraps") { - let input = getInt64(0) - let actual = UInt64(input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt64 +.test("FromInt64_NeverFails") +.forEach(in: [ + (getUInt64(+0), getInt64(+0)), + (getUInt64(+9223372036854775807), getInt64(+9223372036854775807)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) } -FixedPointConversion_Debug64_ToUInt64.test("FromInt64(0)_NeverFails") { - let input = getInt64(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt64 +.test("FromInt64_AlwaysTraps") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-1), +]) { + expectCrashLater() + _blackHole(UInt64($0)) } -FixedPointConversion_Debug64_ToUInt64.test("FromInt64(9223372036854775807)_NeverTraps") { - let input = getInt64(9223372036854775807) - let actual = UInt64(input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromInt64(9223372036854775807)_NeverFails") { - let input = getInt64(9223372036854775807) - let actual = UInt64(exactly: input) - expectEqual(9223372036854775807, actual) +FixedPointConversion_Debug64_ToUInt64 +.test("FromInt64_AlwaysFails") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-1), +]) { + expectNil(UInt64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt: (0)...(18446744073709551615) +// MARK: UInt: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt64.test("FromUInt(0)_NeverTraps") { - let input = getUInt(0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromUInt(0)_NeverFails") { - let input = getUInt(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromUInt(18446744073709551615)_NeverTraps") { - let input = getUInt(18446744073709551615) - let actual = UInt64(input) - expectEqual(18446744073709551615, actual) +FixedPointConversion_Debug64_ToUInt64 +.test("FromUInt_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getUInt(+0)), + (getUInt64(+18446744073709551615), getUInt(+18446744073709551615)), +]) { + expectEqual($0.0, UInt64($0.1)) } -FixedPointConversion_Debug64_ToUInt64.test("FromUInt(18446744073709551615)_NeverFails") { - let input = getUInt(18446744073709551615) - let actual = UInt64(exactly: input) - expectEqual(18446744073709551615, actual) +FixedPointConversion_Debug64_ToUInt64 +.test("FromUInt_NeverFails") +.forEach(in: [ + (getUInt64(+0), getUInt(+0)), + (getUInt64(+18446744073709551615), getUInt(+18446744073709551615)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int: (-9223372036854775808)...(9223372036854775807) +// MARK: Int: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt64.test("FromInt(-9223372036854775808)_AlwaysTraps") { - let input = getInt(-9223372036854775808) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromInt(-9223372036854775808)_AlwaysFails") { - let input = getInt(-9223372036854775808) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromInt(-1)_AlwaysTraps") { - let input = getInt(-1) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromInt(-1)_AlwaysFails") { - let input = getInt(-1) - let actual = UInt64(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt64 +.test("FromInt_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getInt(+0)), + (getUInt64(+9223372036854775807), getInt(+9223372036854775807)), +]) { + expectEqual($0.0, UInt64($0.1)) } -FixedPointConversion_Debug64_ToUInt64.test("FromInt(0)_NeverTraps") { - let input = getInt(0) - let actual = UInt64(input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt64 +.test("FromInt_NeverFails") +.forEach(in: [ + (getUInt64(+0), getInt(+0)), + (getUInt64(+9223372036854775807), getInt(+9223372036854775807)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) } -FixedPointConversion_Debug64_ToUInt64.test("FromInt(0)_NeverFails") { - let input = getInt(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt64 +.test("FromInt_AlwaysTraps") +.forEach(in: [ + getInt(-9223372036854775808), + getInt(-1), +]) { + expectCrashLater() + _blackHole(UInt64($0)) } -FixedPointConversion_Debug64_ToUInt64.test("FromInt(9223372036854775807)_NeverTraps") { - let input = getInt(9223372036854775807) - let actual = UInt64(input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromInt(9223372036854775807)_NeverFails") { - let input = getInt(9223372036854775807) - let actual = UInt64(exactly: input) - expectEqual(9223372036854775807, actual) +FixedPointConversion_Debug64_ToUInt64 +.test("FromInt_AlwaysFails") +.forEach(in: [ + getInt(-9223372036854775808), + getInt(-1), +]) { + expectNil(UInt64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float16: (-2047)...(2047) +// MARK: Float16: (-2047)...(+2047) //===----------------------------------------------------------------------===// #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -FixedPointConversion_Debug64_ToUInt64.test("FromFloat16(-2047)_AlwaysTraps") { - let input = getFloat16(-2047) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat16(-2047)_AlwaysFails") { - let input = getFloat16(-2047) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat16(-128.5)_AlwaysTraps") { - let input = getFloat16(-128.5) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat16(-128.5)_AlwaysFails") { - let input = getFloat16(-128.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat16(-1)_AlwaysTraps") { - let input = getFloat16(-1) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat16(-1)_AlwaysFails") { - let input = getFloat16(-1) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat16(-0.5)_NeverTraps") { - let input = getFloat16(-0.5) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat16(-0.5)_AlwaysFails") { - let input = getFloat16(-0.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat16(0)_NeverTraps") { - let input = getFloat16(0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat16(0)_NeverFails") { - let input = getFloat16(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat16(-0.0)_NeverTraps") { - let input = getFloat16(-0.0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat16(-0.0)_NeverFails") { - let input = getFloat16(-0.0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat16(0.0)_NeverTraps") { - let input = getFloat16(0.0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat16(0.0)_NeverFails") { - let input = getFloat16(0.0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat16(0.5)_NeverTraps") { - let input = getFloat16(0.5) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat16(0.5)_AlwaysFails") { - let input = getFloat16(0.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat16(127.5)_NeverTraps") { - let input = getFloat16(127.5) - let actual = UInt64(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat16(127.5)_AlwaysFails") { - let input = getFloat16(127.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat16(255.5)_NeverTraps") { - let input = getFloat16(255.5) - let actual = UInt64(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat16(255.5)_AlwaysFails") { - let input = getFloat16(255.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat16(2047)_NeverTraps") { - let input = getFloat16(2047) - let actual = UInt64(input) - expectEqual(2047, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat16(2047)_NeverFails") { - let input = getFloat16(2047) - let actual = UInt64(exactly: input) - expectEqual(2047, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat16(-.infinity)_AlwaysTraps") { - let input = getFloat16(-.infinity) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat16(-.infinity)_AlwaysFails") { - let input = getFloat16(-.infinity) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat16(+.infinity)_AlwaysTraps") { - let input = getFloat16(+.infinity) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat16(+.infinity)_AlwaysFails") { - let input = getFloat16(+.infinity) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat16(-.nan)_AlwaysTraps") { - let input = getFloat16(-.nan) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat16(-.nan)_AlwaysFails") { - let input = getFloat16(-.nan) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat16(+.nan)_AlwaysTraps") { - let input = getFloat16(+.nan) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat16(+.nan)_AlwaysFails") { - let input = getFloat16(+.nan) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat16(-.signalingNaN)_AlwaysTraps") { - let input = getFloat16(-.signalingNaN) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat16(-.signalingNaN)_AlwaysFails") { - let input = getFloat16(-.signalingNaN) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat16(+.signalingNaN)_AlwaysTraps") { - let input = getFloat16(+.signalingNaN) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat16(+.signalingNaN)_AlwaysFails") { - let input = getFloat16(+.signalingNaN) - let actual = UInt64(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt64 +.test("FromFloat16_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getFloat16(-0.5)), + (getUInt64(+0), getFloat16(+0)), + (getUInt64(+0), getFloat16(-0)), + (getUInt64(+0), getFloat16(+0.5)), + (getUInt64(+127), getFloat16(+127.5)), + (getUInt64(+255), getFloat16(+255.5)), + (getUInt64(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, UInt64($0.1)) +} + +FixedPointConversion_Debug64_ToUInt64 +.test("FromFloat16_NeverFails") +.forEach(in: [ + (getUInt64(+0), getFloat16(+0)), + (getUInt64(+0), getFloat16(-0)), + (getUInt64(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToUInt64 +.test("FromFloat16_AlwaysTraps") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-128.5), + getFloat16(-1), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt64($0)) +} + +FixedPointConversion_Debug64_ToUInt64 +.test("FromFloat16_AlwaysFails") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-128.5), + getFloat16(-1), + getFloat16(-0.5), + getFloat16(+0.5), + getFloat16(+127.5), + getFloat16(+255.5), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectNil(UInt64(exactly: $0)) } } #endif // Float16 //===----------------------------------------------------------------------===// -// MARK: Float32: (-16777215)...(16777215) +// MARK: Float32: (-16777215)...(+16777215) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt64.test("FromFloat32(-16777215)_AlwaysTraps") { - let input = getFloat32(-16777215) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat32(-16777215)_AlwaysFails") { - let input = getFloat32(-16777215) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat32(-32768.5)_AlwaysTraps") { - let input = getFloat32(-32768.5) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat32(-32768.5)_AlwaysFails") { - let input = getFloat32(-32768.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat32(-128.5)_AlwaysTraps") { - let input = getFloat32(-128.5) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat32(-128.5)_AlwaysFails") { - let input = getFloat32(-128.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat32(-1)_AlwaysTraps") { - let input = getFloat32(-1) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat32(-1)_AlwaysFails") { - let input = getFloat32(-1) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat32(-0.5)_NeverTraps") { - let input = getFloat32(-0.5) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat32(-0.5)_AlwaysFails") { - let input = getFloat32(-0.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat32(0)_NeverTraps") { - let input = getFloat32(0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat32(0)_NeverFails") { - let input = getFloat32(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat32(-0.0)_NeverTraps") { - let input = getFloat32(-0.0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat32(-0.0)_NeverFails") { - let input = getFloat32(-0.0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat32(0.0)_NeverTraps") { - let input = getFloat32(0.0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat32(0.0)_NeverFails") { - let input = getFloat32(0.0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat32(0.5)_NeverTraps") { - let input = getFloat32(0.5) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat32(0.5)_AlwaysFails") { - let input = getFloat32(0.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat32(127.5)_NeverTraps") { - let input = getFloat32(127.5) - let actual = UInt64(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat32(127.5)_AlwaysFails") { - let input = getFloat32(127.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat32(255.5)_NeverTraps") { - let input = getFloat32(255.5) - let actual = UInt64(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat32(255.5)_AlwaysFails") { - let input = getFloat32(255.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat32(32767.5)_NeverTraps") { - let input = getFloat32(32767.5) - let actual = UInt64(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat32(32767.5)_AlwaysFails") { - let input = getFloat32(32767.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat32(65535.5)_NeverTraps") { - let input = getFloat32(65535.5) - let actual = UInt64(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat32(65535.5)_AlwaysFails") { - let input = getFloat32(65535.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat32(16777215)_NeverTraps") { - let input = getFloat32(16777215) - let actual = UInt64(input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat32(16777215)_NeverFails") { - let input = getFloat32(16777215) - let actual = UInt64(exactly: input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat32(-.infinity)_AlwaysTraps") { - let input = getFloat32(-.infinity) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat32(-.infinity)_AlwaysFails") { - let input = getFloat32(-.infinity) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat32(+.infinity)_AlwaysTraps") { - let input = getFloat32(+.infinity) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat32(+.infinity)_AlwaysFails") { - let input = getFloat32(+.infinity) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat32(-.nan)_AlwaysTraps") { - let input = getFloat32(-.nan) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat32(-.nan)_AlwaysFails") { - let input = getFloat32(-.nan) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat32(+.nan)_AlwaysTraps") { - let input = getFloat32(+.nan) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat32(+.nan)_AlwaysFails") { - let input = getFloat32(+.nan) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat32(-.signalingNaN)_AlwaysTraps") { - let input = getFloat32(-.signalingNaN) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat32(-.signalingNaN)_AlwaysFails") { - let input = getFloat32(-.signalingNaN) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat32(+.signalingNaN)_AlwaysTraps") { - let input = getFloat32(+.signalingNaN) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat32(+.signalingNaN)_AlwaysFails") { - let input = getFloat32(+.signalingNaN) - let actual = UInt64(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt64 +.test("FromFloat32_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getFloat32(-0.5)), + (getUInt64(+0), getFloat32(+0)), + (getUInt64(+0), getFloat32(-0)), + (getUInt64(+0), getFloat32(+0.5)), + (getUInt64(+127), getFloat32(+127.5)), + (getUInt64(+255), getFloat32(+255.5)), + (getUInt64(+32767), getFloat32(+32767.5)), + (getUInt64(+65535), getFloat32(+65535.5)), + (getUInt64(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, UInt64($0.1)) +} + +FixedPointConversion_Debug64_ToUInt64 +.test("FromFloat32_NeverFails") +.forEach(in: [ + (getUInt64(+0), getFloat32(+0)), + (getUInt64(+0), getFloat32(-0)), + (getUInt64(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToUInt64 +.test("FromFloat32_AlwaysTraps") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-1), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt64($0)) +} + +FixedPointConversion_Debug64_ToUInt64 +.test("FromFloat32_AlwaysFails") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-1), + getFloat32(-0.5), + getFloat32(+0.5), + getFloat32(+127.5), + getFloat32(+255.5), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectNil(UInt64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float64: (-9007199254740991)...(9007199254740991) +// MARK: Float64: (-9007199254740991)...(+9007199254740991) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt64.test("FromFloat64(-9007199254740991)_AlwaysTraps") { - let input = getFloat64(-9007199254740991) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat64(-9007199254740991)_AlwaysFails") { - let input = getFloat64(-9007199254740991) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat64(-32768.5)_AlwaysTraps") { - let input = getFloat64(-32768.5) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat64(-32768.5)_AlwaysFails") { - let input = getFloat64(-32768.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat64(-128.5)_AlwaysTraps") { - let input = getFloat64(-128.5) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat64(-128.5)_AlwaysFails") { - let input = getFloat64(-128.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat64(-1)_AlwaysTraps") { - let input = getFloat64(-1) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat64(-1)_AlwaysFails") { - let input = getFloat64(-1) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat64(-0.5)_NeverTraps") { - let input = getFloat64(-0.5) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat64(-0.5)_AlwaysFails") { - let input = getFloat64(-0.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat64(0)_NeverTraps") { - let input = getFloat64(0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat64(0)_NeverFails") { - let input = getFloat64(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat64(-0.0)_NeverTraps") { - let input = getFloat64(-0.0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat64(-0.0)_NeverFails") { - let input = getFloat64(-0.0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat64(0.0)_NeverTraps") { - let input = getFloat64(0.0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat64(0.0)_NeverFails") { - let input = getFloat64(0.0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat64(0.5)_NeverTraps") { - let input = getFloat64(0.5) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat64(0.5)_AlwaysFails") { - let input = getFloat64(0.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat64(127.5)_NeverTraps") { - let input = getFloat64(127.5) - let actual = UInt64(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat64(127.5)_AlwaysFails") { - let input = getFloat64(127.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat64(255.5)_NeverTraps") { - let input = getFloat64(255.5) - let actual = UInt64(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat64(255.5)_AlwaysFails") { - let input = getFloat64(255.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat64(32767.5)_NeverTraps") { - let input = getFloat64(32767.5) - let actual = UInt64(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat64(32767.5)_AlwaysFails") { - let input = getFloat64(32767.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat64(65535.5)_NeverTraps") { - let input = getFloat64(65535.5) - let actual = UInt64(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat64(65535.5)_AlwaysFails") { - let input = getFloat64(65535.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat64(9007199254740991)_NeverTraps") { - let input = getFloat64(9007199254740991) - let actual = UInt64(input) - expectEqual(9007199254740991, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat64(9007199254740991)_NeverFails") { - let input = getFloat64(9007199254740991) - let actual = UInt64(exactly: input) - expectEqual(9007199254740991, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat64(-.infinity)_AlwaysTraps") { - let input = getFloat64(-.infinity) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat64(-.infinity)_AlwaysFails") { - let input = getFloat64(-.infinity) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat64(+.infinity)_AlwaysTraps") { - let input = getFloat64(+.infinity) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat64(+.infinity)_AlwaysFails") { - let input = getFloat64(+.infinity) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat64(-.nan)_AlwaysTraps") { - let input = getFloat64(-.nan) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat64(-.nan)_AlwaysFails") { - let input = getFloat64(-.nan) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat64(+.nan)_AlwaysTraps") { - let input = getFloat64(+.nan) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat64(+.nan)_AlwaysFails") { - let input = getFloat64(+.nan) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat64(-.signalingNaN)_AlwaysTraps") { - let input = getFloat64(-.signalingNaN) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat64(-.signalingNaN)_AlwaysFails") { - let input = getFloat64(-.signalingNaN) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat64(+.signalingNaN)_AlwaysTraps") { - let input = getFloat64(+.signalingNaN) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat64(+.signalingNaN)_AlwaysFails") { - let input = getFloat64(+.signalingNaN) - let actual = UInt64(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt64 +.test("FromFloat64_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getFloat64(-0.5)), + (getUInt64(+0), getFloat64(+0)), + (getUInt64(+0), getFloat64(-0)), + (getUInt64(+0), getFloat64(+0.5)), + (getUInt64(+127), getFloat64(+127.5)), + (getUInt64(+255), getFloat64(+255.5)), + (getUInt64(+32767), getFloat64(+32767.5)), + (getUInt64(+65535), getFloat64(+65535.5)), + (getUInt64(+9007199254740991), getFloat64(+9007199254740991)), +]) { + expectEqual($0.0, UInt64($0.1)) +} + +FixedPointConversion_Debug64_ToUInt64 +.test("FromFloat64_NeverFails") +.forEach(in: [ + (getUInt64(+0), getFloat64(+0)), + (getUInt64(+0), getFloat64(-0)), + (getUInt64(+9007199254740991), getFloat64(+9007199254740991)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToUInt64 +.test("FromFloat64_AlwaysTraps") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-1), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt64($0)) +} + +FixedPointConversion_Debug64_ToUInt64 +.test("FromFloat64_AlwaysFails") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-1), + getFloat64(-0.5), + getFloat64(+0.5), + getFloat64(+127.5), + getFloat64(+255.5), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectNil(UInt64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float80: (-18446744073709551615)...(18446744073709551615) +// MARK: Float80: (-18446744073709551615)...(+18446744073709551615) //===----------------------------------------------------------------------===// #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(-18446744073709551615)_AlwaysTraps") { - let input = getFloat80(-18446744073709551615) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(-18446744073709551615)_AlwaysFails") { - let input = getFloat80(-18446744073709551615) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(-32768.5)_AlwaysTraps") { - let input = getFloat80(-32768.5) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(-32768.5)_AlwaysFails") { - let input = getFloat80(-32768.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(-128.5)_AlwaysTraps") { - let input = getFloat80(-128.5) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(-128.5)_AlwaysFails") { - let input = getFloat80(-128.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(-1)_AlwaysTraps") { - let input = getFloat80(-1) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(-1)_AlwaysFails") { - let input = getFloat80(-1) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(-0.5)_NeverTraps") { - let input = getFloat80(-0.5) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(-0.5)_AlwaysFails") { - let input = getFloat80(-0.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(0)_NeverTraps") { - let input = getFloat80(0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(0)_NeverFails") { - let input = getFloat80(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(-0.0)_NeverTraps") { - let input = getFloat80(-0.0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(-0.0)_NeverFails") { - let input = getFloat80(-0.0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(0.0)_NeverTraps") { - let input = getFloat80(0.0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(0.0)_NeverFails") { - let input = getFloat80(0.0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(0.5)_NeverTraps") { - let input = getFloat80(0.5) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(0.5)_AlwaysFails") { - let input = getFloat80(0.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(127.5)_NeverTraps") { - let input = getFloat80(127.5) - let actual = UInt64(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(127.5)_AlwaysFails") { - let input = getFloat80(127.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(255.5)_NeverTraps") { - let input = getFloat80(255.5) - let actual = UInt64(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(255.5)_AlwaysFails") { - let input = getFloat80(255.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(32767.5)_NeverTraps") { - let input = getFloat80(32767.5) - let actual = UInt64(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(32767.5)_AlwaysFails") { - let input = getFloat80(32767.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(65535.5)_NeverTraps") { - let input = getFloat80(65535.5) - let actual = UInt64(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(65535.5)_AlwaysFails") { - let input = getFloat80(65535.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(18446744073709551615)_NeverTraps") { - let input = getFloat80(18446744073709551615) - let actual = UInt64(input) - expectEqual(18446744073709551615, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(18446744073709551615)_NeverFails") { - let input = getFloat80(18446744073709551615) - let actual = UInt64(exactly: input) - expectEqual(18446744073709551615, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(18446744073709551615)_NeverTraps") { - let input = getFloat80(18446744073709551615) - let actual = UInt64(input) - expectEqual(18446744073709551615, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(18446744073709551615)_NeverFails") { - let input = getFloat80(18446744073709551615) - let actual = UInt64(exactly: input) - expectEqual(18446744073709551615, actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(-.infinity)_AlwaysTraps") { - let input = getFloat80(-.infinity) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(-.infinity)_AlwaysFails") { - let input = getFloat80(-.infinity) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(+.infinity)_AlwaysTraps") { - let input = getFloat80(+.infinity) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(+.infinity)_AlwaysFails") { - let input = getFloat80(+.infinity) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(-.nan)_AlwaysTraps") { - let input = getFloat80(-.nan) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(-.nan)_AlwaysFails") { - let input = getFloat80(-.nan) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(+.nan)_AlwaysTraps") { - let input = getFloat80(+.nan) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(+.nan)_AlwaysFails") { - let input = getFloat80(+.nan) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(-.signalingNaN)_AlwaysTraps") { - let input = getFloat80(-.signalingNaN) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(-.signalingNaN)_AlwaysFails") { - let input = getFloat80(-.signalingNaN) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(+.signalingNaN)_AlwaysTraps") { - let input = getFloat80(+.signalingNaN) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt64.test("FromFloat80(+.signalingNaN)_AlwaysFails") { - let input = getFloat80(+.signalingNaN) - let actual = UInt64(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt64 +.test("FromFloat80_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getFloat80(-0.5)), + (getUInt64(+0), getFloat80(+0)), + (getUInt64(+0), getFloat80(-0)), + (getUInt64(+0), getFloat80(+0.5)), + (getUInt64(+127), getFloat80(+127.5)), + (getUInt64(+255), getFloat80(+255.5)), + (getUInt64(+32767), getFloat80(+32767.5)), + (getUInt64(+65535), getFloat80(+65535.5)), + (getUInt64(+18446744073709551615), getFloat80(+18446744073709551615)), +]) { + expectEqual($0.0, UInt64($0.1)) +} + +FixedPointConversion_Debug64_ToUInt64 +.test("FromFloat80_NeverFails") +.forEach(in: [ + (getUInt64(+0), getFloat80(+0)), + (getUInt64(+0), getFloat80(-0)), + (getUInt64(+18446744073709551615), getFloat80(+18446744073709551615)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToUInt64 +.test("FromFloat80_AlwaysTraps") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-1), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt64($0)) +} + +FixedPointConversion_Debug64_ToUInt64 +.test("FromFloat80_AlwaysFails") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-1), + getFloat80(-0.5), + getFloat80(+0.5), + getFloat80(+127.5), + getFloat80(+255.5), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectNil(UInt64(exactly: $0)) } #endif // Float80 diff --git a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug64_ToUInt8.swift b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug64_ToUInt8.swift index 5c80c060adeb7..e72cc966f0658 100644 --- a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug64_ToUInt8.swift +++ b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Debug64_ToUInt8.swift @@ -14,1800 +14,717 @@ import StdlibUnittest -let FixedPointConversion_Debug64_ToUInt8 = TestSuite("FixedPointConversion_Debug64_ToUInt8") +let FixedPointConversion_Debug64_ToUInt8 = TestSuite( + "FixedPointConversion_Debug64_ToUInt8" +) //===----------------------------------------------------------------------===// -// MARK: UInt8: (0)...(255) +// MARK: UInt8: (+0)...(+255) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt8.test("FromUInt8(0)_NeverTraps") { - let input = getUInt8(0) - let actual = UInt8(input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt8 +.test("FromUInt8_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getUInt8(+0)), + (getUInt8(+255), getUInt8(+255)), +]) { + expectEqual($0.0, UInt8($0.1)) } -FixedPointConversion_Debug64_ToUInt8.test("FromUInt8(0)_NeverFails") { - let input = getUInt8(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromUInt8(255)_NeverTraps") { - let input = getUInt8(255) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromUInt8(255)_NeverFails") { - let input = getUInt8(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) +FixedPointConversion_Debug64_ToUInt8 +.test("FromUInt8_NeverFails") +.forEach(in: [ + (getUInt8(+0), getUInt8(+0)), + (getUInt8(+255), getUInt8(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int8: (-128)...(127) +// MARK: Int8: (-128)...(+127) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt8.test("FromInt8(-128)_AlwaysTraps") { - let input = getInt8(-128) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt8(-128)_AlwaysFails") { - let input = getInt8(-128) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt8(-1)_AlwaysTraps") { - let input = getInt8(-1) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } +FixedPointConversion_Debug64_ToUInt8 +.test("FromInt8_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getInt8(+0)), + (getUInt8(+127), getInt8(+127)), +]) { + expectEqual($0.0, UInt8($0.1)) } -FixedPointConversion_Debug64_ToUInt8.test("FromInt8(-1)_AlwaysFails") { - let input = getInt8(-1) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt8 +.test("FromInt8_NeverFails") +.forEach(in: [ + (getUInt8(+0), getInt8(+0)), + (getUInt8(+127), getInt8(+127)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) } -FixedPointConversion_Debug64_ToUInt8.test("FromInt8(0)_NeverTraps") { - let input = getInt8(0) - let actual = UInt8(input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt8 +.test("FromInt8_AlwaysTraps") +.forEach(in: [ + getInt8(-128), + getInt8(-1), +]) { + expectCrashLater() + _blackHole(UInt8($0)) } -FixedPointConversion_Debug64_ToUInt8.test("FromInt8(0)_NeverFails") { - let input = getInt8(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt8(127)_NeverTraps") { - let input = getInt8(127) - let actual = UInt8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt8(127)_NeverFails") { - let input = getInt8(127) - let actual = UInt8(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Debug64_ToUInt8 +.test("FromInt8_AlwaysFails") +.forEach(in: [ + getInt8(-128), + getInt8(-1), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt16: (0)...(65535) +// MARK: UInt16: (+0)...(+65535) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt8.test("FromUInt16(0)_NeverTraps") { - let input = getUInt16(0) - let actual = UInt8(input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt8 +.test("FromUInt16_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getUInt16(+0)), + (getUInt8(+255), getUInt16(+255)), +]) { + expectEqual($0.0, UInt8($0.1)) } -FixedPointConversion_Debug64_ToUInt8.test("FromUInt16(0)_NeverFails") { - let input = getUInt16(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt8 +.test("FromUInt16_NeverFails") +.forEach(in: [ + (getUInt8(+0), getUInt16(+0)), + (getUInt8(+255), getUInt16(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) } -FixedPointConversion_Debug64_ToUInt8.test("FromUInt16(255)_NeverTraps") { - let input = getUInt16(255) - let actual = UInt8(input) - expectEqual(255, actual) +FixedPointConversion_Debug64_ToUInt8 +.test("FromUInt16_AlwaysTraps") +.forEach(in: [ + getUInt16(+256), + getUInt16(+65535), +]) { + expectCrashLater() + _blackHole(UInt8($0)) } -FixedPointConversion_Debug64_ToUInt8.test("FromUInt16(255)_NeverFails") { - let input = getUInt16(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromUInt16(256)_AlwaysTraps") { - let input = getUInt16(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromUInt16(256)_AlwaysFails") { - let input = getUInt16(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromUInt16(65535)_AlwaysTraps") { - let input = getUInt16(65535) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromUInt16(65535)_AlwaysFails") { - let input = getUInt16(65535) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt8 +.test("FromUInt16_AlwaysFails") +.forEach(in: [ + getUInt16(+256), + getUInt16(+65535), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int16: (-32768)...(32767) +// MARK: Int16: (-32768)...(+32767) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt8.test("FromInt16(-32768)_AlwaysTraps") { - let input = getInt16(-32768) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt16(-32768)_AlwaysFails") { - let input = getInt16(-32768) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt16(-1)_AlwaysTraps") { - let input = getInt16(-1) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt16(-1)_AlwaysFails") { - let input = getInt16(-1) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt16(0)_NeverTraps") { - let input = getInt16(0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt16(0)_NeverFails") { - let input = getInt16(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt16(255)_NeverTraps") { - let input = getInt16(255) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt16(255)_NeverFails") { - let input = getInt16(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt16(256)_AlwaysTraps") { - let input = getInt16(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt16(256)_AlwaysFails") { - let input = getInt16(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt16(32767)_AlwaysTraps") { - let input = getInt16(32767) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt16(32767)_AlwaysFails") { - let input = getInt16(32767) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt8 +.test("FromInt16_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getInt16(+0)), + (getUInt8(+255), getInt16(+255)), +]) { + expectEqual($0.0, UInt8($0.1)) +} + +FixedPointConversion_Debug64_ToUInt8 +.test("FromInt16_NeverFails") +.forEach(in: [ + (getUInt8(+0), getInt16(+0)), + (getUInt8(+255), getInt16(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToUInt8 +.test("FromInt16_AlwaysTraps") +.forEach(in: [ + getInt16(-32768), + getInt16(-1), + getInt16(+256), + getInt16(+32767), +]) { + expectCrashLater() + _blackHole(UInt8($0)) +} + +FixedPointConversion_Debug64_ToUInt8 +.test("FromInt16_AlwaysFails") +.forEach(in: [ + getInt16(-32768), + getInt16(-1), + getInt16(+256), + getInt16(+32767), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt32: (0)...(4294967295) +// MARK: UInt32: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt8.test("FromUInt32(0)_NeverTraps") { - let input = getUInt32(0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromUInt32(0)_NeverFails") { - let input = getUInt32(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt8 +.test("FromUInt32_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getUInt32(+0)), + (getUInt8(+255), getUInt32(+255)), +]) { + expectEqual($0.0, UInt8($0.1)) } -FixedPointConversion_Debug64_ToUInt8.test("FromUInt32(255)_NeverTraps") { - let input = getUInt32(255) - let actual = UInt8(input) - expectEqual(255, actual) +FixedPointConversion_Debug64_ToUInt8 +.test("FromUInt32_NeverFails") +.forEach(in: [ + (getUInt8(+0), getUInt32(+0)), + (getUInt8(+255), getUInt32(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) } -FixedPointConversion_Debug64_ToUInt8.test("FromUInt32(255)_NeverFails") { - let input = getUInt32(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) +FixedPointConversion_Debug64_ToUInt8 +.test("FromUInt32_AlwaysTraps") +.forEach(in: [ + getUInt32(+256), + getUInt32(+4294967295), +]) { + expectCrashLater() + _blackHole(UInt8($0)) } -FixedPointConversion_Debug64_ToUInt8.test("FromUInt32(256)_AlwaysTraps") { - let input = getUInt32(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromUInt32(256)_AlwaysFails") { - let input = getUInt32(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromUInt32(4294967295)_AlwaysTraps") { - let input = getUInt32(4294967295) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromUInt32(4294967295)_AlwaysFails") { - let input = getUInt32(4294967295) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt8 +.test("FromUInt32_AlwaysFails") +.forEach(in: [ + getUInt32(+256), + getUInt32(+4294967295), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int32: (-2147483648)...(2147483647) +// MARK: Int32: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt8.test("FromInt32(-2147483648)_AlwaysTraps") { - let input = getInt32(-2147483648) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt32(-2147483648)_AlwaysFails") { - let input = getInt32(-2147483648) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt32(-1)_AlwaysTraps") { - let input = getInt32(-1) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt32(-1)_AlwaysFails") { - let input = getInt32(-1) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt32(0)_NeverTraps") { - let input = getInt32(0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt32(0)_NeverFails") { - let input = getInt32(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt32(255)_NeverTraps") { - let input = getInt32(255) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt32(255)_NeverFails") { - let input = getInt32(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt32(256)_AlwaysTraps") { - let input = getInt32(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt32(256)_AlwaysFails") { - let input = getInt32(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt32(2147483647)_AlwaysTraps") { - let input = getInt32(2147483647) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt32(2147483647)_AlwaysFails") { - let input = getInt32(2147483647) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt8 +.test("FromInt32_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getInt32(+0)), + (getUInt8(+255), getInt32(+255)), +]) { + expectEqual($0.0, UInt8($0.1)) +} + +FixedPointConversion_Debug64_ToUInt8 +.test("FromInt32_NeverFails") +.forEach(in: [ + (getUInt8(+0), getInt32(+0)), + (getUInt8(+255), getInt32(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToUInt8 +.test("FromInt32_AlwaysTraps") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-1), + getInt32(+256), + getInt32(+2147483647), +]) { + expectCrashLater() + _blackHole(UInt8($0)) +} + +FixedPointConversion_Debug64_ToUInt8 +.test("FromInt32_AlwaysFails") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-1), + getInt32(+256), + getInt32(+2147483647), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt64: (0)...(18446744073709551615) +// MARK: UInt64: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt8.test("FromUInt64(0)_NeverTraps") { - let input = getUInt64(0) - let actual = UInt8(input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt8 +.test("FromUInt64_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getUInt64(+0)), + (getUInt8(+255), getUInt64(+255)), +]) { + expectEqual($0.0, UInt8($0.1)) } -FixedPointConversion_Debug64_ToUInt8.test("FromUInt64(0)_NeverFails") { - let input = getUInt64(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt8 +.test("FromUInt64_NeverFails") +.forEach(in: [ + (getUInt8(+0), getUInt64(+0)), + (getUInt8(+255), getUInt64(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) } -FixedPointConversion_Debug64_ToUInt8.test("FromUInt64(255)_NeverTraps") { - let input = getUInt64(255) - let actual = UInt8(input) - expectEqual(255, actual) +FixedPointConversion_Debug64_ToUInt8 +.test("FromUInt64_AlwaysTraps") +.forEach(in: [ + getUInt64(+256), + getUInt64(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(UInt8($0)) } -FixedPointConversion_Debug64_ToUInt8.test("FromUInt64(255)_NeverFails") { - let input = getUInt64(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromUInt64(256)_AlwaysTraps") { - let input = getUInt64(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromUInt64(256)_AlwaysFails") { - let input = getUInt64(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromUInt64(18446744073709551615)_AlwaysTraps") { - let input = getUInt64(18446744073709551615) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromUInt64(18446744073709551615)_AlwaysFails") { - let input = getUInt64(18446744073709551615) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt8 +.test("FromUInt64_AlwaysFails") +.forEach(in: [ + getUInt64(+256), + getUInt64(+18446744073709551615), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int64: (-9223372036854775808)...(9223372036854775807) +// MARK: Int64: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt8.test("FromInt64(-9223372036854775808)_AlwaysTraps") { - let input = getInt64(-9223372036854775808) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt64(-9223372036854775808)_AlwaysFails") { - let input = getInt64(-9223372036854775808) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt64(-1)_AlwaysTraps") { - let input = getInt64(-1) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt64(-1)_AlwaysFails") { - let input = getInt64(-1) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt64(0)_NeverTraps") { - let input = getInt64(0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt64(0)_NeverFails") { - let input = getInt64(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt64(255)_NeverTraps") { - let input = getInt64(255) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt64(255)_NeverFails") { - let input = getInt64(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt64(256)_AlwaysTraps") { - let input = getInt64(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt64(256)_AlwaysFails") { - let input = getInt64(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt64(9223372036854775807)_AlwaysTraps") { - let input = getInt64(9223372036854775807) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt64(9223372036854775807)_AlwaysFails") { - let input = getInt64(9223372036854775807) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt8 +.test("FromInt64_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getInt64(+0)), + (getUInt8(+255), getInt64(+255)), +]) { + expectEqual($0.0, UInt8($0.1)) +} + +FixedPointConversion_Debug64_ToUInt8 +.test("FromInt64_NeverFails") +.forEach(in: [ + (getUInt8(+0), getInt64(+0)), + (getUInt8(+255), getInt64(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToUInt8 +.test("FromInt64_AlwaysTraps") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-1), + getInt64(+256), + getInt64(+9223372036854775807), +]) { + expectCrashLater() + _blackHole(UInt8($0)) +} + +FixedPointConversion_Debug64_ToUInt8 +.test("FromInt64_AlwaysFails") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-1), + getInt64(+256), + getInt64(+9223372036854775807), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt: (0)...(18446744073709551615) +// MARK: UInt: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt8.test("FromUInt(0)_NeverTraps") { - let input = getUInt(0) - let actual = UInt8(input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt8 +.test("FromUInt_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getUInt(+0)), + (getUInt8(+255), getUInt(+255)), +]) { + expectEqual($0.0, UInt8($0.1)) } -FixedPointConversion_Debug64_ToUInt8.test("FromUInt(0)_NeverFails") { - let input = getUInt(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Debug64_ToUInt8 +.test("FromUInt_NeverFails") +.forEach(in: [ + (getUInt8(+0), getUInt(+0)), + (getUInt8(+255), getUInt(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) } -FixedPointConversion_Debug64_ToUInt8.test("FromUInt(255)_NeverTraps") { - let input = getUInt(255) - let actual = UInt8(input) - expectEqual(255, actual) +FixedPointConversion_Debug64_ToUInt8 +.test("FromUInt_AlwaysTraps") +.forEach(in: [ + getUInt(+256), + getUInt(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(UInt8($0)) } -FixedPointConversion_Debug64_ToUInt8.test("FromUInt(255)_NeverFails") { - let input = getUInt(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromUInt(256)_AlwaysTraps") { - let input = getUInt(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromUInt(256)_AlwaysFails") { - let input = getUInt(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromUInt(18446744073709551615)_AlwaysTraps") { - let input = getUInt(18446744073709551615) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromUInt(18446744073709551615)_AlwaysFails") { - let input = getUInt(18446744073709551615) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt8 +.test("FromUInt_AlwaysFails") +.forEach(in: [ + getUInt(+256), + getUInt(+18446744073709551615), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int: (-9223372036854775808)...(9223372036854775807) +// MARK: Int: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt8.test("FromInt(-9223372036854775808)_AlwaysTraps") { - let input = getInt(-9223372036854775808) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt(-9223372036854775808)_AlwaysFails") { - let input = getInt(-9223372036854775808) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt(-1)_AlwaysTraps") { - let input = getInt(-1) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt(-1)_AlwaysFails") { - let input = getInt(-1) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt(0)_NeverTraps") { - let input = getInt(0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt(0)_NeverFails") { - let input = getInt(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt(255)_NeverTraps") { - let input = getInt(255) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt(255)_NeverFails") { - let input = getInt(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt(256)_AlwaysTraps") { - let input = getInt(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt(256)_AlwaysFails") { - let input = getInt(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt(9223372036854775807)_AlwaysTraps") { - let input = getInt(9223372036854775807) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromInt(9223372036854775807)_AlwaysFails") { - let input = getInt(9223372036854775807) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt8 +.test("FromInt_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getInt(+0)), + (getUInt8(+255), getInt(+255)), +]) { + expectEqual($0.0, UInt8($0.1)) +} + +FixedPointConversion_Debug64_ToUInt8 +.test("FromInt_NeverFails") +.forEach(in: [ + (getUInt8(+0), getInt(+0)), + (getUInt8(+255), getInt(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToUInt8 +.test("FromInt_AlwaysTraps") +.forEach(in: [ + getInt(-9223372036854775808), + getInt(-1), + getInt(+256), + getInt(+9223372036854775807), +]) { + expectCrashLater() + _blackHole(UInt8($0)) +} + +FixedPointConversion_Debug64_ToUInt8 +.test("FromInt_AlwaysFails") +.forEach(in: [ + getInt(-9223372036854775808), + getInt(-1), + getInt(+256), + getInt(+9223372036854775807), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float16: (-2047)...(2047) +// MARK: Float16: (-2047)...(+2047) //===----------------------------------------------------------------------===// #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -FixedPointConversion_Debug64_ToUInt8.test("FromFloat16(-2047)_AlwaysTraps") { - let input = getFloat16(-2047) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat16(-2047)_AlwaysFails") { - let input = getFloat16(-2047) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat16(-128.5)_AlwaysTraps") { - let input = getFloat16(-128.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat16(-128.5)_AlwaysFails") { - let input = getFloat16(-128.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat16(-1)_AlwaysTraps") { - let input = getFloat16(-1) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat16(-1)_AlwaysFails") { - let input = getFloat16(-1) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat16(-0.5)_NeverTraps") { - let input = getFloat16(-0.5) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat16(-0.5)_AlwaysFails") { - let input = getFloat16(-0.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat16(0)_NeverTraps") { - let input = getFloat16(0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat16(0)_NeverFails") { - let input = getFloat16(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat16(-0.0)_NeverTraps") { - let input = getFloat16(-0.0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat16(-0.0)_NeverFails") { - let input = getFloat16(-0.0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat16(0.0)_NeverTraps") { - let input = getFloat16(0.0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat16(0.0)_NeverFails") { - let input = getFloat16(0.0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat16(0.5)_NeverTraps") { - let input = getFloat16(0.5) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat16(0.5)_AlwaysFails") { - let input = getFloat16(0.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat16(127.5)_NeverTraps") { - let input = getFloat16(127.5) - let actual = UInt8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat16(127.5)_AlwaysFails") { - let input = getFloat16(127.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat16(255)_NeverTraps") { - let input = getFloat16(255) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat16(255)_NeverFails") { - let input = getFloat16(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat16(255.5)_NeverTraps") { - let input = getFloat16(255.5) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat16(255.5)_AlwaysFails") { - let input = getFloat16(255.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat16(256)_AlwaysTraps") { - let input = getFloat16(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat16(256)_AlwaysFails") { - let input = getFloat16(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat16(2047)_AlwaysTraps") { - let input = getFloat16(2047) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat16(2047)_AlwaysFails") { - let input = getFloat16(2047) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat16(-.infinity)_AlwaysTraps") { - let input = getFloat16(-.infinity) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat16(-.infinity)_AlwaysFails") { - let input = getFloat16(-.infinity) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat16(+.infinity)_AlwaysTraps") { - let input = getFloat16(+.infinity) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat16(+.infinity)_AlwaysFails") { - let input = getFloat16(+.infinity) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat16(-.nan)_AlwaysTraps") { - let input = getFloat16(-.nan) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat16(-.nan)_AlwaysFails") { - let input = getFloat16(-.nan) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat16(+.nan)_AlwaysTraps") { - let input = getFloat16(+.nan) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat16(+.nan)_AlwaysFails") { - let input = getFloat16(+.nan) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat16(-.signalingNaN)_AlwaysTraps") { - let input = getFloat16(-.signalingNaN) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat16(-.signalingNaN)_AlwaysFails") { - let input = getFloat16(-.signalingNaN) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat16(+.signalingNaN)_AlwaysTraps") { - let input = getFloat16(+.signalingNaN) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat16(+.signalingNaN)_AlwaysFails") { - let input = getFloat16(+.signalingNaN) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt8 +.test("FromFloat16_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getFloat16(-0.5)), + (getUInt8(+0), getFloat16(-0)), + (getUInt8(+0), getFloat16(+0)), + (getUInt8(+0), getFloat16(+0.5)), + (getUInt8(+127), getFloat16(+127.5)), + (getUInt8(+255), getFloat16(+255)), + (getUInt8(+255), getFloat16(+255.5)), +]) { + expectEqual($0.0, UInt8($0.1)) +} + +FixedPointConversion_Debug64_ToUInt8 +.test("FromFloat16_NeverFails") +.forEach(in: [ + (getUInt8(+0), getFloat16(-0)), + (getUInt8(+0), getFloat16(+0)), + (getUInt8(+255), getFloat16(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToUInt8 +.test("FromFloat16_AlwaysTraps") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-128.5), + getFloat16(-1), + getFloat16(+256), + getFloat16(+2047), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt8($0)) +} + +FixedPointConversion_Debug64_ToUInt8 +.test("FromFloat16_AlwaysFails") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-128.5), + getFloat16(-1), + getFloat16(-0.5), + getFloat16(+0.5), + getFloat16(+127.5), + getFloat16(+255.5), + getFloat16(+256), + getFloat16(+2047), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectNil(UInt8(exactly: $0)) } } #endif // Float16 //===----------------------------------------------------------------------===// -// MARK: Float32: (-16777215)...(16777215) +// MARK: Float32: (-16777215)...(+16777215) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(-16777215)_AlwaysTraps") { - let input = getFloat32(-16777215) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(-16777215)_AlwaysFails") { - let input = getFloat32(-16777215) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(-32768.5)_AlwaysTraps") { - let input = getFloat32(-32768.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(-32768.5)_AlwaysFails") { - let input = getFloat32(-32768.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(-128.5)_AlwaysTraps") { - let input = getFloat32(-128.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(-128.5)_AlwaysFails") { - let input = getFloat32(-128.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(-1)_AlwaysTraps") { - let input = getFloat32(-1) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(-1)_AlwaysFails") { - let input = getFloat32(-1) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(-0.5)_NeverTraps") { - let input = getFloat32(-0.5) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(-0.5)_AlwaysFails") { - let input = getFloat32(-0.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(0)_NeverTraps") { - let input = getFloat32(0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(0)_NeverFails") { - let input = getFloat32(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(-0.0)_NeverTraps") { - let input = getFloat32(-0.0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(-0.0)_NeverFails") { - let input = getFloat32(-0.0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(0.0)_NeverTraps") { - let input = getFloat32(0.0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(0.0)_NeverFails") { - let input = getFloat32(0.0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(0.5)_NeverTraps") { - let input = getFloat32(0.5) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(0.5)_AlwaysFails") { - let input = getFloat32(0.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(127.5)_NeverTraps") { - let input = getFloat32(127.5) - let actual = UInt8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(127.5)_AlwaysFails") { - let input = getFloat32(127.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(255)_NeverTraps") { - let input = getFloat32(255) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(255)_NeverFails") { - let input = getFloat32(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(255.5)_NeverTraps") { - let input = getFloat32(255.5) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(255.5)_AlwaysFails") { - let input = getFloat32(255.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(256)_AlwaysTraps") { - let input = getFloat32(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(256)_AlwaysFails") { - let input = getFloat32(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(32767.5)_AlwaysTraps") { - let input = getFloat32(32767.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(32767.5)_AlwaysFails") { - let input = getFloat32(32767.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(65535.5)_AlwaysTraps") { - let input = getFloat32(65535.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(65535.5)_AlwaysFails") { - let input = getFloat32(65535.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(16777215)_AlwaysTraps") { - let input = getFloat32(16777215) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(16777215)_AlwaysFails") { - let input = getFloat32(16777215) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(-.infinity)_AlwaysTraps") { - let input = getFloat32(-.infinity) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(-.infinity)_AlwaysFails") { - let input = getFloat32(-.infinity) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(+.infinity)_AlwaysTraps") { - let input = getFloat32(+.infinity) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(+.infinity)_AlwaysFails") { - let input = getFloat32(+.infinity) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(-.nan)_AlwaysTraps") { - let input = getFloat32(-.nan) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(-.nan)_AlwaysFails") { - let input = getFloat32(-.nan) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(+.nan)_AlwaysTraps") { - let input = getFloat32(+.nan) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(+.nan)_AlwaysFails") { - let input = getFloat32(+.nan) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(-.signalingNaN)_AlwaysTraps") { - let input = getFloat32(-.signalingNaN) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(-.signalingNaN)_AlwaysFails") { - let input = getFloat32(-.signalingNaN) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(+.signalingNaN)_AlwaysTraps") { - let input = getFloat32(+.signalingNaN) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat32(+.signalingNaN)_AlwaysFails") { - let input = getFloat32(+.signalingNaN) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt8 +.test("FromFloat32_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getFloat32(-0.5)), + (getUInt8(+0), getFloat32(+0)), + (getUInt8(+0), getFloat32(-0)), + (getUInt8(+0), getFloat32(+0.5)), + (getUInt8(+127), getFloat32(+127.5)), + (getUInt8(+255), getFloat32(+255)), + (getUInt8(+255), getFloat32(+255.5)), +]) { + expectEqual($0.0, UInt8($0.1)) +} + +FixedPointConversion_Debug64_ToUInt8 +.test("FromFloat32_NeverFails") +.forEach(in: [ + (getUInt8(+0), getFloat32(+0)), + (getUInt8(+0), getFloat32(-0)), + (getUInt8(+255), getFloat32(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToUInt8 +.test("FromFloat32_AlwaysTraps") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-1), + getFloat32(+256), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(+16777215), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt8($0)) +} + +FixedPointConversion_Debug64_ToUInt8 +.test("FromFloat32_AlwaysFails") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-1), + getFloat32(-0.5), + getFloat32(+0.5), + getFloat32(+127.5), + getFloat32(+255.5), + getFloat32(+256), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(+16777215), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float64: (-9007199254740991)...(9007199254740991) +// MARK: Float64: (-9007199254740991)...(+9007199254740991) //===----------------------------------------------------------------------===// -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(-9007199254740991)_AlwaysTraps") { - let input = getFloat64(-9007199254740991) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(-9007199254740991)_AlwaysFails") { - let input = getFloat64(-9007199254740991) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(-32768.5)_AlwaysTraps") { - let input = getFloat64(-32768.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(-32768.5)_AlwaysFails") { - let input = getFloat64(-32768.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(-128.5)_AlwaysTraps") { - let input = getFloat64(-128.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(-128.5)_AlwaysFails") { - let input = getFloat64(-128.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(-1)_AlwaysTraps") { - let input = getFloat64(-1) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(-1)_AlwaysFails") { - let input = getFloat64(-1) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(-0.5)_NeverTraps") { - let input = getFloat64(-0.5) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(-0.5)_AlwaysFails") { - let input = getFloat64(-0.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(0)_NeverTraps") { - let input = getFloat64(0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(0)_NeverFails") { - let input = getFloat64(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(-0.0)_NeverTraps") { - let input = getFloat64(-0.0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(-0.0)_NeverFails") { - let input = getFloat64(-0.0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(0.0)_NeverTraps") { - let input = getFloat64(0.0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(0.0)_NeverFails") { - let input = getFloat64(0.0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(0.5)_NeverTraps") { - let input = getFloat64(0.5) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(0.5)_AlwaysFails") { - let input = getFloat64(0.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(127.5)_NeverTraps") { - let input = getFloat64(127.5) - let actual = UInt8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(127.5)_AlwaysFails") { - let input = getFloat64(127.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(255)_NeverTraps") { - let input = getFloat64(255) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(255)_NeverFails") { - let input = getFloat64(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(255.5)_NeverTraps") { - let input = getFloat64(255.5) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(255.5)_AlwaysFails") { - let input = getFloat64(255.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(256)_AlwaysTraps") { - let input = getFloat64(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(256)_AlwaysFails") { - let input = getFloat64(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(32767.5)_AlwaysTraps") { - let input = getFloat64(32767.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(32767.5)_AlwaysFails") { - let input = getFloat64(32767.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(65535.5)_AlwaysTraps") { - let input = getFloat64(65535.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(65535.5)_AlwaysFails") { - let input = getFloat64(65535.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(9007199254740991)_AlwaysTraps") { - let input = getFloat64(9007199254740991) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(9007199254740991)_AlwaysFails") { - let input = getFloat64(9007199254740991) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(-.infinity)_AlwaysTraps") { - let input = getFloat64(-.infinity) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(-.infinity)_AlwaysFails") { - let input = getFloat64(-.infinity) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(+.infinity)_AlwaysTraps") { - let input = getFloat64(+.infinity) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(+.infinity)_AlwaysFails") { - let input = getFloat64(+.infinity) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(-.nan)_AlwaysTraps") { - let input = getFloat64(-.nan) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(-.nan)_AlwaysFails") { - let input = getFloat64(-.nan) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(+.nan)_AlwaysTraps") { - let input = getFloat64(+.nan) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(+.nan)_AlwaysFails") { - let input = getFloat64(+.nan) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(-.signalingNaN)_AlwaysTraps") { - let input = getFloat64(-.signalingNaN) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(-.signalingNaN)_AlwaysFails") { - let input = getFloat64(-.signalingNaN) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(+.signalingNaN)_AlwaysTraps") { - let input = getFloat64(+.signalingNaN) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat64(+.signalingNaN)_AlwaysFails") { - let input = getFloat64(+.signalingNaN) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt8 +.test("FromFloat64_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getFloat64(-0.5)), + (getUInt8(+0), getFloat64(+0)), + (getUInt8(+0), getFloat64(-0)), + (getUInt8(+0), getFloat64(+0.5)), + (getUInt8(+127), getFloat64(+127.5)), + (getUInt8(+255), getFloat64(+255)), + (getUInt8(+255), getFloat64(+255.5)), +]) { + expectEqual($0.0, UInt8($0.1)) +} + +FixedPointConversion_Debug64_ToUInt8 +.test("FromFloat64_NeverFails") +.forEach(in: [ + (getUInt8(+0), getFloat64(+0)), + (getUInt8(+0), getFloat64(-0)), + (getUInt8(+255), getFloat64(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToUInt8 +.test("FromFloat64_AlwaysTraps") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-1), + getFloat64(+256), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt8($0)) +} + +FixedPointConversion_Debug64_ToUInt8 +.test("FromFloat64_AlwaysFails") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-1), + getFloat64(-0.5), + getFloat64(+0.5), + getFloat64(+127.5), + getFloat64(+255.5), + getFloat64(+256), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float80: (-18446744073709551615)...(18446744073709551615) +// MARK: Float80: (-18446744073709551615)...(+18446744073709551615) //===----------------------------------------------------------------------===// #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(-18446744073709551615)_AlwaysTraps") { - let input = getFloat80(-18446744073709551615) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(-18446744073709551615)_AlwaysFails") { - let input = getFloat80(-18446744073709551615) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(-32768.5)_AlwaysTraps") { - let input = getFloat80(-32768.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(-32768.5)_AlwaysFails") { - let input = getFloat80(-32768.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(-128.5)_AlwaysTraps") { - let input = getFloat80(-128.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(-128.5)_AlwaysFails") { - let input = getFloat80(-128.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(-1)_AlwaysTraps") { - let input = getFloat80(-1) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(-1)_AlwaysFails") { - let input = getFloat80(-1) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(-0.5)_NeverTraps") { - let input = getFloat80(-0.5) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(-0.5)_AlwaysFails") { - let input = getFloat80(-0.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(0)_NeverTraps") { - let input = getFloat80(0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(0)_NeverFails") { - let input = getFloat80(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(-0.0)_NeverTraps") { - let input = getFloat80(-0.0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(-0.0)_NeverFails") { - let input = getFloat80(-0.0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(0.0)_NeverTraps") { - let input = getFloat80(0.0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(0.0)_NeverFails") { - let input = getFloat80(0.0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(0.5)_NeverTraps") { - let input = getFloat80(0.5) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(0.5)_AlwaysFails") { - let input = getFloat80(0.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(127.5)_NeverTraps") { - let input = getFloat80(127.5) - let actual = UInt8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(127.5)_AlwaysFails") { - let input = getFloat80(127.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(255)_NeverTraps") { - let input = getFloat80(255) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(255)_NeverFails") { - let input = getFloat80(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(255.5)_NeverTraps") { - let input = getFloat80(255.5) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(255.5)_AlwaysFails") { - let input = getFloat80(255.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(256)_AlwaysTraps") { - let input = getFloat80(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(256)_AlwaysFails") { - let input = getFloat80(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(32767.5)_AlwaysTraps") { - let input = getFloat80(32767.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(32767.5)_AlwaysFails") { - let input = getFloat80(32767.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(65535.5)_AlwaysTraps") { - let input = getFloat80(65535.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(65535.5)_AlwaysFails") { - let input = getFloat80(65535.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(18446744073709551615)_AlwaysTraps") { - let input = getFloat80(18446744073709551615) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(18446744073709551615)_AlwaysFails") { - let input = getFloat80(18446744073709551615) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(-.infinity)_AlwaysTraps") { - let input = getFloat80(-.infinity) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(-.infinity)_AlwaysFails") { - let input = getFloat80(-.infinity) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(+.infinity)_AlwaysTraps") { - let input = getFloat80(+.infinity) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(+.infinity)_AlwaysFails") { - let input = getFloat80(+.infinity) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(-.nan)_AlwaysTraps") { - let input = getFloat80(-.nan) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(-.nan)_AlwaysFails") { - let input = getFloat80(-.nan) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(+.nan)_AlwaysTraps") { - let input = getFloat80(+.nan) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(+.nan)_AlwaysFails") { - let input = getFloat80(+.nan) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(-.signalingNaN)_AlwaysTraps") { - let input = getFloat80(-.signalingNaN) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(-.signalingNaN)_AlwaysFails") { - let input = getFloat80(-.signalingNaN) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(+.signalingNaN)_AlwaysTraps") { - let input = getFloat80(+.signalingNaN) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Debug64_ToUInt8.test("FromFloat80(+.signalingNaN)_AlwaysFails") { - let input = getFloat80(+.signalingNaN) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Debug64_ToUInt8 +.test("FromFloat80_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getFloat80(-0.5)), + (getUInt8(+0), getFloat80(-0)), + (getUInt8(+0), getFloat80(+0)), + (getUInt8(+0), getFloat80(+0.5)), + (getUInt8(+127), getFloat80(+127.5)), + (getUInt8(+255), getFloat80(+255)), + (getUInt8(+255), getFloat80(+255.5)), +]) { + expectEqual($0.0, UInt8($0.1)) +} + +FixedPointConversion_Debug64_ToUInt8 +.test("FromFloat80_NeverFails") +.forEach(in: [ + (getUInt8(+0), getFloat80(-0)), + (getUInt8(+0), getFloat80(+0)), + (getUInt8(+255), getFloat80(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) +} + +FixedPointConversion_Debug64_ToUInt8 +.test("FromFloat80_AlwaysTraps") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-1), + getFloat80(+256), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt8($0)) +} + +FixedPointConversion_Debug64_ToUInt8 +.test("FromFloat80_AlwaysFails") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-1), + getFloat80(-0.5), + getFloat80(+0.5), + getFloat80(+127.5), + getFloat80(+255.5), + getFloat80(+256), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectNil(UInt8(exactly: $0)) } #endif // Float80 diff --git a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release32_ToInt.swift b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release32_ToInt.swift index 5ef28a54d216c..e1a3f77daf82a 100644 --- a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release32_ToInt.swift +++ b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release32_ToInt.swift @@ -5,7 +5,7 @@ // //===----------------------------------------------------------------------===// // -// REQUIRES: executable_test, long_test +// REQUIRES: executable_test // REQUIRES: PTRSIZE=32 // RUN: %target-run-simple-swift(-O) // END. @@ -14,1498 +14,612 @@ import StdlibUnittest -let FixedPointConversion_Release32_ToInt = TestSuite("FixedPointConversion_Release32_ToInt") +let FixedPointConversion_Release32_ToInt = TestSuite( + "FixedPointConversion_Release32_ToInt" +) //===----------------------------------------------------------------------===// -// MARK: UInt8: (0)...(255) +// MARK: UInt8: (+0)...(+255) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt.test("FromUInt8(0)_NeverTraps") { - let input = getUInt8(0) - let actual = Int(input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToInt +.test("FromUInt8_NeverTraps") +.forEach(in: [ + (getInt(+0), getUInt8(+0)), + (getInt(+255), getUInt8(+255)), +]) { + expectEqual($0.0, Int($0.1)) } -FixedPointConversion_Release32_ToInt.test("FromUInt8(0)_NeverFails") { - let input = getUInt8(0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromUInt8(255)_NeverTraps") { - let input = getUInt8(255) - let actual = Int(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromUInt8(255)_NeverFails") { - let input = getUInt8(255) - let actual = Int(exactly: input) - expectEqual(255, actual) +FixedPointConversion_Release32_ToInt +.test("FromUInt8_NeverFails") +.forEach(in: [ + (getInt(+0), getUInt8(+0)), + (getInt(+255), getUInt8(+255)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int8: (-128)...(127) +// MARK: Int8: (-128)...(+127) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt.test("FromInt8(-128)_NeverTraps") { - let input = getInt8(-128) - let actual = Int(input) - expectEqual(-128, actual) +FixedPointConversion_Release32_ToInt +.test("FromInt8_NeverTraps") +.forEach(in: [ + (getInt(-128), getInt8(-128)), + (getInt(+0), getInt8(+0)), + (getInt(+127), getInt8(+127)), +]) { + expectEqual($0.0, Int($0.1)) } -FixedPointConversion_Release32_ToInt.test("FromInt8(-128)_NeverFails") { - let input = getInt8(-128) - let actual = Int(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromInt8(0)_NeverTraps") { - let input = getInt8(0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromInt8(0)_NeverFails") { - let input = getInt8(0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromInt8(127)_NeverTraps") { - let input = getInt8(127) - let actual = Int(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromInt8(127)_NeverFails") { - let input = getInt8(127) - let actual = Int(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Release32_ToInt +.test("FromInt8_NeverFails") +.forEach(in: [ + (getInt(-128), getInt8(-128)), + (getInt(+0), getInt8(+0)), + (getInt(+127), getInt8(+127)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt16: (0)...(65535) +// MARK: UInt16: (+0)...(+65535) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt.test("FromUInt16(0)_NeverTraps") { - let input = getUInt16(0) - let actual = Int(input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToInt +.test("FromUInt16_NeverTraps") +.forEach(in: [ + (getInt(+0), getUInt16(+0)), + (getInt(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, Int($0.1)) } -FixedPointConversion_Release32_ToInt.test("FromUInt16(0)_NeverFails") { - let input = getUInt16(0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromUInt16(65535)_NeverTraps") { - let input = getUInt16(65535) - let actual = Int(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromUInt16(65535)_NeverFails") { - let input = getUInt16(65535) - let actual = Int(exactly: input) - expectEqual(65535, actual) +FixedPointConversion_Release32_ToInt +.test("FromUInt16_NeverFails") +.forEach(in: [ + (getInt(+0), getUInt16(+0)), + (getInt(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int16: (-32768)...(32767) +// MARK: Int16: (-32768)...(+32767) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt.test("FromInt16(-32768)_NeverTraps") { - let input = getInt16(-32768) - let actual = Int(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromInt16(-32768)_NeverFails") { - let input = getInt16(-32768) - let actual = Int(exactly: input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromInt16(0)_NeverTraps") { - let input = getInt16(0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromInt16(0)_NeverFails") { - let input = getInt16(0) - let actual = Int(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToInt +.test("FromInt16_NeverTraps") +.forEach(in: [ + (getInt(-32768), getInt16(-32768)), + (getInt(+0), getInt16(+0)), + (getInt(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, Int($0.1)) } -FixedPointConversion_Release32_ToInt.test("FromInt16(32767)_NeverTraps") { - let input = getInt16(32767) - let actual = Int(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromInt16(32767)_NeverFails") { - let input = getInt16(32767) - let actual = Int(exactly: input) - expectEqual(32767, actual) +FixedPointConversion_Release32_ToInt +.test("FromInt16_NeverFails") +.forEach(in: [ + (getInt(-32768), getInt16(-32768)), + (getInt(+0), getInt16(+0)), + (getInt(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt32: (0)...(4294967295) +// MARK: UInt32: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt.test("FromUInt32(0)_NeverTraps") { - let input = getUInt32(0) - let actual = Int(input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToInt +.test("FromUInt32_NeverTraps") +.forEach(in: [ + (getInt(+0), getUInt32(+0)), + (getInt(+2147483647), getUInt32(+2147483647)), +]) { + expectEqual($0.0, Int($0.1)) } -FixedPointConversion_Release32_ToInt.test("FromUInt32(0)_NeverFails") { - let input = getUInt32(0) - let actual = Int(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToInt +.test("FromUInt32_NeverFails") +.forEach(in: [ + (getInt(+0), getUInt32(+0)), + (getInt(+2147483647), getUInt32(+2147483647)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) } -FixedPointConversion_Release32_ToInt.test("FromUInt32(2147483647)_NeverTraps") { - let input = getUInt32(2147483647) - let actual = Int(input) - expectEqual(2147483647, actual) +FixedPointConversion_Release32_ToInt +.test("FromUInt32_AlwaysTraps") +.forEach(in: [ + getUInt32(+2147483648), + getUInt32(+4294967295), +]) { + expectCrashLater() + _blackHole(Int($0)) } -FixedPointConversion_Release32_ToInt.test("FromUInt32(2147483647)_NeverFails") { - let input = getUInt32(2147483647) - let actual = Int(exactly: input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromUInt32(2147483648)_AlwaysTraps") { - let input = getUInt32(2147483648) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromUInt32(2147483648)_AlwaysFails") { - let input = getUInt32(2147483648) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromUInt32(4294967295)_AlwaysTraps") { - let input = getUInt32(4294967295) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromUInt32(4294967295)_AlwaysFails") { - let input = getUInt32(4294967295) - let actual = Int(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt +.test("FromUInt32_AlwaysFails") +.forEach(in: [ + getUInt32(+2147483648), + getUInt32(+4294967295), +]) { + expectNil(Int(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int32: (-2147483648)...(2147483647) +// MARK: Int32: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt.test("FromInt32(-2147483648)_NeverTraps") { - let input = getInt32(-2147483648) - let actual = Int(input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromInt32(-2147483648)_NeverFails") { - let input = getInt32(-2147483648) - let actual = Int(exactly: input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromInt32(0)_NeverTraps") { - let input = getInt32(0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromInt32(0)_NeverFails") { - let input = getInt32(0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromInt32(2147483647)_NeverTraps") { - let input = getInt32(2147483647) - let actual = Int(input) - expectEqual(2147483647, actual) +FixedPointConversion_Release32_ToInt +.test("FromInt32_NeverTraps") +.forEach(in: [ + (getInt(-2147483648), getInt32(-2147483648)), + (getInt(+0), getInt32(+0)), + (getInt(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, Int($0.1)) } -FixedPointConversion_Release32_ToInt.test("FromInt32(2147483647)_NeverFails") { - let input = getInt32(2147483647) - let actual = Int(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Release32_ToInt +.test("FromInt32_NeverFails") +.forEach(in: [ + (getInt(-2147483648), getInt32(-2147483648)), + (getInt(+0), getInt32(+0)), + (getInt(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt64: (0)...(18446744073709551615) +// MARK: UInt64: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt.test("FromUInt64(0)_NeverTraps") { - let input = getUInt64(0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromUInt64(0)_NeverFails") { - let input = getUInt64(0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromUInt64(2147483647)_NeverTraps") { - let input = getUInt64(2147483647) - let actual = Int(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromUInt64(2147483647)_NeverFails") { - let input = getUInt64(2147483647) - let actual = Int(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Release32_ToInt +.test("FromUInt64_NeverTraps") +.forEach(in: [ + (getInt(+0), getUInt64(+0)), + (getInt(+2147483647), getUInt64(+2147483647)), +]) { + expectEqual($0.0, Int($0.1)) } -FixedPointConversion_Release32_ToInt.test("FromUInt64(2147483648)_AlwaysTraps") { - let input = getUInt64(2147483648) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } +FixedPointConversion_Release32_ToInt +.test("FromUInt64_NeverFails") +.forEach(in: [ + (getInt(+0), getUInt64(+0)), + (getInt(+2147483647), getUInt64(+2147483647)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) } -FixedPointConversion_Release32_ToInt.test("FromUInt64(2147483648)_AlwaysFails") { - let input = getUInt64(2147483648) - let actual = Int(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt +.test("FromUInt64_AlwaysTraps") +.forEach(in: [ + getUInt64(+2147483648), + getUInt64(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(Int($0)) } -FixedPointConversion_Release32_ToInt.test("FromUInt64(18446744073709551615)_AlwaysTraps") { - let input = getUInt64(18446744073709551615) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromUInt64(18446744073709551615)_AlwaysFails") { - let input = getUInt64(18446744073709551615) - let actual = Int(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt +.test("FromUInt64_AlwaysFails") +.forEach(in: [ + getUInt64(+2147483648), + getUInt64(+18446744073709551615), +]) { + expectNil(Int(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int64: (-9223372036854775808)...(9223372036854775807) +// MARK: Int64: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt.test("FromInt64(-9223372036854775808)_AlwaysTraps") { - let input = getInt64(-9223372036854775808) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromInt64(-9223372036854775808)_AlwaysFails") { - let input = getInt64(-9223372036854775808) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromInt64(-2147483649)_AlwaysTraps") { - let input = getInt64(-2147483649) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromInt64(-2147483649)_AlwaysFails") { - let input = getInt64(-2147483649) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromInt64(-2147483648)_NeverTraps") { - let input = getInt64(-2147483648) - let actual = Int(input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromInt64(-2147483648)_NeverFails") { - let input = getInt64(-2147483648) - let actual = Int(exactly: input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromInt64(0)_NeverTraps") { - let input = getInt64(0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromInt64(0)_NeverFails") { - let input = getInt64(0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromInt64(2147483647)_NeverTraps") { - let input = getInt64(2147483647) - let actual = Int(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromInt64(2147483647)_NeverFails") { - let input = getInt64(2147483647) - let actual = Int(exactly: input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromInt64(2147483648)_AlwaysTraps") { - let input = getInt64(2147483648) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromInt64(2147483648)_AlwaysFails") { - let input = getInt64(2147483648) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromInt64(9223372036854775807)_AlwaysTraps") { - let input = getInt64(9223372036854775807) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromInt64(9223372036854775807)_AlwaysFails") { - let input = getInt64(9223372036854775807) - let actual = Int(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt +.test("FromInt64_NeverTraps") +.forEach(in: [ + (getInt(-2147483648), getInt64(-2147483648)), + (getInt(+0), getInt64(+0)), + (getInt(+2147483647), getInt64(+2147483647)), +]) { + expectEqual($0.0, Int($0.1)) +} + +FixedPointConversion_Release32_ToInt +.test("FromInt64_NeverFails") +.forEach(in: [ + (getInt(-2147483648), getInt64(-2147483648)), + (getInt(+0), getInt64(+0)), + (getInt(+2147483647), getInt64(+2147483647)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToInt +.test("FromInt64_AlwaysTraps") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-2147483649), + getInt64(+2147483648), + getInt64(+9223372036854775807), +]) { + expectCrashLater() + _blackHole(Int($0)) +} + +FixedPointConversion_Release32_ToInt +.test("FromInt64_AlwaysFails") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-2147483649), + getInt64(+2147483648), + getInt64(+9223372036854775807), +]) { + expectNil(Int(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt: (0)...(4294967295) +// MARK: UInt: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt.test("FromUInt(0)_NeverTraps") { - let input = getUInt(0) - let actual = Int(input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToInt +.test("FromUInt_NeverTraps") +.forEach(in: [ + (getInt(+0), getUInt(+0)), + (getInt(+2147483647), getUInt(+2147483647)), +]) { + expectEqual($0.0, Int($0.1)) } -FixedPointConversion_Release32_ToInt.test("FromUInt(0)_NeverFails") { - let input = getUInt(0) - let actual = Int(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToInt +.test("FromUInt_NeverFails") +.forEach(in: [ + (getInt(+0), getUInt(+0)), + (getInt(+2147483647), getUInt(+2147483647)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) } -FixedPointConversion_Release32_ToInt.test("FromUInt(2147483647)_NeverTraps") { - let input = getUInt(2147483647) - let actual = Int(input) - expectEqual(2147483647, actual) +FixedPointConversion_Release32_ToInt +.test("FromUInt_AlwaysTraps") +.forEach(in: [ + getUInt(+2147483648), + getUInt(+4294967295), +]) { + expectCrashLater() + _blackHole(Int($0)) } -FixedPointConversion_Release32_ToInt.test("FromUInt(2147483647)_NeverFails") { - let input = getUInt(2147483647) - let actual = Int(exactly: input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromUInt(2147483648)_AlwaysTraps") { - let input = getUInt(2147483648) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromUInt(2147483648)_AlwaysFails") { - let input = getUInt(2147483648) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromUInt(4294967295)_AlwaysTraps") { - let input = getUInt(4294967295) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromUInt(4294967295)_AlwaysFails") { - let input = getUInt(4294967295) - let actual = Int(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt +.test("FromUInt_AlwaysFails") +.forEach(in: [ + getUInt(+2147483648), + getUInt(+4294967295), +]) { + expectNil(Int(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int: (-2147483648)...(2147483647) +// MARK: Int: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt.test("FromInt(-2147483648)_NeverTraps") { - let input = getInt(-2147483648) - let actual = Int(input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromInt(-2147483648)_NeverFails") { - let input = getInt(-2147483648) - let actual = Int(exactly: input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromInt(0)_NeverTraps") { - let input = getInt(0) - let actual = Int(input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToInt +.test("FromInt_NeverTraps") +.forEach(in: [ + (getInt(-2147483648), getInt(-2147483648)), + (getInt(+0), getInt(+0)), + (getInt(+2147483647), getInt(+2147483647)), +]) { + expectEqual($0.0, Int($0.1)) } -FixedPointConversion_Release32_ToInt.test("FromInt(0)_NeverFails") { - let input = getInt(0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromInt(2147483647)_NeverTraps") { - let input = getInt(2147483647) - let actual = Int(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromInt(2147483647)_NeverFails") { - let input = getInt(2147483647) - let actual = Int(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Release32_ToInt +.test("FromInt_NeverFails") +.forEach(in: [ + (getInt(-2147483648), getInt(-2147483648)), + (getInt(+0), getInt(+0)), + (getInt(+2147483647), getInt(+2147483647)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Float16: (-2047)...(2047) +// MARK: Float16: (-2047)...(+2047) //===----------------------------------------------------------------------===// #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -FixedPointConversion_Release32_ToInt.test("FromFloat16(-2047)_NeverTraps") { - let input = getFloat16(-2047) - let actual = Int(input) - expectEqual(-2047, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat16(-2047)_NeverFails") { - let input = getFloat16(-2047) - let actual = Int(exactly: input) - expectEqual(-2047, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat16(-128.5)_NeverTraps") { - let input = getFloat16(-128.5) - let actual = Int(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat16(-128.5)_AlwaysFails") { - let input = getFloat16(-128.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat16(-0.5)_NeverTraps") { - let input = getFloat16(-0.5) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat16(-0.5)_AlwaysFails") { - let input = getFloat16(-0.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat16(-0.0)_NeverTraps") { - let input = getFloat16(-0.0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat16(-0.0)_NeverFails") { - let input = getFloat16(-0.0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat16(0.0)_NeverTraps") { - let input = getFloat16(0.0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat16(0.0)_NeverFails") { - let input = getFloat16(0.0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat16(0.5)_NeverTraps") { - let input = getFloat16(0.5) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat16(0.5)_AlwaysFails") { - let input = getFloat16(0.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat16(127.5)_NeverTraps") { - let input = getFloat16(127.5) - let actual = Int(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat16(127.5)_AlwaysFails") { - let input = getFloat16(127.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat16(255.5)_NeverTraps") { - let input = getFloat16(255.5) - let actual = Int(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat16(255.5)_AlwaysFails") { - let input = getFloat16(255.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat16(2047)_NeverTraps") { - let input = getFloat16(2047) - let actual = Int(input) - expectEqual(2047, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat16(2047)_NeverFails") { - let input = getFloat16(2047) - let actual = Int(exactly: input) - expectEqual(2047, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat16(-.infinity)_AlwaysTraps") { - let input = getFloat16(-.infinity) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromFloat16(-.infinity)_AlwaysFails") { - let input = getFloat16(-.infinity) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat16(+.infinity)_AlwaysTraps") { - let input = getFloat16(+.infinity) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromFloat16(+.infinity)_AlwaysFails") { - let input = getFloat16(+.infinity) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat16(-.nan)_AlwaysTraps") { - let input = getFloat16(-.nan) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromFloat16(-.nan)_AlwaysFails") { - let input = getFloat16(-.nan) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat16(+.nan)_AlwaysTraps") { - let input = getFloat16(+.nan) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromFloat16(+.nan)_AlwaysFails") { - let input = getFloat16(+.nan) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat16(-.signalingNaN)_AlwaysTraps") { - let input = getFloat16(-.signalingNaN) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromFloat16(-.signalingNaN)_AlwaysFails") { - let input = getFloat16(-.signalingNaN) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat16(+.signalingNaN)_AlwaysTraps") { - let input = getFloat16(+.signalingNaN) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromFloat16(+.signalingNaN)_AlwaysFails") { - let input = getFloat16(+.signalingNaN) - let actual = Int(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt +.test("FromFloat16_NeverTraps") +.forEach(in: [ + (getInt(-2047), getFloat16(-2047)), + (getInt(-128), getFloat16(-128.5)), + (getInt(+0), getFloat16(-0.5)), + (getInt(+0), getFloat16(+0)), + (getInt(+0), getFloat16(-0)), + (getInt(+0), getFloat16(+0.5)), + (getInt(+127), getFloat16(+127.5)), + (getInt(+255), getFloat16(+255.5)), + (getInt(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, Int($0.1)) +} + +FixedPointConversion_Release32_ToInt +.test("FromFloat16_NeverFails") +.forEach(in: [ + (getInt(-2047), getFloat16(-2047)), + (getInt(+0), getFloat16(+0)), + (getInt(+0), getFloat16(-0)), + (getInt(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToInt +.test("FromFloat16_AlwaysTraps") +.forEach(in: [ + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int($0)) +} + +FixedPointConversion_Release32_ToInt +.test("FromFloat16_AlwaysFails") +.forEach(in: [ + getFloat16(-128.5), + getFloat16(-0.5), + getFloat16(+0.5), + getFloat16(+127.5), + getFloat16(+255.5), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectNil(Int(exactly: $0)) } } #endif // Float16 //===----------------------------------------------------------------------===// -// MARK: Float32: (-16777215)...(16777215) +// MARK: Float32: (-16777215)...(+16777215) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt.test("FromFloat32(-16777215)_NeverTraps") { - let input = getFloat32(-16777215) - let actual = Int(input) - expectEqual(-16777215, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat32(-16777215)_NeverFails") { - let input = getFloat32(-16777215) - let actual = Int(exactly: input) - expectEqual(-16777215, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat32(-32768.5)_NeverTraps") { - let input = getFloat32(-32768.5) - let actual = Int(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat32(-32768.5)_AlwaysFails") { - let input = getFloat32(-32768.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat32(-128.5)_NeverTraps") { - let input = getFloat32(-128.5) - let actual = Int(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat32(-128.5)_AlwaysFails") { - let input = getFloat32(-128.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat32(-0.5)_NeverTraps") { - let input = getFloat32(-0.5) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat32(-0.5)_AlwaysFails") { - let input = getFloat32(-0.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat32(-0.0)_NeverTraps") { - let input = getFloat32(-0.0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat32(-0.0)_NeverFails") { - let input = getFloat32(-0.0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat32(0.0)_NeverTraps") { - let input = getFloat32(0.0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat32(0.0)_NeverFails") { - let input = getFloat32(0.0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat32(0.5)_NeverTraps") { - let input = getFloat32(0.5) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat32(0.5)_AlwaysFails") { - let input = getFloat32(0.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat32(127.5)_NeverTraps") { - let input = getFloat32(127.5) - let actual = Int(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat32(127.5)_AlwaysFails") { - let input = getFloat32(127.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat32(255.5)_NeverTraps") { - let input = getFloat32(255.5) - let actual = Int(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat32(255.5)_AlwaysFails") { - let input = getFloat32(255.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat32(32767.5)_NeverTraps") { - let input = getFloat32(32767.5) - let actual = Int(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat32(32767.5)_AlwaysFails") { - let input = getFloat32(32767.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat32(65535.5)_NeverTraps") { - let input = getFloat32(65535.5) - let actual = Int(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat32(65535.5)_AlwaysFails") { - let input = getFloat32(65535.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat32(16777215)_NeverTraps") { - let input = getFloat32(16777215) - let actual = Int(input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat32(16777215)_NeverFails") { - let input = getFloat32(16777215) - let actual = Int(exactly: input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat32(-.infinity)_AlwaysTraps") { - let input = getFloat32(-.infinity) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromFloat32(-.infinity)_AlwaysFails") { - let input = getFloat32(-.infinity) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat32(+.infinity)_AlwaysTraps") { - let input = getFloat32(+.infinity) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromFloat32(+.infinity)_AlwaysFails") { - let input = getFloat32(+.infinity) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat32(-.nan)_AlwaysTraps") { - let input = getFloat32(-.nan) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromFloat32(-.nan)_AlwaysFails") { - let input = getFloat32(-.nan) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat32(+.nan)_AlwaysTraps") { - let input = getFloat32(+.nan) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromFloat32(+.nan)_AlwaysFails") { - let input = getFloat32(+.nan) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat32(-.signalingNaN)_AlwaysTraps") { - let input = getFloat32(-.signalingNaN) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromFloat32(-.signalingNaN)_AlwaysFails") { - let input = getFloat32(-.signalingNaN) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat32(+.signalingNaN)_AlwaysTraps") { - let input = getFloat32(+.signalingNaN) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromFloat32(+.signalingNaN)_AlwaysFails") { - let input = getFloat32(+.signalingNaN) - let actual = Int(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt +.test("FromFloat32_NeverTraps") +.forEach(in: [ + (getInt(-16777215), getFloat32(-16777215)), + (getInt(-32768), getFloat32(-32768.5)), + (getInt(-128), getFloat32(-128.5)), + (getInt(+0), getFloat32(-0.5)), + (getInt(+0), getFloat32(+0)), + (getInt(+0), getFloat32(-0)), + (getInt(+0), getFloat32(+0.5)), + (getInt(+127), getFloat32(+127.5)), + (getInt(+255), getFloat32(+255.5)), + (getInt(+32767), getFloat32(+32767.5)), + (getInt(+65535), getFloat32(+65535.5)), + (getInt(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, Int($0.1)) +} + +FixedPointConversion_Release32_ToInt +.test("FromFloat32_NeverFails") +.forEach(in: [ + (getInt(-16777215), getFloat32(-16777215)), + (getInt(+0), getFloat32(+0)), + (getInt(+0), getFloat32(-0)), + (getInt(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToInt +.test("FromFloat32_AlwaysTraps") +.forEach(in: [ + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int($0)) +} + +FixedPointConversion_Release32_ToInt +.test("FromFloat32_AlwaysFails") +.forEach(in: [ + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-0.5), + getFloat32(+0.5), + getFloat32(+127.5), + getFloat32(+255.5), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectNil(Int(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float64: (-9007199254740991)...(9007199254740991) +// MARK: Float64: (-9007199254740991)...(+9007199254740991) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt.test("FromFloat64(-9007199254740991)_AlwaysTraps") { - let input = getFloat64(-9007199254740991) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(-9007199254740991)_AlwaysFails") { - let input = getFloat64(-9007199254740991) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(-2147483649)_AlwaysTraps") { - let input = getFloat64(-2147483649) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(-2147483649)_AlwaysFails") { - let input = getFloat64(-2147483649) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(-2147483648)_NeverTraps") { - let input = getFloat64(-2147483648) - let actual = Int(input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(-2147483648)_NeverFails") { - let input = getFloat64(-2147483648) - let actual = Int(exactly: input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(-32768.5)_NeverTraps") { - let input = getFloat64(-32768.5) - let actual = Int(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(-32768.5)_AlwaysFails") { - let input = getFloat64(-32768.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(-128.5)_NeverTraps") { - let input = getFloat64(-128.5) - let actual = Int(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(-128.5)_AlwaysFails") { - let input = getFloat64(-128.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(-0.5)_NeverTraps") { - let input = getFloat64(-0.5) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(-0.5)_AlwaysFails") { - let input = getFloat64(-0.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(-0.0)_NeverTraps") { - let input = getFloat64(-0.0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(-0.0)_NeverFails") { - let input = getFloat64(-0.0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(0.0)_NeverTraps") { - let input = getFloat64(0.0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(0.0)_NeverFails") { - let input = getFloat64(0.0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(0.5)_NeverTraps") { - let input = getFloat64(0.5) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(0.5)_AlwaysFails") { - let input = getFloat64(0.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(127.5)_NeverTraps") { - let input = getFloat64(127.5) - let actual = Int(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(127.5)_AlwaysFails") { - let input = getFloat64(127.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(255.5)_NeverTraps") { - let input = getFloat64(255.5) - let actual = Int(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(255.5)_AlwaysFails") { - let input = getFloat64(255.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(32767.5)_NeverTraps") { - let input = getFloat64(32767.5) - let actual = Int(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(32767.5)_AlwaysFails") { - let input = getFloat64(32767.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(65535.5)_NeverTraps") { - let input = getFloat64(65535.5) - let actual = Int(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(65535.5)_AlwaysFails") { - let input = getFloat64(65535.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(2147483647)_NeverTraps") { - let input = getFloat64(2147483647) - let actual = Int(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(2147483647)_NeverFails") { - let input = getFloat64(2147483647) - let actual = Int(exactly: input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(2147483648)_AlwaysTraps") { - let input = getFloat64(2147483648) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(2147483648)_AlwaysFails") { - let input = getFloat64(2147483648) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(9007199254740991)_AlwaysTraps") { - let input = getFloat64(9007199254740991) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(9007199254740991)_AlwaysFails") { - let input = getFloat64(9007199254740991) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(-.infinity)_AlwaysTraps") { - let input = getFloat64(-.infinity) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(-.infinity)_AlwaysFails") { - let input = getFloat64(-.infinity) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(+.infinity)_AlwaysTraps") { - let input = getFloat64(+.infinity) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(+.infinity)_AlwaysFails") { - let input = getFloat64(+.infinity) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(-.nan)_AlwaysTraps") { - let input = getFloat64(-.nan) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(-.nan)_AlwaysFails") { - let input = getFloat64(-.nan) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(+.nan)_AlwaysTraps") { - let input = getFloat64(+.nan) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(+.nan)_AlwaysFails") { - let input = getFloat64(+.nan) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(-.signalingNaN)_AlwaysTraps") { - let input = getFloat64(-.signalingNaN) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(-.signalingNaN)_AlwaysFails") { - let input = getFloat64(-.signalingNaN) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(+.signalingNaN)_AlwaysTraps") { - let input = getFloat64(+.signalingNaN) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromFloat64(+.signalingNaN)_AlwaysFails") { - let input = getFloat64(+.signalingNaN) - let actual = Int(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt +.test("FromFloat64_NeverTraps") +.forEach(in: [ + (getInt(-2147483648), getFloat64(-2147483648)), + (getInt(-32768), getFloat64(-32768.5)), + (getInt(-128), getFloat64(-128.5)), + (getInt(+0), getFloat64(-0.5)), + (getInt(+0), getFloat64(-0)), + (getInt(+0), getFloat64(+0)), + (getInt(+0), getFloat64(+0.5)), + (getInt(+127), getFloat64(+127.5)), + (getInt(+255), getFloat64(+255.5)), + (getInt(+32767), getFloat64(+32767.5)), + (getInt(+65535), getFloat64(+65535.5)), + (getInt(+2147483647), getFloat64(+2147483647)), +]) { + expectEqual($0.0, Int($0.1)) +} + +FixedPointConversion_Release32_ToInt +.test("FromFloat64_NeverFails") +.forEach(in: [ + (getInt(-2147483648), getFloat64(-2147483648)), + (getInt(+0), getFloat64(-0)), + (getInt(+0), getFloat64(+0)), + (getInt(+2147483647), getFloat64(+2147483647)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToInt +.test("FromFloat64_AlwaysTraps") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-2147483649), + getFloat64(+2147483648), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int($0)) +} + +FixedPointConversion_Release32_ToInt +.test("FromFloat64_AlwaysFails") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-2147483649), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-0.5), + getFloat64(+0.5), + getFloat64(+127.5), + getFloat64(+255.5), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(+2147483648), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectNil(Int(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float80: (-18446744073709551615)...(18446744073709551615) +// MARK: Float80: (-18446744073709551615)...(+18446744073709551615) //===----------------------------------------------------------------------===// #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) -FixedPointConversion_Release32_ToInt.test("FromFloat80(-18446744073709551615)_AlwaysTraps") { - let input = getFloat80(-18446744073709551615) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(-18446744073709551615)_AlwaysFails") { - let input = getFloat80(-18446744073709551615) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(-2147483649)_AlwaysTraps") { - let input = getFloat80(-2147483649) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(-2147483649)_AlwaysFails") { - let input = getFloat80(-2147483649) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(-2147483648)_NeverTraps") { - let input = getFloat80(-2147483648) - let actual = Int(input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(-2147483648)_NeverFails") { - let input = getFloat80(-2147483648) - let actual = Int(exactly: input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(-32768.5)_NeverTraps") { - let input = getFloat80(-32768.5) - let actual = Int(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(-32768.5)_AlwaysFails") { - let input = getFloat80(-32768.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(-128.5)_NeverTraps") { - let input = getFloat80(-128.5) - let actual = Int(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(-128.5)_AlwaysFails") { - let input = getFloat80(-128.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(-0.5)_NeverTraps") { - let input = getFloat80(-0.5) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(-0.5)_AlwaysFails") { - let input = getFloat80(-0.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(-0.0)_NeverTraps") { - let input = getFloat80(-0.0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(-0.0)_NeverFails") { - let input = getFloat80(-0.0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(0.0)_NeverTraps") { - let input = getFloat80(0.0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(0.0)_NeverFails") { - let input = getFloat80(0.0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(0.5)_NeverTraps") { - let input = getFloat80(0.5) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(0.5)_AlwaysFails") { - let input = getFloat80(0.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(127.5)_NeverTraps") { - let input = getFloat80(127.5) - let actual = Int(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(127.5)_AlwaysFails") { - let input = getFloat80(127.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(255.5)_NeverTraps") { - let input = getFloat80(255.5) - let actual = Int(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(255.5)_AlwaysFails") { - let input = getFloat80(255.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(32767.5)_NeverTraps") { - let input = getFloat80(32767.5) - let actual = Int(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(32767.5)_AlwaysFails") { - let input = getFloat80(32767.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(65535.5)_NeverTraps") { - let input = getFloat80(65535.5) - let actual = Int(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(65535.5)_AlwaysFails") { - let input = getFloat80(65535.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(2147483647)_NeverTraps") { - let input = getFloat80(2147483647) - let actual = Int(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(2147483647)_NeverFails") { - let input = getFloat80(2147483647) - let actual = Int(exactly: input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(2147483648)_AlwaysTraps") { - let input = getFloat80(2147483648) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(2147483648)_AlwaysFails") { - let input = getFloat80(2147483648) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(18446744073709551615)_AlwaysTraps") { - let input = getFloat80(18446744073709551615) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(18446744073709551615)_AlwaysFails") { - let input = getFloat80(18446744073709551615) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(-.infinity)_AlwaysTraps") { - let input = getFloat80(-.infinity) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(-.infinity)_AlwaysFails") { - let input = getFloat80(-.infinity) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(+.infinity)_AlwaysTraps") { - let input = getFloat80(+.infinity) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(+.infinity)_AlwaysFails") { - let input = getFloat80(+.infinity) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(-.nan)_AlwaysTraps") { - let input = getFloat80(-.nan) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(-.nan)_AlwaysFails") { - let input = getFloat80(-.nan) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(+.nan)_AlwaysTraps") { - let input = getFloat80(+.nan) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(+.nan)_AlwaysFails") { - let input = getFloat80(+.nan) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(-.signalingNaN)_AlwaysTraps") { - let input = getFloat80(-.signalingNaN) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(-.signalingNaN)_AlwaysFails") { - let input = getFloat80(-.signalingNaN) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(+.signalingNaN)_AlwaysTraps") { - let input = getFloat80(+.signalingNaN) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt.test("FromFloat80(+.signalingNaN)_AlwaysFails") { - let input = getFloat80(+.signalingNaN) - let actual = Int(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt +.test("FromFloat80_NeverTraps") +.forEach(in: [ + (getInt(-2147483648), getFloat80(-2147483648)), + (getInt(-32768), getFloat80(-32768.5)), + (getInt(-128), getFloat80(-128.5)), + (getInt(+0), getFloat80(-0.5)), + (getInt(+0), getFloat80(-0)), + (getInt(+0), getFloat80(+0)), + (getInt(+0), getFloat80(+0.5)), + (getInt(+127), getFloat80(+127.5)), + (getInt(+255), getFloat80(+255.5)), + (getInt(+32767), getFloat80(+32767.5)), + (getInt(+65535), getFloat80(+65535.5)), + (getInt(+2147483647), getFloat80(+2147483647)), +]) { + expectEqual($0.0, Int($0.1)) +} + +FixedPointConversion_Release32_ToInt +.test("FromFloat80_NeverFails") +.forEach(in: [ + (getInt(-2147483648), getFloat80(-2147483648)), + (getInt(+0), getFloat80(-0)), + (getInt(+0), getFloat80(+0)), + (getInt(+2147483647), getFloat80(+2147483647)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToInt +.test("FromFloat80_AlwaysTraps") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-2147483649), + getFloat80(+2147483648), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int($0)) +} + +FixedPointConversion_Release32_ToInt +.test("FromFloat80_AlwaysFails") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-2147483649), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-0.5), + getFloat80(+0.5), + getFloat80(+127.5), + getFloat80(+255.5), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(+2147483648), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectNil(Int(exactly: $0)) } #endif // Float80 diff --git a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release32_ToInt16.swift b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release32_ToInt16.swift index b0dc4238104f6..c7da28f7eac7e 100644 --- a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release32_ToInt16.swift +++ b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release32_ToInt16.swift @@ -5,7 +5,7 @@ // //===----------------------------------------------------------------------===// // -// REQUIRES: executable_test, long_test +// REQUIRES: executable_test // REQUIRES: PTRSIZE=32 // RUN: %target-run-simple-swift(-O) // END. @@ -14,1700 +14,685 @@ import StdlibUnittest -let FixedPointConversion_Release32_ToInt16 = TestSuite("FixedPointConversion_Release32_ToInt16") +let FixedPointConversion_Release32_ToInt16 = TestSuite( + "FixedPointConversion_Release32_ToInt16" +) //===----------------------------------------------------------------------===// -// MARK: UInt8: (0)...(255) +// MARK: UInt8: (+0)...(+255) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt16.test("FromUInt8(0)_NeverTraps") { - let input = getUInt8(0) - let actual = Int16(input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToInt16 +.test("FromUInt8_NeverTraps") +.forEach(in: [ + (getInt16(+0), getUInt8(+0)), + (getInt16(+255), getUInt8(+255)), +]) { + expectEqual($0.0, Int16($0.1)) } -FixedPointConversion_Release32_ToInt16.test("FromUInt8(0)_NeverFails") { - let input = getUInt8(0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromUInt8(255)_NeverTraps") { - let input = getUInt8(255) - let actual = Int16(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromUInt8(255)_NeverFails") { - let input = getUInt8(255) - let actual = Int16(exactly: input) - expectEqual(255, actual) +FixedPointConversion_Release32_ToInt16 +.test("FromUInt8_NeverFails") +.forEach(in: [ + (getInt16(+0), getUInt8(+0)), + (getInt16(+255), getUInt8(+255)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int8: (-128)...(127) +// MARK: Int8: (-128)...(+127) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt16.test("FromInt8(-128)_NeverTraps") { - let input = getInt8(-128) - let actual = Int16(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromInt8(-128)_NeverFails") { - let input = getInt8(-128) - let actual = Int16(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromInt8(0)_NeverTraps") { - let input = getInt8(0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromInt8(0)_NeverFails") { - let input = getInt8(0) - let actual = Int16(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToInt16 +.test("FromInt8_NeverTraps") +.forEach(in: [ + (getInt16(-128), getInt8(-128)), + (getInt16(+0), getInt8(+0)), + (getInt16(+127), getInt8(+127)), +]) { + expectEqual($0.0, Int16($0.1)) } -FixedPointConversion_Release32_ToInt16.test("FromInt8(127)_NeverTraps") { - let input = getInt8(127) - let actual = Int16(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromInt8(127)_NeverFails") { - let input = getInt8(127) - let actual = Int16(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Release32_ToInt16 +.test("FromInt8_NeverFails") +.forEach(in: [ + (getInt16(-128), getInt8(-128)), + (getInt16(+0), getInt8(+0)), + (getInt16(+127), getInt8(+127)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt16: (0)...(65535) +// MARK: UInt16: (+0)...(+65535) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt16.test("FromUInt16(0)_NeverTraps") { - let input = getUInt16(0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromUInt16(0)_NeverFails") { - let input = getUInt16(0) - let actual = Int16(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToInt16 +.test("FromUInt16_NeverTraps") +.forEach(in: [ + (getInt16(+0), getUInt16(+0)), + (getInt16(+32767), getUInt16(+32767)), +]) { + expectEqual($0.0, Int16($0.1)) } -FixedPointConversion_Release32_ToInt16.test("FromUInt16(32767)_NeverTraps") { - let input = getUInt16(32767) - let actual = Int16(input) - expectEqual(32767, actual) +FixedPointConversion_Release32_ToInt16 +.test("FromUInt16_NeverFails") +.forEach(in: [ + (getInt16(+0), getUInt16(+0)), + (getInt16(+32767), getUInt16(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) } -FixedPointConversion_Release32_ToInt16.test("FromUInt16(32767)_NeverFails") { - let input = getUInt16(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) +FixedPointConversion_Release32_ToInt16 +.test("FromUInt16_AlwaysTraps") +.forEach(in: [ + getUInt16(+32768), + getUInt16(+65535), +]) { + expectCrashLater() + _blackHole(Int16($0)) } -FixedPointConversion_Release32_ToInt16.test("FromUInt16(32768)_AlwaysTraps") { - let input = getUInt16(32768) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromUInt16(32768)_AlwaysFails") { - let input = getUInt16(32768) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromUInt16(65535)_AlwaysTraps") { - let input = getUInt16(65535) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromUInt16(65535)_AlwaysFails") { - let input = getUInt16(65535) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt16 +.test("FromUInt16_AlwaysFails") +.forEach(in: [ + getUInt16(+32768), + getUInt16(+65535), +]) { + expectNil(Int16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int16: (-32768)...(32767) +// MARK: Int16: (-32768)...(+32767) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt16.test("FromInt16(-32768)_NeverTraps") { - let input = getInt16(-32768) - let actual = Int16(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromInt16(-32768)_NeverFails") { - let input = getInt16(-32768) - let actual = Int16(exactly: input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromInt16(0)_NeverTraps") { - let input = getInt16(0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromInt16(0)_NeverFails") { - let input = getInt16(0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromInt16(32767)_NeverTraps") { - let input = getInt16(32767) - let actual = Int16(input) - expectEqual(32767, actual) +FixedPointConversion_Release32_ToInt16 +.test("FromInt16_NeverTraps") +.forEach(in: [ + (getInt16(-32768), getInt16(-32768)), + (getInt16(+0), getInt16(+0)), + (getInt16(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, Int16($0.1)) } -FixedPointConversion_Release32_ToInt16.test("FromInt16(32767)_NeverFails") { - let input = getInt16(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) +FixedPointConversion_Release32_ToInt16 +.test("FromInt16_NeverFails") +.forEach(in: [ + (getInt16(-32768), getInt16(-32768)), + (getInt16(+0), getInt16(+0)), + (getInt16(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt32: (0)...(4294967295) +// MARK: UInt32: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt16.test("FromUInt32(0)_NeverTraps") { - let input = getUInt32(0) - let actual = Int16(input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToInt16 +.test("FromUInt32_NeverTraps") +.forEach(in: [ + (getInt16(+0), getUInt32(+0)), + (getInt16(+32767), getUInt32(+32767)), +]) { + expectEqual($0.0, Int16($0.1)) } -FixedPointConversion_Release32_ToInt16.test("FromUInt32(0)_NeverFails") { - let input = getUInt32(0) - let actual = Int16(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToInt16 +.test("FromUInt32_NeverFails") +.forEach(in: [ + (getInt16(+0), getUInt32(+0)), + (getInt16(+32767), getUInt32(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) } -FixedPointConversion_Release32_ToInt16.test("FromUInt32(32767)_NeverTraps") { - let input = getUInt32(32767) - let actual = Int16(input) - expectEqual(32767, actual) +FixedPointConversion_Release32_ToInt16 +.test("FromUInt32_AlwaysTraps") +.forEach(in: [ + getUInt32(+32768), + getUInt32(+4294967295), +]) { + expectCrashLater() + _blackHole(Int16($0)) } -FixedPointConversion_Release32_ToInt16.test("FromUInt32(32767)_NeverFails") { - let input = getUInt32(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromUInt32(32768)_AlwaysTraps") { - let input = getUInt32(32768) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromUInt32(32768)_AlwaysFails") { - let input = getUInt32(32768) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromUInt32(4294967295)_AlwaysTraps") { - let input = getUInt32(4294967295) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromUInt32(4294967295)_AlwaysFails") { - let input = getUInt32(4294967295) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt16 +.test("FromUInt32_AlwaysFails") +.forEach(in: [ + getUInt32(+32768), + getUInt32(+4294967295), +]) { + expectNil(Int16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int32: (-2147483648)...(2147483647) +// MARK: Int32: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt16.test("FromInt32(-2147483648)_AlwaysTraps") { - let input = getInt32(-2147483648) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromInt32(-2147483648)_AlwaysFails") { - let input = getInt32(-2147483648) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromInt32(-32769)_AlwaysTraps") { - let input = getInt32(-32769) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromInt32(-32769)_AlwaysFails") { - let input = getInt32(-32769) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromInt32(-32768)_NeverTraps") { - let input = getInt32(-32768) - let actual = Int16(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromInt32(-32768)_NeverFails") { - let input = getInt32(-32768) - let actual = Int16(exactly: input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromInt32(0)_NeverTraps") { - let input = getInt32(0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromInt32(0)_NeverFails") { - let input = getInt32(0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromInt32(32767)_NeverTraps") { - let input = getInt32(32767) - let actual = Int16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromInt32(32767)_NeverFails") { - let input = getInt32(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromInt32(32768)_AlwaysTraps") { - let input = getInt32(32768) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromInt32(32768)_AlwaysFails") { - let input = getInt32(32768) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromInt32(2147483647)_AlwaysTraps") { - let input = getInt32(2147483647) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromInt32(2147483647)_AlwaysFails") { - let input = getInt32(2147483647) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt16 +.test("FromInt32_NeverTraps") +.forEach(in: [ + (getInt16(-32768), getInt32(-32768)), + (getInt16(+0), getInt32(+0)), + (getInt16(+32767), getInt32(+32767)), +]) { + expectEqual($0.0, Int16($0.1)) +} + +FixedPointConversion_Release32_ToInt16 +.test("FromInt32_NeverFails") +.forEach(in: [ + (getInt16(-32768), getInt32(-32768)), + (getInt16(+0), getInt32(+0)), + (getInt16(+32767), getInt32(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToInt16 +.test("FromInt32_AlwaysTraps") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-32769), + getInt32(+32768), + getInt32(+2147483647), +]) { + expectCrashLater() + _blackHole(Int16($0)) +} + +FixedPointConversion_Release32_ToInt16 +.test("FromInt32_AlwaysFails") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-32769), + getInt32(+32768), + getInt32(+2147483647), +]) { + expectNil(Int16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt64: (0)...(18446744073709551615) +// MARK: UInt64: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt16.test("FromUInt64(0)_NeverTraps") { - let input = getUInt64(0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromUInt64(0)_NeverFails") { - let input = getUInt64(0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromUInt64(32767)_NeverTraps") { - let input = getUInt64(32767) - let actual = Int16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromUInt64(32767)_NeverFails") { - let input = getUInt64(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromUInt64(32768)_AlwaysTraps") { - let input = getUInt64(32768) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } +FixedPointConversion_Release32_ToInt16 +.test("FromUInt64_NeverTraps") +.forEach(in: [ + (getInt16(+0), getUInt64(+0)), + (getInt16(+32767), getUInt64(+32767)), +]) { + expectEqual($0.0, Int16($0.1)) } -FixedPointConversion_Release32_ToInt16.test("FromUInt64(32768)_AlwaysFails") { - let input = getUInt64(32768) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt16 +.test("FromUInt64_NeverFails") +.forEach(in: [ + (getInt16(+0), getUInt64(+0)), + (getInt16(+32767), getUInt64(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) } -FixedPointConversion_Release32_ToInt16.test("FromUInt64(18446744073709551615)_AlwaysTraps") { - let input = getUInt64(18446744073709551615) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } +FixedPointConversion_Release32_ToInt16 +.test("FromUInt64_AlwaysTraps") +.forEach(in: [ + getUInt64(+32768), + getUInt64(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(Int16($0)) } -FixedPointConversion_Release32_ToInt16.test("FromUInt64(18446744073709551615)_AlwaysFails") { - let input = getUInt64(18446744073709551615) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt16 +.test("FromUInt64_AlwaysFails") +.forEach(in: [ + getUInt64(+32768), + getUInt64(+18446744073709551615), +]) { + expectNil(Int16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int64: (-9223372036854775808)...(9223372036854775807) +// MARK: Int64: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt16.test("FromInt64(-9223372036854775808)_AlwaysTraps") { - let input = getInt64(-9223372036854775808) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromInt64(-9223372036854775808)_AlwaysFails") { - let input = getInt64(-9223372036854775808) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromInt64(-32769)_AlwaysTraps") { - let input = getInt64(-32769) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromInt64(-32769)_AlwaysFails") { - let input = getInt64(-32769) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromInt64(-32768)_NeverTraps") { - let input = getInt64(-32768) - let actual = Int16(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromInt64(-32768)_NeverFails") { - let input = getInt64(-32768) - let actual = Int16(exactly: input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromInt64(0)_NeverTraps") { - let input = getInt64(0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromInt64(0)_NeverFails") { - let input = getInt64(0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromInt64(32767)_NeverTraps") { - let input = getInt64(32767) - let actual = Int16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromInt64(32767)_NeverFails") { - let input = getInt64(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromInt64(32768)_AlwaysTraps") { - let input = getInt64(32768) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromInt64(32768)_AlwaysFails") { - let input = getInt64(32768) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromInt64(9223372036854775807)_AlwaysTraps") { - let input = getInt64(9223372036854775807) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromInt64(9223372036854775807)_AlwaysFails") { - let input = getInt64(9223372036854775807) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt16 +.test("FromInt64_NeverTraps") +.forEach(in: [ + (getInt16(-32768), getInt64(-32768)), + (getInt16(+0), getInt64(+0)), + (getInt16(+32767), getInt64(+32767)), +]) { + expectEqual($0.0, Int16($0.1)) +} + +FixedPointConversion_Release32_ToInt16 +.test("FromInt64_NeverFails") +.forEach(in: [ + (getInt16(-32768), getInt64(-32768)), + (getInt16(+0), getInt64(+0)), + (getInt16(+32767), getInt64(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToInt16 +.test("FromInt64_AlwaysTraps") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-32769), + getInt64(+32768), + getInt64(+9223372036854775807), +]) { + expectCrashLater() + _blackHole(Int16($0)) +} + +FixedPointConversion_Release32_ToInt16 +.test("FromInt64_AlwaysFails") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-32769), + getInt64(+32768), + getInt64(+9223372036854775807), +]) { + expectNil(Int16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt: (0)...(4294967295) +// MARK: UInt: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt16.test("FromUInt(0)_NeverTraps") { - let input = getUInt(0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromUInt(0)_NeverFails") { - let input = getUInt(0) - let actual = Int16(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToInt16 +.test("FromUInt_NeverTraps") +.forEach(in: [ + (getInt16(+0), getUInt(+0)), + (getInt16(+32767), getUInt(+32767)), +]) { + expectEqual($0.0, Int16($0.1)) } -FixedPointConversion_Release32_ToInt16.test("FromUInt(32767)_NeverTraps") { - let input = getUInt(32767) - let actual = Int16(input) - expectEqual(32767, actual) +FixedPointConversion_Release32_ToInt16 +.test("FromUInt_NeverFails") +.forEach(in: [ + (getInt16(+0), getUInt(+0)), + (getInt16(+32767), getUInt(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) } -FixedPointConversion_Release32_ToInt16.test("FromUInt(32767)_NeverFails") { - let input = getUInt(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) +FixedPointConversion_Release32_ToInt16 +.test("FromUInt_AlwaysTraps") +.forEach(in: [ + getUInt(+32768), + getUInt(+4294967295), +]) { + expectCrashLater() + _blackHole(Int16($0)) } -FixedPointConversion_Release32_ToInt16.test("FromUInt(32768)_AlwaysTraps") { - let input = getUInt(32768) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromUInt(32768)_AlwaysFails") { - let input = getUInt(32768) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromUInt(4294967295)_AlwaysTraps") { - let input = getUInt(4294967295) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromUInt(4294967295)_AlwaysFails") { - let input = getUInt(4294967295) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt16 +.test("FromUInt_AlwaysFails") +.forEach(in: [ + getUInt(+32768), + getUInt(+4294967295), +]) { + expectNil(Int16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int: (-2147483648)...(2147483647) +// MARK: Int: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt16.test("FromInt(-2147483648)_AlwaysTraps") { - let input = getInt(-2147483648) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromInt(-2147483648)_AlwaysFails") { - let input = getInt(-2147483648) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromInt(-32769)_AlwaysTraps") { - let input = getInt(-32769) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromInt(-32769)_AlwaysFails") { - let input = getInt(-32769) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromInt(-32768)_NeverTraps") { - let input = getInt(-32768) - let actual = Int16(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromInt(-32768)_NeverFails") { - let input = getInt(-32768) - let actual = Int16(exactly: input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromInt(0)_NeverTraps") { - let input = getInt(0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromInt(0)_NeverFails") { - let input = getInt(0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromInt(32767)_NeverTraps") { - let input = getInt(32767) - let actual = Int16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromInt(32767)_NeverFails") { - let input = getInt(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromInt(32768)_AlwaysTraps") { - let input = getInt(32768) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromInt(32768)_AlwaysFails") { - let input = getInt(32768) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromInt(2147483647)_AlwaysTraps") { - let input = getInt(2147483647) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromInt(2147483647)_AlwaysFails") { - let input = getInt(2147483647) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt16 +.test("FromInt_NeverTraps") +.forEach(in: [ + (getInt16(-32768), getInt(-32768)), + (getInt16(+0), getInt(+0)), + (getInt16(+32767), getInt(+32767)), +]) { + expectEqual($0.0, Int16($0.1)) +} + +FixedPointConversion_Release32_ToInt16 +.test("FromInt_NeverFails") +.forEach(in: [ + (getInt16(-32768), getInt(-32768)), + (getInt16(+0), getInt(+0)), + (getInt16(+32767), getInt(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToInt16 +.test("FromInt_AlwaysTraps") +.forEach(in: [ + getInt(-2147483648), + getInt(-32769), + getInt(+32768), + getInt(+2147483647), +]) { + expectCrashLater() + _blackHole(Int16($0)) +} + +FixedPointConversion_Release32_ToInt16 +.test("FromInt_AlwaysFails") +.forEach(in: [ + getInt(-2147483648), + getInt(-32769), + getInt(+32768), + getInt(+2147483647), +]) { + expectNil(Int16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float16: (-2047)...(2047) +// MARK: Float16: (-2047)...(+2047) //===----------------------------------------------------------------------===// #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -FixedPointConversion_Release32_ToInt16.test("FromFloat16(-2047)_NeverTraps") { - let input = getFloat16(-2047) - let actual = Int16(input) - expectEqual(-2047, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat16(-2047)_NeverFails") { - let input = getFloat16(-2047) - let actual = Int16(exactly: input) - expectEqual(-2047, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat16(-128.5)_NeverTraps") { - let input = getFloat16(-128.5) - let actual = Int16(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat16(-128.5)_AlwaysFails") { - let input = getFloat16(-128.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat16(-0.5)_NeverTraps") { - let input = getFloat16(-0.5) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat16(-0.5)_AlwaysFails") { - let input = getFloat16(-0.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat16(-0.0)_NeverTraps") { - let input = getFloat16(-0.0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat16(-0.0)_NeverFails") { - let input = getFloat16(-0.0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat16(0.0)_NeverTraps") { - let input = getFloat16(0.0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat16(0.0)_NeverFails") { - let input = getFloat16(0.0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat16(0.5)_NeverTraps") { - let input = getFloat16(0.5) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat16(0.5)_AlwaysFails") { - let input = getFloat16(0.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat16(127.5)_NeverTraps") { - let input = getFloat16(127.5) - let actual = Int16(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat16(127.5)_AlwaysFails") { - let input = getFloat16(127.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat16(255.5)_NeverTraps") { - let input = getFloat16(255.5) - let actual = Int16(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat16(255.5)_AlwaysFails") { - let input = getFloat16(255.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat16(2047)_NeverTraps") { - let input = getFloat16(2047) - let actual = Int16(input) - expectEqual(2047, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat16(2047)_NeverFails") { - let input = getFloat16(2047) - let actual = Int16(exactly: input) - expectEqual(2047, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat16(-.infinity)_AlwaysTraps") { - let input = getFloat16(-.infinity) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat16(-.infinity)_AlwaysFails") { - let input = getFloat16(-.infinity) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat16(+.infinity)_AlwaysTraps") { - let input = getFloat16(+.infinity) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat16(+.infinity)_AlwaysFails") { - let input = getFloat16(+.infinity) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat16(-.nan)_AlwaysTraps") { - let input = getFloat16(-.nan) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat16(-.nan)_AlwaysFails") { - let input = getFloat16(-.nan) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat16(+.nan)_AlwaysTraps") { - let input = getFloat16(+.nan) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat16(+.nan)_AlwaysFails") { - let input = getFloat16(+.nan) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat16(-.signalingNaN)_AlwaysTraps") { - let input = getFloat16(-.signalingNaN) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat16(-.signalingNaN)_AlwaysFails") { - let input = getFloat16(-.signalingNaN) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat16(+.signalingNaN)_AlwaysTraps") { - let input = getFloat16(+.signalingNaN) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat16(+.signalingNaN)_AlwaysFails") { - let input = getFloat16(+.signalingNaN) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt16 +.test("FromFloat16_NeverTraps") +.forEach(in: [ + (getInt16(-2047), getFloat16(-2047)), + (getInt16(-128), getFloat16(-128.5)), + (getInt16(+0), getFloat16(-0.5)), + (getInt16(+0), getFloat16(+0)), + (getInt16(+0), getFloat16(-0)), + (getInt16(+0), getFloat16(+0.5)), + (getInt16(+127), getFloat16(+127.5)), + (getInt16(+255), getFloat16(+255.5)), + (getInt16(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, Int16($0.1)) +} + +FixedPointConversion_Release32_ToInt16 +.test("FromFloat16_NeverFails") +.forEach(in: [ + (getInt16(-2047), getFloat16(-2047)), + (getInt16(+0), getFloat16(+0)), + (getInt16(+0), getFloat16(-0)), + (getInt16(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToInt16 +.test("FromFloat16_AlwaysTraps") +.forEach(in: [ + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int16($0)) +} + +FixedPointConversion_Release32_ToInt16 +.test("FromFloat16_AlwaysFails") +.forEach(in: [ + getFloat16(-128.5), + getFloat16(-0.5), + getFloat16(+0.5), + getFloat16(+127.5), + getFloat16(+255.5), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectNil(Int16(exactly: $0)) } } #endif // Float16 //===----------------------------------------------------------------------===// -// MARK: Float32: (-16777215)...(16777215) +// MARK: Float32: (-16777215)...(+16777215) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt16.test("FromFloat32(-16777215)_AlwaysTraps") { - let input = getFloat32(-16777215) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(-16777215)_AlwaysFails") { - let input = getFloat32(-16777215) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(-32769)_AlwaysTraps") { - let input = getFloat32(-32769) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(-32769)_AlwaysFails") { - let input = getFloat32(-32769) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(-32768.5)_NeverTraps") { - let input = getFloat32(-32768.5) - let actual = Int16(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(-32768.5)_AlwaysFails") { - let input = getFloat32(-32768.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(-32768)_NeverTraps") { - let input = getFloat32(-32768) - let actual = Int16(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(-32768)_NeverFails") { - let input = getFloat32(-32768) - let actual = Int16(exactly: input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(-128.5)_NeverTraps") { - let input = getFloat32(-128.5) - let actual = Int16(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(-128.5)_AlwaysFails") { - let input = getFloat32(-128.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(-0.5)_NeverTraps") { - let input = getFloat32(-0.5) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(-0.5)_AlwaysFails") { - let input = getFloat32(-0.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(-0.0)_NeverTraps") { - let input = getFloat32(-0.0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(-0.0)_NeverFails") { - let input = getFloat32(-0.0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(0.0)_NeverTraps") { - let input = getFloat32(0.0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(0.0)_NeverFails") { - let input = getFloat32(0.0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(0.5)_NeverTraps") { - let input = getFloat32(0.5) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(0.5)_AlwaysFails") { - let input = getFloat32(0.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(127.5)_NeverTraps") { - let input = getFloat32(127.5) - let actual = Int16(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(127.5)_AlwaysFails") { - let input = getFloat32(127.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(255.5)_NeverTraps") { - let input = getFloat32(255.5) - let actual = Int16(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(255.5)_AlwaysFails") { - let input = getFloat32(255.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(32767)_NeverTraps") { - let input = getFloat32(32767) - let actual = Int16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(32767)_NeverFails") { - let input = getFloat32(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(32767.5)_NeverTraps") { - let input = getFloat32(32767.5) - let actual = Int16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(32767.5)_AlwaysFails") { - let input = getFloat32(32767.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(32768)_AlwaysTraps") { - let input = getFloat32(32768) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(32768)_AlwaysFails") { - let input = getFloat32(32768) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(65535.5)_AlwaysTraps") { - let input = getFloat32(65535.5) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(65535.5)_AlwaysFails") { - let input = getFloat32(65535.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(16777215)_AlwaysTraps") { - let input = getFloat32(16777215) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(16777215)_AlwaysFails") { - let input = getFloat32(16777215) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(-.infinity)_AlwaysTraps") { - let input = getFloat32(-.infinity) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(-.infinity)_AlwaysFails") { - let input = getFloat32(-.infinity) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(+.infinity)_AlwaysTraps") { - let input = getFloat32(+.infinity) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(+.infinity)_AlwaysFails") { - let input = getFloat32(+.infinity) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(-.nan)_AlwaysTraps") { - let input = getFloat32(-.nan) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(-.nan)_AlwaysFails") { - let input = getFloat32(-.nan) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(+.nan)_AlwaysTraps") { - let input = getFloat32(+.nan) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(+.nan)_AlwaysFails") { - let input = getFloat32(+.nan) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(-.signalingNaN)_AlwaysTraps") { - let input = getFloat32(-.signalingNaN) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(-.signalingNaN)_AlwaysFails") { - let input = getFloat32(-.signalingNaN) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(+.signalingNaN)_AlwaysTraps") { - let input = getFloat32(+.signalingNaN) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat32(+.signalingNaN)_AlwaysFails") { - let input = getFloat32(+.signalingNaN) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt16 +.test("FromFloat32_NeverTraps") +.forEach(in: [ + (getInt16(-32768), getFloat32(-32768.5)), + (getInt16(-32768), getFloat32(-32768)), + (getInt16(-128), getFloat32(-128.5)), + (getInt16(+0), getFloat32(-0.5)), + (getInt16(+0), getFloat32(+0)), + (getInt16(+0), getFloat32(-0)), + (getInt16(+0), getFloat32(+0.5)), + (getInt16(+127), getFloat32(+127.5)), + (getInt16(+255), getFloat32(+255.5)), + (getInt16(+32767), getFloat32(+32767)), + (getInt16(+32767), getFloat32(+32767.5)), +]) { + expectEqual($0.0, Int16($0.1)) +} + +FixedPointConversion_Release32_ToInt16 +.test("FromFloat32_NeverFails") +.forEach(in: [ + (getInt16(-32768), getFloat32(-32768)), + (getInt16(+0), getFloat32(+0)), + (getInt16(+0), getFloat32(-0)), + (getInt16(+32767), getFloat32(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToInt16 +.test("FromFloat32_AlwaysTraps") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32769), + getFloat32(+32768), + getFloat32(+65535.5), + getFloat32(+16777215), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int16($0)) +} + +FixedPointConversion_Release32_ToInt16 +.test("FromFloat32_AlwaysFails") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32769), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-0.5), + getFloat32(+0.5), + getFloat32(+127.5), + getFloat32(+255.5), + getFloat32(+32767.5), + getFloat32(+32768), + getFloat32(+65535.5), + getFloat32(+16777215), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectNil(Int16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float64: (-9007199254740991)...(9007199254740991) +// MARK: Float64: (-9007199254740991)...(+9007199254740991) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt16.test("FromFloat64(-9007199254740991)_AlwaysTraps") { - let input = getFloat64(-9007199254740991) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(-9007199254740991)_AlwaysFails") { - let input = getFloat64(-9007199254740991) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(-32769)_AlwaysTraps") { - let input = getFloat64(-32769) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(-32769)_AlwaysFails") { - let input = getFloat64(-32769) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(-32768.5)_NeverTraps") { - let input = getFloat64(-32768.5) - let actual = Int16(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(-32768.5)_AlwaysFails") { - let input = getFloat64(-32768.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(-32768)_NeverTraps") { - let input = getFloat64(-32768) - let actual = Int16(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(-32768)_NeverFails") { - let input = getFloat64(-32768) - let actual = Int16(exactly: input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(-128.5)_NeverTraps") { - let input = getFloat64(-128.5) - let actual = Int16(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(-128.5)_AlwaysFails") { - let input = getFloat64(-128.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(-0.5)_NeverTraps") { - let input = getFloat64(-0.5) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(-0.5)_AlwaysFails") { - let input = getFloat64(-0.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(-0.0)_NeverTraps") { - let input = getFloat64(-0.0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(-0.0)_NeverFails") { - let input = getFloat64(-0.0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(0.0)_NeverTraps") { - let input = getFloat64(0.0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(0.0)_NeverFails") { - let input = getFloat64(0.0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(0.5)_NeverTraps") { - let input = getFloat64(0.5) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(0.5)_AlwaysFails") { - let input = getFloat64(0.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(127.5)_NeverTraps") { - let input = getFloat64(127.5) - let actual = Int16(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(127.5)_AlwaysFails") { - let input = getFloat64(127.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(255.5)_NeverTraps") { - let input = getFloat64(255.5) - let actual = Int16(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(255.5)_AlwaysFails") { - let input = getFloat64(255.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(32767)_NeverTraps") { - let input = getFloat64(32767) - let actual = Int16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(32767)_NeverFails") { - let input = getFloat64(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(32767.5)_NeverTraps") { - let input = getFloat64(32767.5) - let actual = Int16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(32767.5)_AlwaysFails") { - let input = getFloat64(32767.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(32768)_AlwaysTraps") { - let input = getFloat64(32768) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(32768)_AlwaysFails") { - let input = getFloat64(32768) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(65535.5)_AlwaysTraps") { - let input = getFloat64(65535.5) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(65535.5)_AlwaysFails") { - let input = getFloat64(65535.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(9007199254740991)_AlwaysTraps") { - let input = getFloat64(9007199254740991) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(9007199254740991)_AlwaysFails") { - let input = getFloat64(9007199254740991) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(-.infinity)_AlwaysTraps") { - let input = getFloat64(-.infinity) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(-.infinity)_AlwaysFails") { - let input = getFloat64(-.infinity) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(+.infinity)_AlwaysTraps") { - let input = getFloat64(+.infinity) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(+.infinity)_AlwaysFails") { - let input = getFloat64(+.infinity) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(-.nan)_AlwaysTraps") { - let input = getFloat64(-.nan) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(-.nan)_AlwaysFails") { - let input = getFloat64(-.nan) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(+.nan)_AlwaysTraps") { - let input = getFloat64(+.nan) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(+.nan)_AlwaysFails") { - let input = getFloat64(+.nan) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(-.signalingNaN)_AlwaysTraps") { - let input = getFloat64(-.signalingNaN) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(-.signalingNaN)_AlwaysFails") { - let input = getFloat64(-.signalingNaN) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(+.signalingNaN)_AlwaysTraps") { - let input = getFloat64(+.signalingNaN) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat64(+.signalingNaN)_AlwaysFails") { - let input = getFloat64(+.signalingNaN) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt16 +.test("FromFloat64_NeverTraps") +.forEach(in: [ + (getInt16(-32768), getFloat64(-32768.5)), + (getInt16(-32768), getFloat64(-32768)), + (getInt16(-128), getFloat64(-128.5)), + (getInt16(+0), getFloat64(-0.5)), + (getInt16(+0), getFloat64(+0)), + (getInt16(+0), getFloat64(-0)), + (getInt16(+0), getFloat64(+0.5)), + (getInt16(+127), getFloat64(+127.5)), + (getInt16(+255), getFloat64(+255.5)), + (getInt16(+32767), getFloat64(+32767)), + (getInt16(+32767), getFloat64(+32767.5)), +]) { + expectEqual($0.0, Int16($0.1)) +} + +FixedPointConversion_Release32_ToInt16 +.test("FromFloat64_NeverFails") +.forEach(in: [ + (getInt16(-32768), getFloat64(-32768)), + (getInt16(+0), getFloat64(+0)), + (getInt16(+0), getFloat64(-0)), + (getInt16(+32767), getFloat64(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToInt16 +.test("FromFloat64_AlwaysTraps") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32769), + getFloat64(+32768), + getFloat64(+65535.5), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int16($0)) +} + +FixedPointConversion_Release32_ToInt16 +.test("FromFloat64_AlwaysFails") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32769), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-0.5), + getFloat64(+0.5), + getFloat64(+127.5), + getFloat64(+255.5), + getFloat64(+32767.5), + getFloat64(+32768), + getFloat64(+65535.5), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectNil(Int16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float80: (-18446744073709551615)...(18446744073709551615) +// MARK: Float80: (-18446744073709551615)...(+18446744073709551615) //===----------------------------------------------------------------------===// #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) -FixedPointConversion_Release32_ToInt16.test("FromFloat80(-18446744073709551615)_AlwaysTraps") { - let input = getFloat80(-18446744073709551615) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(-18446744073709551615)_AlwaysFails") { - let input = getFloat80(-18446744073709551615) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(-32769)_AlwaysTraps") { - let input = getFloat80(-32769) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(-32769)_AlwaysFails") { - let input = getFloat80(-32769) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(-32768.5)_NeverTraps") { - let input = getFloat80(-32768.5) - let actual = Int16(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(-32768.5)_AlwaysFails") { - let input = getFloat80(-32768.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(-32768)_NeverTraps") { - let input = getFloat80(-32768) - let actual = Int16(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(-32768)_NeverFails") { - let input = getFloat80(-32768) - let actual = Int16(exactly: input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(-128.5)_NeverTraps") { - let input = getFloat80(-128.5) - let actual = Int16(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(-128.5)_AlwaysFails") { - let input = getFloat80(-128.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(-0.5)_NeverTraps") { - let input = getFloat80(-0.5) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(-0.5)_AlwaysFails") { - let input = getFloat80(-0.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(-0.0)_NeverTraps") { - let input = getFloat80(-0.0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(-0.0)_NeverFails") { - let input = getFloat80(-0.0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(0.0)_NeverTraps") { - let input = getFloat80(0.0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(0.0)_NeverFails") { - let input = getFloat80(0.0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(0.5)_NeverTraps") { - let input = getFloat80(0.5) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(0.5)_AlwaysFails") { - let input = getFloat80(0.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(127.5)_NeverTraps") { - let input = getFloat80(127.5) - let actual = Int16(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(127.5)_AlwaysFails") { - let input = getFloat80(127.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(255.5)_NeverTraps") { - let input = getFloat80(255.5) - let actual = Int16(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(255.5)_AlwaysFails") { - let input = getFloat80(255.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(32767)_NeverTraps") { - let input = getFloat80(32767) - let actual = Int16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(32767)_NeverFails") { - let input = getFloat80(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(32767.5)_NeverTraps") { - let input = getFloat80(32767.5) - let actual = Int16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(32767.5)_AlwaysFails") { - let input = getFloat80(32767.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(32768)_AlwaysTraps") { - let input = getFloat80(32768) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(32768)_AlwaysFails") { - let input = getFloat80(32768) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(65535.5)_AlwaysTraps") { - let input = getFloat80(65535.5) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(65535.5)_AlwaysFails") { - let input = getFloat80(65535.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(18446744073709551615)_AlwaysTraps") { - let input = getFloat80(18446744073709551615) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(18446744073709551615)_AlwaysFails") { - let input = getFloat80(18446744073709551615) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(-.infinity)_AlwaysTraps") { - let input = getFloat80(-.infinity) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(-.infinity)_AlwaysFails") { - let input = getFloat80(-.infinity) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(+.infinity)_AlwaysTraps") { - let input = getFloat80(+.infinity) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(+.infinity)_AlwaysFails") { - let input = getFloat80(+.infinity) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(-.nan)_AlwaysTraps") { - let input = getFloat80(-.nan) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(-.nan)_AlwaysFails") { - let input = getFloat80(-.nan) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(+.nan)_AlwaysTraps") { - let input = getFloat80(+.nan) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(+.nan)_AlwaysFails") { - let input = getFloat80(+.nan) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(-.signalingNaN)_AlwaysTraps") { - let input = getFloat80(-.signalingNaN) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(-.signalingNaN)_AlwaysFails") { - let input = getFloat80(-.signalingNaN) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(+.signalingNaN)_AlwaysTraps") { - let input = getFloat80(+.signalingNaN) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt16.test("FromFloat80(+.signalingNaN)_AlwaysFails") { - let input = getFloat80(+.signalingNaN) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt16 +.test("FromFloat80_NeverTraps") +.forEach(in: [ + (getInt16(-32768), getFloat80(-32768.5)), + (getInt16(-32768), getFloat80(-32768)), + (getInt16(-128), getFloat80(-128.5)), + (getInt16(+0), getFloat80(-0.5)), + (getInt16(+0), getFloat80(+0)), + (getInt16(+0), getFloat80(-0)), + (getInt16(+0), getFloat80(+0.5)), + (getInt16(+127), getFloat80(+127.5)), + (getInt16(+255), getFloat80(+255.5)), + (getInt16(+32767), getFloat80(+32767)), + (getInt16(+32767), getFloat80(+32767.5)), +]) { + expectEqual($0.0, Int16($0.1)) +} + +FixedPointConversion_Release32_ToInt16 +.test("FromFloat80_NeverFails") +.forEach(in: [ + (getInt16(-32768), getFloat80(-32768)), + (getInt16(+0), getFloat80(+0)), + (getInt16(+0), getFloat80(-0)), + (getInt16(+32767), getFloat80(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToInt16 +.test("FromFloat80_AlwaysTraps") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32769), + getFloat80(+32768), + getFloat80(+65535.5), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int16($0)) +} + +FixedPointConversion_Release32_ToInt16 +.test("FromFloat80_AlwaysFails") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32769), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-0.5), + getFloat80(+0.5), + getFloat80(+127.5), + getFloat80(+255.5), + getFloat80(+32767.5), + getFloat80(+32768), + getFloat80(+65535.5), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectNil(Int16(exactly: $0)) } #endif // Float80 diff --git a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release32_ToInt32.swift b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release32_ToInt32.swift index b568a7d6faedc..57ee41341eeaf 100644 --- a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release32_ToInt32.swift +++ b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release32_ToInt32.swift @@ -5,7 +5,7 @@ // //===----------------------------------------------------------------------===// // -// REQUIRES: executable_test, long_test +// REQUIRES: executable_test // REQUIRES: PTRSIZE=32 // RUN: %target-run-simple-swift(-O) // END. @@ -14,1498 +14,612 @@ import StdlibUnittest -let FixedPointConversion_Release32_ToInt32 = TestSuite("FixedPointConversion_Release32_ToInt32") +let FixedPointConversion_Release32_ToInt32 = TestSuite( + "FixedPointConversion_Release32_ToInt32" +) //===----------------------------------------------------------------------===// -// MARK: UInt8: (0)...(255) +// MARK: UInt8: (+0)...(+255) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt32.test("FromUInt8(0)_NeverTraps") { - let input = getUInt8(0) - let actual = Int32(input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToInt32 +.test("FromUInt8_NeverTraps") +.forEach(in: [ + (getInt32(+0), getUInt8(+0)), + (getInt32(+255), getUInt8(+255)), +]) { + expectEqual($0.0, Int32($0.1)) } -FixedPointConversion_Release32_ToInt32.test("FromUInt8(0)_NeverFails") { - let input = getUInt8(0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromUInt8(255)_NeverTraps") { - let input = getUInt8(255) - let actual = Int32(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromUInt8(255)_NeverFails") { - let input = getUInt8(255) - let actual = Int32(exactly: input) - expectEqual(255, actual) +FixedPointConversion_Release32_ToInt32 +.test("FromUInt8_NeverFails") +.forEach(in: [ + (getInt32(+0), getUInt8(+0)), + (getInt32(+255), getUInt8(+255)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int8: (-128)...(127) +// MARK: Int8: (-128)...(+127) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt32.test("FromInt8(-128)_NeverTraps") { - let input = getInt8(-128) - let actual = Int32(input) - expectEqual(-128, actual) +FixedPointConversion_Release32_ToInt32 +.test("FromInt8_NeverTraps") +.forEach(in: [ + (getInt32(-128), getInt8(-128)), + (getInt32(+0), getInt8(+0)), + (getInt32(+127), getInt8(+127)), +]) { + expectEqual($0.0, Int32($0.1)) } -FixedPointConversion_Release32_ToInt32.test("FromInt8(-128)_NeverFails") { - let input = getInt8(-128) - let actual = Int32(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromInt8(0)_NeverTraps") { - let input = getInt8(0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromInt8(0)_NeverFails") { - let input = getInt8(0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromInt8(127)_NeverTraps") { - let input = getInt8(127) - let actual = Int32(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromInt8(127)_NeverFails") { - let input = getInt8(127) - let actual = Int32(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Release32_ToInt32 +.test("FromInt8_NeverFails") +.forEach(in: [ + (getInt32(-128), getInt8(-128)), + (getInt32(+0), getInt8(+0)), + (getInt32(+127), getInt8(+127)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt16: (0)...(65535) +// MARK: UInt16: (+0)...(+65535) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt32.test("FromUInt16(0)_NeverTraps") { - let input = getUInt16(0) - let actual = Int32(input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToInt32 +.test("FromUInt16_NeverTraps") +.forEach(in: [ + (getInt32(+0), getUInt16(+0)), + (getInt32(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, Int32($0.1)) } -FixedPointConversion_Release32_ToInt32.test("FromUInt16(0)_NeverFails") { - let input = getUInt16(0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromUInt16(65535)_NeverTraps") { - let input = getUInt16(65535) - let actual = Int32(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromUInt16(65535)_NeverFails") { - let input = getUInt16(65535) - let actual = Int32(exactly: input) - expectEqual(65535, actual) +FixedPointConversion_Release32_ToInt32 +.test("FromUInt16_NeverFails") +.forEach(in: [ + (getInt32(+0), getUInt16(+0)), + (getInt32(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int16: (-32768)...(32767) +// MARK: Int16: (-32768)...(+32767) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt32.test("FromInt16(-32768)_NeverTraps") { - let input = getInt16(-32768) - let actual = Int32(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromInt16(-32768)_NeverFails") { - let input = getInt16(-32768) - let actual = Int32(exactly: input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromInt16(0)_NeverTraps") { - let input = getInt16(0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromInt16(0)_NeverFails") { - let input = getInt16(0) - let actual = Int32(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToInt32 +.test("FromInt16_NeverTraps") +.forEach(in: [ + (getInt32(-32768), getInt16(-32768)), + (getInt32(+0), getInt16(+0)), + (getInt32(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, Int32($0.1)) } -FixedPointConversion_Release32_ToInt32.test("FromInt16(32767)_NeverTraps") { - let input = getInt16(32767) - let actual = Int32(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromInt16(32767)_NeverFails") { - let input = getInt16(32767) - let actual = Int32(exactly: input) - expectEqual(32767, actual) +FixedPointConversion_Release32_ToInt32 +.test("FromInt16_NeverFails") +.forEach(in: [ + (getInt32(-32768), getInt16(-32768)), + (getInt32(+0), getInt16(+0)), + (getInt32(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt32: (0)...(4294967295) +// MARK: UInt32: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt32.test("FromUInt32(0)_NeverTraps") { - let input = getUInt32(0) - let actual = Int32(input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToInt32 +.test("FromUInt32_NeverTraps") +.forEach(in: [ + (getInt32(+0), getUInt32(+0)), + (getInt32(+2147483647), getUInt32(+2147483647)), +]) { + expectEqual($0.0, Int32($0.1)) } -FixedPointConversion_Release32_ToInt32.test("FromUInt32(0)_NeverFails") { - let input = getUInt32(0) - let actual = Int32(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToInt32 +.test("FromUInt32_NeverFails") +.forEach(in: [ + (getInt32(+0), getUInt32(+0)), + (getInt32(+2147483647), getUInt32(+2147483647)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) } -FixedPointConversion_Release32_ToInt32.test("FromUInt32(2147483647)_NeverTraps") { - let input = getUInt32(2147483647) - let actual = Int32(input) - expectEqual(2147483647, actual) +FixedPointConversion_Release32_ToInt32 +.test("FromUInt32_AlwaysTraps") +.forEach(in: [ + getUInt32(+2147483648), + getUInt32(+4294967295), +]) { + expectCrashLater() + _blackHole(Int32($0)) } -FixedPointConversion_Release32_ToInt32.test("FromUInt32(2147483647)_NeverFails") { - let input = getUInt32(2147483647) - let actual = Int32(exactly: input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromUInt32(2147483648)_AlwaysTraps") { - let input = getUInt32(2147483648) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromUInt32(2147483648)_AlwaysFails") { - let input = getUInt32(2147483648) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromUInt32(4294967295)_AlwaysTraps") { - let input = getUInt32(4294967295) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromUInt32(4294967295)_AlwaysFails") { - let input = getUInt32(4294967295) - let actual = Int32(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt32 +.test("FromUInt32_AlwaysFails") +.forEach(in: [ + getUInt32(+2147483648), + getUInt32(+4294967295), +]) { + expectNil(Int32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int32: (-2147483648)...(2147483647) +// MARK: Int32: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt32.test("FromInt32(-2147483648)_NeverTraps") { - let input = getInt32(-2147483648) - let actual = Int32(input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromInt32(-2147483648)_NeverFails") { - let input = getInt32(-2147483648) - let actual = Int32(exactly: input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromInt32(0)_NeverTraps") { - let input = getInt32(0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromInt32(0)_NeverFails") { - let input = getInt32(0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromInt32(2147483647)_NeverTraps") { - let input = getInt32(2147483647) - let actual = Int32(input) - expectEqual(2147483647, actual) +FixedPointConversion_Release32_ToInt32 +.test("FromInt32_NeverTraps") +.forEach(in: [ + (getInt32(-2147483648), getInt32(-2147483648)), + (getInt32(+0), getInt32(+0)), + (getInt32(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, Int32($0.1)) } -FixedPointConversion_Release32_ToInt32.test("FromInt32(2147483647)_NeverFails") { - let input = getInt32(2147483647) - let actual = Int32(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Release32_ToInt32 +.test("FromInt32_NeverFails") +.forEach(in: [ + (getInt32(-2147483648), getInt32(-2147483648)), + (getInt32(+0), getInt32(+0)), + (getInt32(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt64: (0)...(18446744073709551615) +// MARK: UInt64: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt32.test("FromUInt64(0)_NeverTraps") { - let input = getUInt64(0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromUInt64(0)_NeverFails") { - let input = getUInt64(0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromUInt64(2147483647)_NeverTraps") { - let input = getUInt64(2147483647) - let actual = Int32(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromUInt64(2147483647)_NeverFails") { - let input = getUInt64(2147483647) - let actual = Int32(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Release32_ToInt32 +.test("FromUInt64_NeverTraps") +.forEach(in: [ + (getInt32(+0), getUInt64(+0)), + (getInt32(+2147483647), getUInt64(+2147483647)), +]) { + expectEqual($0.0, Int32($0.1)) } -FixedPointConversion_Release32_ToInt32.test("FromUInt64(2147483648)_AlwaysTraps") { - let input = getUInt64(2147483648) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } +FixedPointConversion_Release32_ToInt32 +.test("FromUInt64_NeverFails") +.forEach(in: [ + (getInt32(+0), getUInt64(+0)), + (getInt32(+2147483647), getUInt64(+2147483647)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) } -FixedPointConversion_Release32_ToInt32.test("FromUInt64(2147483648)_AlwaysFails") { - let input = getUInt64(2147483648) - let actual = Int32(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt32 +.test("FromUInt64_AlwaysTraps") +.forEach(in: [ + getUInt64(+2147483648), + getUInt64(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(Int32($0)) } -FixedPointConversion_Release32_ToInt32.test("FromUInt64(18446744073709551615)_AlwaysTraps") { - let input = getUInt64(18446744073709551615) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromUInt64(18446744073709551615)_AlwaysFails") { - let input = getUInt64(18446744073709551615) - let actual = Int32(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt32 +.test("FromUInt64_AlwaysFails") +.forEach(in: [ + getUInt64(+2147483648), + getUInt64(+18446744073709551615), +]) { + expectNil(Int32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int64: (-9223372036854775808)...(9223372036854775807) +// MARK: Int64: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt32.test("FromInt64(-9223372036854775808)_AlwaysTraps") { - let input = getInt64(-9223372036854775808) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromInt64(-9223372036854775808)_AlwaysFails") { - let input = getInt64(-9223372036854775808) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromInt64(-2147483649)_AlwaysTraps") { - let input = getInt64(-2147483649) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromInt64(-2147483649)_AlwaysFails") { - let input = getInt64(-2147483649) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromInt64(-2147483648)_NeverTraps") { - let input = getInt64(-2147483648) - let actual = Int32(input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromInt64(-2147483648)_NeverFails") { - let input = getInt64(-2147483648) - let actual = Int32(exactly: input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromInt64(0)_NeverTraps") { - let input = getInt64(0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromInt64(0)_NeverFails") { - let input = getInt64(0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromInt64(2147483647)_NeverTraps") { - let input = getInt64(2147483647) - let actual = Int32(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromInt64(2147483647)_NeverFails") { - let input = getInt64(2147483647) - let actual = Int32(exactly: input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromInt64(2147483648)_AlwaysTraps") { - let input = getInt64(2147483648) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromInt64(2147483648)_AlwaysFails") { - let input = getInt64(2147483648) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromInt64(9223372036854775807)_AlwaysTraps") { - let input = getInt64(9223372036854775807) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromInt64(9223372036854775807)_AlwaysFails") { - let input = getInt64(9223372036854775807) - let actual = Int32(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt32 +.test("FromInt64_NeverTraps") +.forEach(in: [ + (getInt32(-2147483648), getInt64(-2147483648)), + (getInt32(+0), getInt64(+0)), + (getInt32(+2147483647), getInt64(+2147483647)), +]) { + expectEqual($0.0, Int32($0.1)) +} + +FixedPointConversion_Release32_ToInt32 +.test("FromInt64_NeverFails") +.forEach(in: [ + (getInt32(-2147483648), getInt64(-2147483648)), + (getInt32(+0), getInt64(+0)), + (getInt32(+2147483647), getInt64(+2147483647)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToInt32 +.test("FromInt64_AlwaysTraps") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-2147483649), + getInt64(+2147483648), + getInt64(+9223372036854775807), +]) { + expectCrashLater() + _blackHole(Int32($0)) +} + +FixedPointConversion_Release32_ToInt32 +.test("FromInt64_AlwaysFails") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-2147483649), + getInt64(+2147483648), + getInt64(+9223372036854775807), +]) { + expectNil(Int32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt: (0)...(4294967295) +// MARK: UInt: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt32.test("FromUInt(0)_NeverTraps") { - let input = getUInt(0) - let actual = Int32(input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToInt32 +.test("FromUInt_NeverTraps") +.forEach(in: [ + (getInt32(+0), getUInt(+0)), + (getInt32(+2147483647), getUInt(+2147483647)), +]) { + expectEqual($0.0, Int32($0.1)) } -FixedPointConversion_Release32_ToInt32.test("FromUInt(0)_NeverFails") { - let input = getUInt(0) - let actual = Int32(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToInt32 +.test("FromUInt_NeverFails") +.forEach(in: [ + (getInt32(+0), getUInt(+0)), + (getInt32(+2147483647), getUInt(+2147483647)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) } -FixedPointConversion_Release32_ToInt32.test("FromUInt(2147483647)_NeverTraps") { - let input = getUInt(2147483647) - let actual = Int32(input) - expectEqual(2147483647, actual) +FixedPointConversion_Release32_ToInt32 +.test("FromUInt_AlwaysTraps") +.forEach(in: [ + getUInt(+2147483648), + getUInt(+4294967295), +]) { + expectCrashLater() + _blackHole(Int32($0)) } -FixedPointConversion_Release32_ToInt32.test("FromUInt(2147483647)_NeverFails") { - let input = getUInt(2147483647) - let actual = Int32(exactly: input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromUInt(2147483648)_AlwaysTraps") { - let input = getUInt(2147483648) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromUInt(2147483648)_AlwaysFails") { - let input = getUInt(2147483648) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromUInt(4294967295)_AlwaysTraps") { - let input = getUInt(4294967295) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromUInt(4294967295)_AlwaysFails") { - let input = getUInt(4294967295) - let actual = Int32(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt32 +.test("FromUInt_AlwaysFails") +.forEach(in: [ + getUInt(+2147483648), + getUInt(+4294967295), +]) { + expectNil(Int32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int: (-2147483648)...(2147483647) +// MARK: Int: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt32.test("FromInt(-2147483648)_NeverTraps") { - let input = getInt(-2147483648) - let actual = Int32(input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromInt(-2147483648)_NeverFails") { - let input = getInt(-2147483648) - let actual = Int32(exactly: input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromInt(0)_NeverTraps") { - let input = getInt(0) - let actual = Int32(input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToInt32 +.test("FromInt_NeverTraps") +.forEach(in: [ + (getInt32(-2147483648), getInt(-2147483648)), + (getInt32(+0), getInt(+0)), + (getInt32(+2147483647), getInt(+2147483647)), +]) { + expectEqual($0.0, Int32($0.1)) } -FixedPointConversion_Release32_ToInt32.test("FromInt(0)_NeverFails") { - let input = getInt(0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromInt(2147483647)_NeverTraps") { - let input = getInt(2147483647) - let actual = Int32(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromInt(2147483647)_NeverFails") { - let input = getInt(2147483647) - let actual = Int32(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Release32_ToInt32 +.test("FromInt_NeverFails") +.forEach(in: [ + (getInt32(-2147483648), getInt(-2147483648)), + (getInt32(+0), getInt(+0)), + (getInt32(+2147483647), getInt(+2147483647)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Float16: (-2047)...(2047) +// MARK: Float16: (-2047)...(+2047) //===----------------------------------------------------------------------===// #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -FixedPointConversion_Release32_ToInt32.test("FromFloat16(-2047)_NeverTraps") { - let input = getFloat16(-2047) - let actual = Int32(input) - expectEqual(-2047, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat16(-2047)_NeverFails") { - let input = getFloat16(-2047) - let actual = Int32(exactly: input) - expectEqual(-2047, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat16(-128.5)_NeverTraps") { - let input = getFloat16(-128.5) - let actual = Int32(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat16(-128.5)_AlwaysFails") { - let input = getFloat16(-128.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat16(-0.5)_NeverTraps") { - let input = getFloat16(-0.5) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat16(-0.5)_AlwaysFails") { - let input = getFloat16(-0.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat16(-0.0)_NeverTraps") { - let input = getFloat16(-0.0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat16(-0.0)_NeverFails") { - let input = getFloat16(-0.0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat16(0.0)_NeverTraps") { - let input = getFloat16(0.0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat16(0.0)_NeverFails") { - let input = getFloat16(0.0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat16(0.5)_NeverTraps") { - let input = getFloat16(0.5) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat16(0.5)_AlwaysFails") { - let input = getFloat16(0.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat16(127.5)_NeverTraps") { - let input = getFloat16(127.5) - let actual = Int32(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat16(127.5)_AlwaysFails") { - let input = getFloat16(127.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat16(255.5)_NeverTraps") { - let input = getFloat16(255.5) - let actual = Int32(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat16(255.5)_AlwaysFails") { - let input = getFloat16(255.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat16(2047)_NeverTraps") { - let input = getFloat16(2047) - let actual = Int32(input) - expectEqual(2047, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat16(2047)_NeverFails") { - let input = getFloat16(2047) - let actual = Int32(exactly: input) - expectEqual(2047, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat16(-.infinity)_AlwaysTraps") { - let input = getFloat16(-.infinity) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat16(-.infinity)_AlwaysFails") { - let input = getFloat16(-.infinity) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat16(+.infinity)_AlwaysTraps") { - let input = getFloat16(+.infinity) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat16(+.infinity)_AlwaysFails") { - let input = getFloat16(+.infinity) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat16(-.nan)_AlwaysTraps") { - let input = getFloat16(-.nan) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat16(-.nan)_AlwaysFails") { - let input = getFloat16(-.nan) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat16(+.nan)_AlwaysTraps") { - let input = getFloat16(+.nan) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat16(+.nan)_AlwaysFails") { - let input = getFloat16(+.nan) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat16(-.signalingNaN)_AlwaysTraps") { - let input = getFloat16(-.signalingNaN) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat16(-.signalingNaN)_AlwaysFails") { - let input = getFloat16(-.signalingNaN) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat16(+.signalingNaN)_AlwaysTraps") { - let input = getFloat16(+.signalingNaN) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat16(+.signalingNaN)_AlwaysFails") { - let input = getFloat16(+.signalingNaN) - let actual = Int32(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt32 +.test("FromFloat16_NeverTraps") +.forEach(in: [ + (getInt32(-2047), getFloat16(-2047)), + (getInt32(-128), getFloat16(-128.5)), + (getInt32(+0), getFloat16(-0.5)), + (getInt32(+0), getFloat16(+0)), + (getInt32(+0), getFloat16(-0)), + (getInt32(+0), getFloat16(+0.5)), + (getInt32(+127), getFloat16(+127.5)), + (getInt32(+255), getFloat16(+255.5)), + (getInt32(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, Int32($0.1)) +} + +FixedPointConversion_Release32_ToInt32 +.test("FromFloat16_NeverFails") +.forEach(in: [ + (getInt32(-2047), getFloat16(-2047)), + (getInt32(+0), getFloat16(+0)), + (getInt32(+0), getFloat16(-0)), + (getInt32(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToInt32 +.test("FromFloat16_AlwaysTraps") +.forEach(in: [ + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int32($0)) +} + +FixedPointConversion_Release32_ToInt32 +.test("FromFloat16_AlwaysFails") +.forEach(in: [ + getFloat16(-128.5), + getFloat16(-0.5), + getFloat16(+0.5), + getFloat16(+127.5), + getFloat16(+255.5), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectNil(Int32(exactly: $0)) } } #endif // Float16 //===----------------------------------------------------------------------===// -// MARK: Float32: (-16777215)...(16777215) +// MARK: Float32: (-16777215)...(+16777215) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt32.test("FromFloat32(-16777215)_NeverTraps") { - let input = getFloat32(-16777215) - let actual = Int32(input) - expectEqual(-16777215, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat32(-16777215)_NeverFails") { - let input = getFloat32(-16777215) - let actual = Int32(exactly: input) - expectEqual(-16777215, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat32(-32768.5)_NeverTraps") { - let input = getFloat32(-32768.5) - let actual = Int32(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat32(-32768.5)_AlwaysFails") { - let input = getFloat32(-32768.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat32(-128.5)_NeverTraps") { - let input = getFloat32(-128.5) - let actual = Int32(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat32(-128.5)_AlwaysFails") { - let input = getFloat32(-128.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat32(-0.5)_NeverTraps") { - let input = getFloat32(-0.5) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat32(-0.5)_AlwaysFails") { - let input = getFloat32(-0.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat32(-0.0)_NeverTraps") { - let input = getFloat32(-0.0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat32(-0.0)_NeverFails") { - let input = getFloat32(-0.0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat32(0.0)_NeverTraps") { - let input = getFloat32(0.0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat32(0.0)_NeverFails") { - let input = getFloat32(0.0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat32(0.5)_NeverTraps") { - let input = getFloat32(0.5) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat32(0.5)_AlwaysFails") { - let input = getFloat32(0.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat32(127.5)_NeverTraps") { - let input = getFloat32(127.5) - let actual = Int32(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat32(127.5)_AlwaysFails") { - let input = getFloat32(127.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat32(255.5)_NeverTraps") { - let input = getFloat32(255.5) - let actual = Int32(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat32(255.5)_AlwaysFails") { - let input = getFloat32(255.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat32(32767.5)_NeverTraps") { - let input = getFloat32(32767.5) - let actual = Int32(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat32(32767.5)_AlwaysFails") { - let input = getFloat32(32767.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat32(65535.5)_NeverTraps") { - let input = getFloat32(65535.5) - let actual = Int32(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat32(65535.5)_AlwaysFails") { - let input = getFloat32(65535.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat32(16777215)_NeverTraps") { - let input = getFloat32(16777215) - let actual = Int32(input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat32(16777215)_NeverFails") { - let input = getFloat32(16777215) - let actual = Int32(exactly: input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat32(-.infinity)_AlwaysTraps") { - let input = getFloat32(-.infinity) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat32(-.infinity)_AlwaysFails") { - let input = getFloat32(-.infinity) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat32(+.infinity)_AlwaysTraps") { - let input = getFloat32(+.infinity) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat32(+.infinity)_AlwaysFails") { - let input = getFloat32(+.infinity) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat32(-.nan)_AlwaysTraps") { - let input = getFloat32(-.nan) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat32(-.nan)_AlwaysFails") { - let input = getFloat32(-.nan) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat32(+.nan)_AlwaysTraps") { - let input = getFloat32(+.nan) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat32(+.nan)_AlwaysFails") { - let input = getFloat32(+.nan) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat32(-.signalingNaN)_AlwaysTraps") { - let input = getFloat32(-.signalingNaN) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat32(-.signalingNaN)_AlwaysFails") { - let input = getFloat32(-.signalingNaN) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat32(+.signalingNaN)_AlwaysTraps") { - let input = getFloat32(+.signalingNaN) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat32(+.signalingNaN)_AlwaysFails") { - let input = getFloat32(+.signalingNaN) - let actual = Int32(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt32 +.test("FromFloat32_NeverTraps") +.forEach(in: [ + (getInt32(-16777215), getFloat32(-16777215)), + (getInt32(-32768), getFloat32(-32768.5)), + (getInt32(-128), getFloat32(-128.5)), + (getInt32(+0), getFloat32(-0.5)), + (getInt32(+0), getFloat32(+0)), + (getInt32(+0), getFloat32(-0)), + (getInt32(+0), getFloat32(+0.5)), + (getInt32(+127), getFloat32(+127.5)), + (getInt32(+255), getFloat32(+255.5)), + (getInt32(+32767), getFloat32(+32767.5)), + (getInt32(+65535), getFloat32(+65535.5)), + (getInt32(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, Int32($0.1)) +} + +FixedPointConversion_Release32_ToInt32 +.test("FromFloat32_NeverFails") +.forEach(in: [ + (getInt32(-16777215), getFloat32(-16777215)), + (getInt32(+0), getFloat32(+0)), + (getInt32(+0), getFloat32(-0)), + (getInt32(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToInt32 +.test("FromFloat32_AlwaysTraps") +.forEach(in: [ + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int32($0)) +} + +FixedPointConversion_Release32_ToInt32 +.test("FromFloat32_AlwaysFails") +.forEach(in: [ + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-0.5), + getFloat32(+0.5), + getFloat32(+127.5), + getFloat32(+255.5), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectNil(Int32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float64: (-9007199254740991)...(9007199254740991) +// MARK: Float64: (-9007199254740991)...(+9007199254740991) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt32.test("FromFloat64(-9007199254740991)_AlwaysTraps") { - let input = getFloat64(-9007199254740991) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(-9007199254740991)_AlwaysFails") { - let input = getFloat64(-9007199254740991) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(-2147483649)_AlwaysTraps") { - let input = getFloat64(-2147483649) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(-2147483649)_AlwaysFails") { - let input = getFloat64(-2147483649) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(-2147483648)_NeverTraps") { - let input = getFloat64(-2147483648) - let actual = Int32(input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(-2147483648)_NeverFails") { - let input = getFloat64(-2147483648) - let actual = Int32(exactly: input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(-32768.5)_NeverTraps") { - let input = getFloat64(-32768.5) - let actual = Int32(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(-32768.5)_AlwaysFails") { - let input = getFloat64(-32768.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(-128.5)_NeverTraps") { - let input = getFloat64(-128.5) - let actual = Int32(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(-128.5)_AlwaysFails") { - let input = getFloat64(-128.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(-0.5)_NeverTraps") { - let input = getFloat64(-0.5) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(-0.5)_AlwaysFails") { - let input = getFloat64(-0.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(-0.0)_NeverTraps") { - let input = getFloat64(-0.0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(-0.0)_NeverFails") { - let input = getFloat64(-0.0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(0.0)_NeverTraps") { - let input = getFloat64(0.0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(0.0)_NeverFails") { - let input = getFloat64(0.0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(0.5)_NeverTraps") { - let input = getFloat64(0.5) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(0.5)_AlwaysFails") { - let input = getFloat64(0.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(127.5)_NeverTraps") { - let input = getFloat64(127.5) - let actual = Int32(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(127.5)_AlwaysFails") { - let input = getFloat64(127.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(255.5)_NeverTraps") { - let input = getFloat64(255.5) - let actual = Int32(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(255.5)_AlwaysFails") { - let input = getFloat64(255.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(32767.5)_NeverTraps") { - let input = getFloat64(32767.5) - let actual = Int32(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(32767.5)_AlwaysFails") { - let input = getFloat64(32767.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(65535.5)_NeverTraps") { - let input = getFloat64(65535.5) - let actual = Int32(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(65535.5)_AlwaysFails") { - let input = getFloat64(65535.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(2147483647)_NeverTraps") { - let input = getFloat64(2147483647) - let actual = Int32(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(2147483647)_NeverFails") { - let input = getFloat64(2147483647) - let actual = Int32(exactly: input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(2147483648)_AlwaysTraps") { - let input = getFloat64(2147483648) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(2147483648)_AlwaysFails") { - let input = getFloat64(2147483648) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(9007199254740991)_AlwaysTraps") { - let input = getFloat64(9007199254740991) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(9007199254740991)_AlwaysFails") { - let input = getFloat64(9007199254740991) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(-.infinity)_AlwaysTraps") { - let input = getFloat64(-.infinity) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(-.infinity)_AlwaysFails") { - let input = getFloat64(-.infinity) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(+.infinity)_AlwaysTraps") { - let input = getFloat64(+.infinity) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(+.infinity)_AlwaysFails") { - let input = getFloat64(+.infinity) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(-.nan)_AlwaysTraps") { - let input = getFloat64(-.nan) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(-.nan)_AlwaysFails") { - let input = getFloat64(-.nan) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(+.nan)_AlwaysTraps") { - let input = getFloat64(+.nan) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(+.nan)_AlwaysFails") { - let input = getFloat64(+.nan) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(-.signalingNaN)_AlwaysTraps") { - let input = getFloat64(-.signalingNaN) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(-.signalingNaN)_AlwaysFails") { - let input = getFloat64(-.signalingNaN) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(+.signalingNaN)_AlwaysTraps") { - let input = getFloat64(+.signalingNaN) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat64(+.signalingNaN)_AlwaysFails") { - let input = getFloat64(+.signalingNaN) - let actual = Int32(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt32 +.test("FromFloat64_NeverTraps") +.forEach(in: [ + (getInt32(-2147483648), getFloat64(-2147483648)), + (getInt32(-32768), getFloat64(-32768.5)), + (getInt32(-128), getFloat64(-128.5)), + (getInt32(+0), getFloat64(-0.5)), + (getInt32(+0), getFloat64(-0)), + (getInt32(+0), getFloat64(+0)), + (getInt32(+0), getFloat64(+0.5)), + (getInt32(+127), getFloat64(+127.5)), + (getInt32(+255), getFloat64(+255.5)), + (getInt32(+32767), getFloat64(+32767.5)), + (getInt32(+65535), getFloat64(+65535.5)), + (getInt32(+2147483647), getFloat64(+2147483647)), +]) { + expectEqual($0.0, Int32($0.1)) +} + +FixedPointConversion_Release32_ToInt32 +.test("FromFloat64_NeverFails") +.forEach(in: [ + (getInt32(-2147483648), getFloat64(-2147483648)), + (getInt32(+0), getFloat64(-0)), + (getInt32(+0), getFloat64(+0)), + (getInt32(+2147483647), getFloat64(+2147483647)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToInt32 +.test("FromFloat64_AlwaysTraps") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-2147483649), + getFloat64(+2147483648), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int32($0)) +} + +FixedPointConversion_Release32_ToInt32 +.test("FromFloat64_AlwaysFails") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-2147483649), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-0.5), + getFloat64(+0.5), + getFloat64(+127.5), + getFloat64(+255.5), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(+2147483648), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectNil(Int32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float80: (-18446744073709551615)...(18446744073709551615) +// MARK: Float80: (-18446744073709551615)...(+18446744073709551615) //===----------------------------------------------------------------------===// #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) -FixedPointConversion_Release32_ToInt32.test("FromFloat80(-18446744073709551615)_AlwaysTraps") { - let input = getFloat80(-18446744073709551615) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(-18446744073709551615)_AlwaysFails") { - let input = getFloat80(-18446744073709551615) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(-2147483649)_AlwaysTraps") { - let input = getFloat80(-2147483649) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(-2147483649)_AlwaysFails") { - let input = getFloat80(-2147483649) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(-2147483648)_NeverTraps") { - let input = getFloat80(-2147483648) - let actual = Int32(input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(-2147483648)_NeverFails") { - let input = getFloat80(-2147483648) - let actual = Int32(exactly: input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(-32768.5)_NeverTraps") { - let input = getFloat80(-32768.5) - let actual = Int32(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(-32768.5)_AlwaysFails") { - let input = getFloat80(-32768.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(-128.5)_NeverTraps") { - let input = getFloat80(-128.5) - let actual = Int32(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(-128.5)_AlwaysFails") { - let input = getFloat80(-128.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(-0.5)_NeverTraps") { - let input = getFloat80(-0.5) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(-0.5)_AlwaysFails") { - let input = getFloat80(-0.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(-0.0)_NeverTraps") { - let input = getFloat80(-0.0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(-0.0)_NeverFails") { - let input = getFloat80(-0.0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(0.0)_NeverTraps") { - let input = getFloat80(0.0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(0.0)_NeverFails") { - let input = getFloat80(0.0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(0.5)_NeverTraps") { - let input = getFloat80(0.5) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(0.5)_AlwaysFails") { - let input = getFloat80(0.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(127.5)_NeverTraps") { - let input = getFloat80(127.5) - let actual = Int32(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(127.5)_AlwaysFails") { - let input = getFloat80(127.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(255.5)_NeverTraps") { - let input = getFloat80(255.5) - let actual = Int32(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(255.5)_AlwaysFails") { - let input = getFloat80(255.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(32767.5)_NeverTraps") { - let input = getFloat80(32767.5) - let actual = Int32(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(32767.5)_AlwaysFails") { - let input = getFloat80(32767.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(65535.5)_NeverTraps") { - let input = getFloat80(65535.5) - let actual = Int32(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(65535.5)_AlwaysFails") { - let input = getFloat80(65535.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(2147483647)_NeverTraps") { - let input = getFloat80(2147483647) - let actual = Int32(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(2147483647)_NeverFails") { - let input = getFloat80(2147483647) - let actual = Int32(exactly: input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(2147483648)_AlwaysTraps") { - let input = getFloat80(2147483648) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(2147483648)_AlwaysFails") { - let input = getFloat80(2147483648) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(18446744073709551615)_AlwaysTraps") { - let input = getFloat80(18446744073709551615) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(18446744073709551615)_AlwaysFails") { - let input = getFloat80(18446744073709551615) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(-.infinity)_AlwaysTraps") { - let input = getFloat80(-.infinity) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(-.infinity)_AlwaysFails") { - let input = getFloat80(-.infinity) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(+.infinity)_AlwaysTraps") { - let input = getFloat80(+.infinity) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(+.infinity)_AlwaysFails") { - let input = getFloat80(+.infinity) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(-.nan)_AlwaysTraps") { - let input = getFloat80(-.nan) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(-.nan)_AlwaysFails") { - let input = getFloat80(-.nan) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(+.nan)_AlwaysTraps") { - let input = getFloat80(+.nan) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(+.nan)_AlwaysFails") { - let input = getFloat80(+.nan) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(-.signalingNaN)_AlwaysTraps") { - let input = getFloat80(-.signalingNaN) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(-.signalingNaN)_AlwaysFails") { - let input = getFloat80(-.signalingNaN) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(+.signalingNaN)_AlwaysTraps") { - let input = getFloat80(+.signalingNaN) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt32.test("FromFloat80(+.signalingNaN)_AlwaysFails") { - let input = getFloat80(+.signalingNaN) - let actual = Int32(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt32 +.test("FromFloat80_NeverTraps") +.forEach(in: [ + (getInt32(-2147483648), getFloat80(-2147483648)), + (getInt32(-32768), getFloat80(-32768.5)), + (getInt32(-128), getFloat80(-128.5)), + (getInt32(+0), getFloat80(-0.5)), + (getInt32(+0), getFloat80(-0)), + (getInt32(+0), getFloat80(+0)), + (getInt32(+0), getFloat80(+0.5)), + (getInt32(+127), getFloat80(+127.5)), + (getInt32(+255), getFloat80(+255.5)), + (getInt32(+32767), getFloat80(+32767.5)), + (getInt32(+65535), getFloat80(+65535.5)), + (getInt32(+2147483647), getFloat80(+2147483647)), +]) { + expectEqual($0.0, Int32($0.1)) +} + +FixedPointConversion_Release32_ToInt32 +.test("FromFloat80_NeverFails") +.forEach(in: [ + (getInt32(-2147483648), getFloat80(-2147483648)), + (getInt32(+0), getFloat80(-0)), + (getInt32(+0), getFloat80(+0)), + (getInt32(+2147483647), getFloat80(+2147483647)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToInt32 +.test("FromFloat80_AlwaysTraps") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-2147483649), + getFloat80(+2147483648), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int32($0)) +} + +FixedPointConversion_Release32_ToInt32 +.test("FromFloat80_AlwaysFails") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-2147483649), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-0.5), + getFloat80(+0.5), + getFloat80(+127.5), + getFloat80(+255.5), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(+2147483648), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectNil(Int32(exactly: $0)) } #endif // Float80 diff --git a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release32_ToInt64.swift b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release32_ToInt64.swift index afb85ded232b8..b35d3db1c7341 100644 --- a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release32_ToInt64.swift +++ b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release32_ToInt64.swift @@ -5,7 +5,7 @@ // //===----------------------------------------------------------------------===// // -// REQUIRES: executable_test, long_test +// REQUIRES: executable_test // REQUIRES: PTRSIZE=32 // RUN: %target-run-simple-swift(-O) // END. @@ -14,1330 +14,543 @@ import StdlibUnittest -let FixedPointConversion_Release32_ToInt64 = TestSuite("FixedPointConversion_Release32_ToInt64") +let FixedPointConversion_Release32_ToInt64 = TestSuite( + "FixedPointConversion_Release32_ToInt64" +) //===----------------------------------------------------------------------===// -// MARK: UInt8: (0)...(255) +// MARK: UInt8: (+0)...(+255) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt64.test("FromUInt8(0)_NeverTraps") { - let input = getUInt8(0) - let actual = Int64(input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToInt64 +.test("FromUInt8_NeverTraps") +.forEach(in: [ + (getInt64(+0), getUInt8(+0)), + (getInt64(+255), getUInt8(+255)), +]) { + expectEqual($0.0, Int64($0.1)) } -FixedPointConversion_Release32_ToInt64.test("FromUInt8(0)_NeverFails") { - let input = getUInt8(0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromUInt8(255)_NeverTraps") { - let input = getUInt8(255) - let actual = Int64(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromUInt8(255)_NeverFails") { - let input = getUInt8(255) - let actual = Int64(exactly: input) - expectEqual(255, actual) +FixedPointConversion_Release32_ToInt64 +.test("FromUInt8_NeverFails") +.forEach(in: [ + (getInt64(+0), getUInt8(+0)), + (getInt64(+255), getUInt8(+255)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int8: (-128)...(127) +// MARK: Int8: (-128)...(+127) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt64.test("FromInt8(-128)_NeverTraps") { - let input = getInt8(-128) - let actual = Int64(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromInt8(-128)_NeverFails") { - let input = getInt8(-128) - let actual = Int64(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromInt8(0)_NeverTraps") { - let input = getInt8(0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromInt8(0)_NeverFails") { - let input = getInt8(0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromInt8(127)_NeverTraps") { - let input = getInt8(127) - let actual = Int64(input) - expectEqual(127, actual) +FixedPointConversion_Release32_ToInt64 +.test("FromInt8_NeverTraps") +.forEach(in: [ + (getInt64(-128), getInt8(-128)), + (getInt64(+0), getInt8(+0)), + (getInt64(+127), getInt8(+127)), +]) { + expectEqual($0.0, Int64($0.1)) } -FixedPointConversion_Release32_ToInt64.test("FromInt8(127)_NeverFails") { - let input = getInt8(127) - let actual = Int64(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Release32_ToInt64 +.test("FromInt8_NeverFails") +.forEach(in: [ + (getInt64(-128), getInt8(-128)), + (getInt64(+0), getInt8(+0)), + (getInt64(+127), getInt8(+127)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt16: (0)...(65535) +// MARK: UInt16: (+0)...(+65535) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt64.test("FromUInt16(0)_NeverTraps") { - let input = getUInt16(0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromUInt16(0)_NeverFails") { - let input = getUInt16(0) - let actual = Int64(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToInt64 +.test("FromUInt16_NeverTraps") +.forEach(in: [ + (getInt64(+0), getUInt16(+0)), + (getInt64(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, Int64($0.1)) } -FixedPointConversion_Release32_ToInt64.test("FromUInt16(65535)_NeverTraps") { - let input = getUInt16(65535) - let actual = Int64(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromUInt16(65535)_NeverFails") { - let input = getUInt16(65535) - let actual = Int64(exactly: input) - expectEqual(65535, actual) +FixedPointConversion_Release32_ToInt64 +.test("FromUInt16_NeverFails") +.forEach(in: [ + (getInt64(+0), getUInt16(+0)), + (getInt64(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int16: (-32768)...(32767) +// MARK: Int16: (-32768)...(+32767) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt64.test("FromInt16(-32768)_NeverTraps") { - let input = getInt16(-32768) - let actual = Int64(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromInt16(-32768)_NeverFails") { - let input = getInt16(-32768) - let actual = Int64(exactly: input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromInt16(0)_NeverTraps") { - let input = getInt16(0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromInt16(0)_NeverFails") { - let input = getInt16(0) - let actual = Int64(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToInt64 +.test("FromInt16_NeverTraps") +.forEach(in: [ + (getInt64(-32768), getInt16(-32768)), + (getInt64(+0), getInt16(+0)), + (getInt64(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, Int64($0.1)) } -FixedPointConversion_Release32_ToInt64.test("FromInt16(32767)_NeverTraps") { - let input = getInt16(32767) - let actual = Int64(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromInt16(32767)_NeverFails") { - let input = getInt16(32767) - let actual = Int64(exactly: input) - expectEqual(32767, actual) +FixedPointConversion_Release32_ToInt64 +.test("FromInt16_NeverFails") +.forEach(in: [ + (getInt64(-32768), getInt16(-32768)), + (getInt64(+0), getInt16(+0)), + (getInt64(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt32: (0)...(4294967295) +// MARK: UInt32: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt64.test("FromUInt32(0)_NeverTraps") { - let input = getUInt32(0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromUInt32(0)_NeverFails") { - let input = getUInt32(0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromUInt32(4294967295)_NeverTraps") { - let input = getUInt32(4294967295) - let actual = Int64(input) - expectEqual(4294967295, actual) +FixedPointConversion_Release32_ToInt64 +.test("FromUInt32_NeverTraps") +.forEach(in: [ + (getInt64(+0), getUInt32(+0)), + (getInt64(+4294967295), getUInt32(+4294967295)), +]) { + expectEqual($0.0, Int64($0.1)) } -FixedPointConversion_Release32_ToInt64.test("FromUInt32(4294967295)_NeverFails") { - let input = getUInt32(4294967295) - let actual = Int64(exactly: input) - expectEqual(4294967295, actual) +FixedPointConversion_Release32_ToInt64 +.test("FromUInt32_NeverFails") +.forEach(in: [ + (getInt64(+0), getUInt32(+0)), + (getInt64(+4294967295), getUInt32(+4294967295)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int32: (-2147483648)...(2147483647) +// MARK: Int32: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt64.test("FromInt32(-2147483648)_NeverTraps") { - let input = getInt32(-2147483648) - let actual = Int64(input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromInt32(-2147483648)_NeverFails") { - let input = getInt32(-2147483648) - let actual = Int64(exactly: input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromInt32(0)_NeverTraps") { - let input = getInt32(0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromInt32(0)_NeverFails") { - let input = getInt32(0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromInt32(2147483647)_NeverTraps") { - let input = getInt32(2147483647) - let actual = Int64(input) - expectEqual(2147483647, actual) +FixedPointConversion_Release32_ToInt64 +.test("FromInt32_NeverTraps") +.forEach(in: [ + (getInt64(-2147483648), getInt32(-2147483648)), + (getInt64(+0), getInt32(+0)), + (getInt64(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, Int64($0.1)) } -FixedPointConversion_Release32_ToInt64.test("FromInt32(2147483647)_NeverFails") { - let input = getInt32(2147483647) - let actual = Int64(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Release32_ToInt64 +.test("FromInt32_NeverFails") +.forEach(in: [ + (getInt64(-2147483648), getInt32(-2147483648)), + (getInt64(+0), getInt32(+0)), + (getInt64(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt64: (0)...(18446744073709551615) +// MARK: UInt64: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt64.test("FromUInt64(0)_NeverTraps") { - let input = getUInt64(0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromUInt64(0)_NeverFails") { - let input = getUInt64(0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromUInt64(9223372036854775807)_NeverTraps") { - let input = getUInt64(9223372036854775807) - let actual = Int64(input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromUInt64(9223372036854775807)_NeverFails") { - let input = getUInt64(9223372036854775807) - let actual = Int64(exactly: input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromUInt64(9223372036854775808)_AlwaysTraps") { - let input = getUInt64(9223372036854775808) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } +FixedPointConversion_Release32_ToInt64 +.test("FromUInt64_NeverTraps") +.forEach(in: [ + (getInt64(+0), getUInt64(+0)), + (getInt64(+9223372036854775807), getUInt64(+9223372036854775807)), +]) { + expectEqual($0.0, Int64($0.1)) } -FixedPointConversion_Release32_ToInt64.test("FromUInt64(9223372036854775808)_AlwaysFails") { - let input = getUInt64(9223372036854775808) - let actual = Int64(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt64 +.test("FromUInt64_NeverFails") +.forEach(in: [ + (getInt64(+0), getUInt64(+0)), + (getInt64(+9223372036854775807), getUInt64(+9223372036854775807)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) } -FixedPointConversion_Release32_ToInt64.test("FromUInt64(18446744073709551615)_AlwaysTraps") { - let input = getUInt64(18446744073709551615) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } +FixedPointConversion_Release32_ToInt64 +.test("FromUInt64_AlwaysTraps") +.forEach(in: [ + getUInt64(+9223372036854775808), + getUInt64(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(Int64($0)) } -FixedPointConversion_Release32_ToInt64.test("FromUInt64(18446744073709551615)_AlwaysFails") { - let input = getUInt64(18446744073709551615) - let actual = Int64(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt64 +.test("FromUInt64_AlwaysFails") +.forEach(in: [ + getUInt64(+9223372036854775808), + getUInt64(+18446744073709551615), +]) { + expectNil(Int64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int64: (-9223372036854775808)...(9223372036854775807) +// MARK: Int64: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt64.test("FromInt64(-9223372036854775808)_NeverTraps") { - let input = getInt64(-9223372036854775808) - let actual = Int64(input) - expectEqual(-9223372036854775808, actual) +FixedPointConversion_Release32_ToInt64 +.test("FromInt64_NeverTraps") +.forEach(in: [ + (getInt64(-9223372036854775808), getInt64(-9223372036854775808)), + (getInt64(+0), getInt64(+0)), + (getInt64(+9223372036854775807), getInt64(+9223372036854775807)), +]) { + expectEqual($0.0, Int64($0.1)) } -FixedPointConversion_Release32_ToInt64.test("FromInt64(-9223372036854775808)_NeverFails") { - let input = getInt64(-9223372036854775808) - let actual = Int64(exactly: input) - expectEqual(-9223372036854775808, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromInt64(0)_NeverTraps") { - let input = getInt64(0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromInt64(0)_NeverFails") { - let input = getInt64(0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromInt64(9223372036854775807)_NeverTraps") { - let input = getInt64(9223372036854775807) - let actual = Int64(input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromInt64(9223372036854775807)_NeverFails") { - let input = getInt64(9223372036854775807) - let actual = Int64(exactly: input) - expectEqual(9223372036854775807, actual) +FixedPointConversion_Release32_ToInt64 +.test("FromInt64_NeverFails") +.forEach(in: [ + (getInt64(-9223372036854775808), getInt64(-9223372036854775808)), + (getInt64(+0), getInt64(+0)), + (getInt64(+9223372036854775807), getInt64(+9223372036854775807)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt: (0)...(4294967295) +// MARK: UInt: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt64.test("FromUInt(0)_NeverTraps") { - let input = getUInt(0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromUInt(0)_NeverFails") { - let input = getUInt(0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromUInt(4294967295)_NeverTraps") { - let input = getUInt(4294967295) - let actual = Int64(input) - expectEqual(4294967295, actual) +FixedPointConversion_Release32_ToInt64 +.test("FromUInt_NeverTraps") +.forEach(in: [ + (getInt64(+0), getUInt(+0)), + (getInt64(+4294967295), getUInt(+4294967295)), +]) { + expectEqual($0.0, Int64($0.1)) } -FixedPointConversion_Release32_ToInt64.test("FromUInt(4294967295)_NeverFails") { - let input = getUInt(4294967295) - let actual = Int64(exactly: input) - expectEqual(4294967295, actual) +FixedPointConversion_Release32_ToInt64 +.test("FromUInt_NeverFails") +.forEach(in: [ + (getInt64(+0), getUInt(+0)), + (getInt64(+4294967295), getUInt(+4294967295)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int: (-2147483648)...(2147483647) +// MARK: Int: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt64.test("FromInt(-2147483648)_NeverTraps") { - let input = getInt(-2147483648) - let actual = Int64(input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromInt(-2147483648)_NeverFails") { - let input = getInt(-2147483648) - let actual = Int64(exactly: input) - expectEqual(-2147483648, actual) +FixedPointConversion_Release32_ToInt64 +.test("FromInt_NeverTraps") +.forEach(in: [ + (getInt64(-2147483648), getInt(-2147483648)), + (getInt64(+0), getInt(+0)), + (getInt64(+2147483647), getInt(+2147483647)), +]) { + expectEqual($0.0, Int64($0.1)) } -FixedPointConversion_Release32_ToInt64.test("FromInt(0)_NeverTraps") { - let input = getInt(0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromInt(0)_NeverFails") { - let input = getInt(0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromInt(2147483647)_NeverTraps") { - let input = getInt(2147483647) - let actual = Int64(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromInt(2147483647)_NeverFails") { - let input = getInt(2147483647) - let actual = Int64(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Release32_ToInt64 +.test("FromInt_NeverFails") +.forEach(in: [ + (getInt64(-2147483648), getInt(-2147483648)), + (getInt64(+0), getInt(+0)), + (getInt64(+2147483647), getInt(+2147483647)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Float16: (-2047)...(2047) +// MARK: Float16: (-2047)...(+2047) //===----------------------------------------------------------------------===// #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -FixedPointConversion_Release32_ToInt64.test("FromFloat16(-2047)_NeverTraps") { - let input = getFloat16(-2047) - let actual = Int64(input) - expectEqual(-2047, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat16(-2047)_NeverFails") { - let input = getFloat16(-2047) - let actual = Int64(exactly: input) - expectEqual(-2047, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat16(-128.5)_NeverTraps") { - let input = getFloat16(-128.5) - let actual = Int64(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat16(-128.5)_AlwaysFails") { - let input = getFloat16(-128.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat16(-0.5)_NeverTraps") { - let input = getFloat16(-0.5) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat16(-0.5)_AlwaysFails") { - let input = getFloat16(-0.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat16(-0.0)_NeverTraps") { - let input = getFloat16(-0.0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat16(-0.0)_NeverFails") { - let input = getFloat16(-0.0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat16(0.0)_NeverTraps") { - let input = getFloat16(0.0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat16(0.0)_NeverFails") { - let input = getFloat16(0.0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat16(0.5)_NeverTraps") { - let input = getFloat16(0.5) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat16(0.5)_AlwaysFails") { - let input = getFloat16(0.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat16(127.5)_NeverTraps") { - let input = getFloat16(127.5) - let actual = Int64(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat16(127.5)_AlwaysFails") { - let input = getFloat16(127.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat16(255.5)_NeverTraps") { - let input = getFloat16(255.5) - let actual = Int64(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat16(255.5)_AlwaysFails") { - let input = getFloat16(255.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat16(2047)_NeverTraps") { - let input = getFloat16(2047) - let actual = Int64(input) - expectEqual(2047, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat16(2047)_NeverFails") { - let input = getFloat16(2047) - let actual = Int64(exactly: input) - expectEqual(2047, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat16(-.infinity)_AlwaysTraps") { - let input = getFloat16(-.infinity) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat16(-.infinity)_AlwaysFails") { - let input = getFloat16(-.infinity) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat16(+.infinity)_AlwaysTraps") { - let input = getFloat16(+.infinity) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat16(+.infinity)_AlwaysFails") { - let input = getFloat16(+.infinity) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat16(-.nan)_AlwaysTraps") { - let input = getFloat16(-.nan) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat16(-.nan)_AlwaysFails") { - let input = getFloat16(-.nan) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat16(+.nan)_AlwaysTraps") { - let input = getFloat16(+.nan) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat16(+.nan)_AlwaysFails") { - let input = getFloat16(+.nan) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat16(-.signalingNaN)_AlwaysTraps") { - let input = getFloat16(-.signalingNaN) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat16(-.signalingNaN)_AlwaysFails") { - let input = getFloat16(-.signalingNaN) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat16(+.signalingNaN)_AlwaysTraps") { - let input = getFloat16(+.signalingNaN) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat16(+.signalingNaN)_AlwaysFails") { - let input = getFloat16(+.signalingNaN) - let actual = Int64(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt64 +.test("FromFloat16_NeverTraps") +.forEach(in: [ + (getInt64(-2047), getFloat16(-2047)), + (getInt64(-128), getFloat16(-128.5)), + (getInt64(+0), getFloat16(-0.5)), + (getInt64(+0), getFloat16(+0)), + (getInt64(+0), getFloat16(-0)), + (getInt64(+0), getFloat16(+0.5)), + (getInt64(+127), getFloat16(+127.5)), + (getInt64(+255), getFloat16(+255.5)), + (getInt64(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, Int64($0.1)) +} + +FixedPointConversion_Release32_ToInt64 +.test("FromFloat16_NeverFails") +.forEach(in: [ + (getInt64(-2047), getFloat16(-2047)), + (getInt64(+0), getFloat16(+0)), + (getInt64(+0), getFloat16(-0)), + (getInt64(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToInt64 +.test("FromFloat16_AlwaysTraps") +.forEach(in: [ + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int64($0)) +} + +FixedPointConversion_Release32_ToInt64 +.test("FromFloat16_AlwaysFails") +.forEach(in: [ + getFloat16(-128.5), + getFloat16(-0.5), + getFloat16(+0.5), + getFloat16(+127.5), + getFloat16(+255.5), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectNil(Int64(exactly: $0)) } } #endif // Float16 //===----------------------------------------------------------------------===// -// MARK: Float32: (-16777215)...(16777215) +// MARK: Float32: (-16777215)...(+16777215) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt64.test("FromFloat32(-16777215)_NeverTraps") { - let input = getFloat32(-16777215) - let actual = Int64(input) - expectEqual(-16777215, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat32(-16777215)_NeverFails") { - let input = getFloat32(-16777215) - let actual = Int64(exactly: input) - expectEqual(-16777215, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat32(-32768.5)_NeverTraps") { - let input = getFloat32(-32768.5) - let actual = Int64(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat32(-32768.5)_AlwaysFails") { - let input = getFloat32(-32768.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat32(-128.5)_NeverTraps") { - let input = getFloat32(-128.5) - let actual = Int64(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat32(-128.5)_AlwaysFails") { - let input = getFloat32(-128.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat32(-0.5)_NeverTraps") { - let input = getFloat32(-0.5) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat32(-0.5)_AlwaysFails") { - let input = getFloat32(-0.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat32(-0.0)_NeverTraps") { - let input = getFloat32(-0.0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat32(-0.0)_NeverFails") { - let input = getFloat32(-0.0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat32(0.0)_NeverTraps") { - let input = getFloat32(0.0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat32(0.0)_NeverFails") { - let input = getFloat32(0.0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat32(0.5)_NeverTraps") { - let input = getFloat32(0.5) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat32(0.5)_AlwaysFails") { - let input = getFloat32(0.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat32(127.5)_NeverTraps") { - let input = getFloat32(127.5) - let actual = Int64(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat32(127.5)_AlwaysFails") { - let input = getFloat32(127.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat32(255.5)_NeverTraps") { - let input = getFloat32(255.5) - let actual = Int64(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat32(255.5)_AlwaysFails") { - let input = getFloat32(255.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat32(32767.5)_NeverTraps") { - let input = getFloat32(32767.5) - let actual = Int64(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat32(32767.5)_AlwaysFails") { - let input = getFloat32(32767.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat32(65535.5)_NeverTraps") { - let input = getFloat32(65535.5) - let actual = Int64(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat32(65535.5)_AlwaysFails") { - let input = getFloat32(65535.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat32(16777215)_NeverTraps") { - let input = getFloat32(16777215) - let actual = Int64(input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat32(16777215)_NeverFails") { - let input = getFloat32(16777215) - let actual = Int64(exactly: input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat32(-.infinity)_AlwaysTraps") { - let input = getFloat32(-.infinity) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat32(-.infinity)_AlwaysFails") { - let input = getFloat32(-.infinity) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat32(+.infinity)_AlwaysTraps") { - let input = getFloat32(+.infinity) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat32(+.infinity)_AlwaysFails") { - let input = getFloat32(+.infinity) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat32(-.nan)_AlwaysTraps") { - let input = getFloat32(-.nan) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat32(-.nan)_AlwaysFails") { - let input = getFloat32(-.nan) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat32(+.nan)_AlwaysTraps") { - let input = getFloat32(+.nan) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat32(+.nan)_AlwaysFails") { - let input = getFloat32(+.nan) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat32(-.signalingNaN)_AlwaysTraps") { - let input = getFloat32(-.signalingNaN) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat32(-.signalingNaN)_AlwaysFails") { - let input = getFloat32(-.signalingNaN) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat32(+.signalingNaN)_AlwaysTraps") { - let input = getFloat32(+.signalingNaN) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat32(+.signalingNaN)_AlwaysFails") { - let input = getFloat32(+.signalingNaN) - let actual = Int64(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt64 +.test("FromFloat32_NeverTraps") +.forEach(in: [ + (getInt64(-16777215), getFloat32(-16777215)), + (getInt64(-32768), getFloat32(-32768.5)), + (getInt64(-128), getFloat32(-128.5)), + (getInt64(+0), getFloat32(-0.5)), + (getInt64(+0), getFloat32(+0)), + (getInt64(+0), getFloat32(-0)), + (getInt64(+0), getFloat32(+0.5)), + (getInt64(+127), getFloat32(+127.5)), + (getInt64(+255), getFloat32(+255.5)), + (getInt64(+32767), getFloat32(+32767.5)), + (getInt64(+65535), getFloat32(+65535.5)), + (getInt64(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, Int64($0.1)) +} + +FixedPointConversion_Release32_ToInt64 +.test("FromFloat32_NeverFails") +.forEach(in: [ + (getInt64(-16777215), getFloat32(-16777215)), + (getInt64(+0), getFloat32(+0)), + (getInt64(+0), getFloat32(-0)), + (getInt64(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToInt64 +.test("FromFloat32_AlwaysTraps") +.forEach(in: [ + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int64($0)) +} + +FixedPointConversion_Release32_ToInt64 +.test("FromFloat32_AlwaysFails") +.forEach(in: [ + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-0.5), + getFloat32(+0.5), + getFloat32(+127.5), + getFloat32(+255.5), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectNil(Int64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float64: (-9007199254740991)...(9007199254740991) +// MARK: Float64: (-9007199254740991)...(+9007199254740991) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt64.test("FromFloat64(-9007199254740991)_NeverTraps") { - let input = getFloat64(-9007199254740991) - let actual = Int64(input) - expectEqual(-9007199254740991, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat64(-9007199254740991)_NeverFails") { - let input = getFloat64(-9007199254740991) - let actual = Int64(exactly: input) - expectEqual(-9007199254740991, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat64(-32768.5)_NeverTraps") { - let input = getFloat64(-32768.5) - let actual = Int64(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat64(-32768.5)_AlwaysFails") { - let input = getFloat64(-32768.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat64(-128.5)_NeverTraps") { - let input = getFloat64(-128.5) - let actual = Int64(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat64(-128.5)_AlwaysFails") { - let input = getFloat64(-128.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat64(-0.5)_NeverTraps") { - let input = getFloat64(-0.5) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat64(-0.5)_AlwaysFails") { - let input = getFloat64(-0.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat64(-0.0)_NeverTraps") { - let input = getFloat64(-0.0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat64(-0.0)_NeverFails") { - let input = getFloat64(-0.0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat64(0.0)_NeverTraps") { - let input = getFloat64(0.0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat64(0.0)_NeverFails") { - let input = getFloat64(0.0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat64(0.5)_NeverTraps") { - let input = getFloat64(0.5) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat64(0.5)_AlwaysFails") { - let input = getFloat64(0.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat64(127.5)_NeverTraps") { - let input = getFloat64(127.5) - let actual = Int64(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat64(127.5)_AlwaysFails") { - let input = getFloat64(127.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat64(255.5)_NeverTraps") { - let input = getFloat64(255.5) - let actual = Int64(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat64(255.5)_AlwaysFails") { - let input = getFloat64(255.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat64(32767.5)_NeverTraps") { - let input = getFloat64(32767.5) - let actual = Int64(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat64(32767.5)_AlwaysFails") { - let input = getFloat64(32767.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat64(65535.5)_NeverTraps") { - let input = getFloat64(65535.5) - let actual = Int64(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat64(65535.5)_AlwaysFails") { - let input = getFloat64(65535.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat64(9007199254740991)_NeverTraps") { - let input = getFloat64(9007199254740991) - let actual = Int64(input) - expectEqual(9007199254740991, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat64(9007199254740991)_NeverFails") { - let input = getFloat64(9007199254740991) - let actual = Int64(exactly: input) - expectEqual(9007199254740991, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat64(-.infinity)_AlwaysTraps") { - let input = getFloat64(-.infinity) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat64(-.infinity)_AlwaysFails") { - let input = getFloat64(-.infinity) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat64(+.infinity)_AlwaysTraps") { - let input = getFloat64(+.infinity) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat64(+.infinity)_AlwaysFails") { - let input = getFloat64(+.infinity) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat64(-.nan)_AlwaysTraps") { - let input = getFloat64(-.nan) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat64(-.nan)_AlwaysFails") { - let input = getFloat64(-.nan) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat64(+.nan)_AlwaysTraps") { - let input = getFloat64(+.nan) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat64(+.nan)_AlwaysFails") { - let input = getFloat64(+.nan) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat64(-.signalingNaN)_AlwaysTraps") { - let input = getFloat64(-.signalingNaN) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat64(-.signalingNaN)_AlwaysFails") { - let input = getFloat64(-.signalingNaN) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat64(+.signalingNaN)_AlwaysTraps") { - let input = getFloat64(+.signalingNaN) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat64(+.signalingNaN)_AlwaysFails") { - let input = getFloat64(+.signalingNaN) - let actual = Int64(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt64 +.test("FromFloat64_NeverTraps") +.forEach(in: [ + (getInt64(-9007199254740991), getFloat64(-9007199254740991)), + (getInt64(-32768), getFloat64(-32768.5)), + (getInt64(-128), getFloat64(-128.5)), + (getInt64(+0), getFloat64(-0.5)), + (getInt64(+0), getFloat64(+0)), + (getInt64(+0), getFloat64(-0)), + (getInt64(+0), getFloat64(+0.5)), + (getInt64(+127), getFloat64(+127.5)), + (getInt64(+255), getFloat64(+255.5)), + (getInt64(+32767), getFloat64(+32767.5)), + (getInt64(+65535), getFloat64(+65535.5)), + (getInt64(+9007199254740991), getFloat64(+9007199254740991)), +]) { + expectEqual($0.0, Int64($0.1)) +} + +FixedPointConversion_Release32_ToInt64 +.test("FromFloat64_NeverFails") +.forEach(in: [ + (getInt64(-9007199254740991), getFloat64(-9007199254740991)), + (getInt64(+0), getFloat64(+0)), + (getInt64(+0), getFloat64(-0)), + (getInt64(+9007199254740991), getFloat64(+9007199254740991)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToInt64 +.test("FromFloat64_AlwaysTraps") +.forEach(in: [ + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int64($0)) +} + +FixedPointConversion_Release32_ToInt64 +.test("FromFloat64_AlwaysFails") +.forEach(in: [ + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-0.5), + getFloat64(+0.5), + getFloat64(+127.5), + getFloat64(+255.5), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectNil(Int64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float80: (-18446744073709551615)...(18446744073709551615) +// MARK: Float80: (-18446744073709551615)...(+18446744073709551615) //===----------------------------------------------------------------------===// #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) -FixedPointConversion_Release32_ToInt64.test("FromFloat80(-18446744073709551615)_AlwaysTraps") { - let input = getFloat80(-18446744073709551615) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(-18446744073709551615)_AlwaysFails") { - let input = getFloat80(-18446744073709551615) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(-9223372036854775809)_AlwaysTraps") { - let input = getFloat80(-9223372036854775809) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(-9223372036854775809)_AlwaysFails") { - let input = getFloat80(-9223372036854775809) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(-9223372036854775808)_NeverTraps") { - let input = getFloat80(-9223372036854775808) - let actual = Int64(input) - expectEqual(-9223372036854775808, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(-9223372036854775808)_NeverFails") { - let input = getFloat80(-9223372036854775808) - let actual = Int64(exactly: input) - expectEqual(-9223372036854775808, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(-32768.5)_NeverTraps") { - let input = getFloat80(-32768.5) - let actual = Int64(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(-32768.5)_AlwaysFails") { - let input = getFloat80(-32768.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(-128.5)_NeverTraps") { - let input = getFloat80(-128.5) - let actual = Int64(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(-128.5)_AlwaysFails") { - let input = getFloat80(-128.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(-0.5)_NeverTraps") { - let input = getFloat80(-0.5) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(-0.5)_AlwaysFails") { - let input = getFloat80(-0.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(-0.0)_NeverTraps") { - let input = getFloat80(-0.0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(-0.0)_NeverFails") { - let input = getFloat80(-0.0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(0.0)_NeverTraps") { - let input = getFloat80(0.0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(0.0)_NeverFails") { - let input = getFloat80(0.0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(0.5)_NeverTraps") { - let input = getFloat80(0.5) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(0.5)_AlwaysFails") { - let input = getFloat80(0.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(127.5)_NeverTraps") { - let input = getFloat80(127.5) - let actual = Int64(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(127.5)_AlwaysFails") { - let input = getFloat80(127.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(255.5)_NeverTraps") { - let input = getFloat80(255.5) - let actual = Int64(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(255.5)_AlwaysFails") { - let input = getFloat80(255.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(32767.5)_NeverTraps") { - let input = getFloat80(32767.5) - let actual = Int64(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(32767.5)_AlwaysFails") { - let input = getFloat80(32767.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(65535.5)_NeverTraps") { - let input = getFloat80(65535.5) - let actual = Int64(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(65535.5)_AlwaysFails") { - let input = getFloat80(65535.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(9223372036854775807)_NeverTraps") { - let input = getFloat80(9223372036854775807) - let actual = Int64(input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(9223372036854775807)_NeverFails") { - let input = getFloat80(9223372036854775807) - let actual = Int64(exactly: input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(9223372036854775808)_AlwaysTraps") { - let input = getFloat80(9223372036854775808) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(9223372036854775808)_AlwaysFails") { - let input = getFloat80(9223372036854775808) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(18446744073709551615)_AlwaysTraps") { - let input = getFloat80(18446744073709551615) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(18446744073709551615)_AlwaysFails") { - let input = getFloat80(18446744073709551615) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(-.infinity)_AlwaysTraps") { - let input = getFloat80(-.infinity) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(-.infinity)_AlwaysFails") { - let input = getFloat80(-.infinity) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(+.infinity)_AlwaysTraps") { - let input = getFloat80(+.infinity) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(+.infinity)_AlwaysFails") { - let input = getFloat80(+.infinity) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(-.nan)_AlwaysTraps") { - let input = getFloat80(-.nan) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(-.nan)_AlwaysFails") { - let input = getFloat80(-.nan) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(+.nan)_AlwaysTraps") { - let input = getFloat80(+.nan) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(+.nan)_AlwaysFails") { - let input = getFloat80(+.nan) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(-.signalingNaN)_AlwaysTraps") { - let input = getFloat80(-.signalingNaN) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(-.signalingNaN)_AlwaysFails") { - let input = getFloat80(-.signalingNaN) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(+.signalingNaN)_AlwaysTraps") { - let input = getFloat80(+.signalingNaN) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt64.test("FromFloat80(+.signalingNaN)_AlwaysFails") { - let input = getFloat80(+.signalingNaN) - let actual = Int64(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt64 +.test("FromFloat80_NeverTraps") +.forEach(in: [ + (getInt64(-9223372036854775808), getFloat80(-9223372036854775808)), + (getInt64(-32768), getFloat80(-32768.5)), + (getInt64(-128), getFloat80(-128.5)), + (getInt64(+0), getFloat80(-0.5)), + (getInt64(+0), getFloat80(-0)), + (getInt64(+0), getFloat80(+0)), + (getInt64(+0), getFloat80(+0.5)), + (getInt64(+127), getFloat80(+127.5)), + (getInt64(+255), getFloat80(+255.5)), + (getInt64(+32767), getFloat80(+32767.5)), + (getInt64(+65535), getFloat80(+65535.5)), + (getInt64(+9223372036854775807), getFloat80(+9223372036854775807)), +]) { + expectEqual($0.0, Int64($0.1)) +} + +FixedPointConversion_Release32_ToInt64 +.test("FromFloat80_NeverFails") +.forEach(in: [ + (getInt64(-9223372036854775808), getFloat80(-9223372036854775808)), + (getInt64(+0), getFloat80(-0)), + (getInt64(+0), getFloat80(+0)), + (getInt64(+9223372036854775807), getFloat80(+9223372036854775807)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToInt64 +.test("FromFloat80_AlwaysTraps") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-9223372036854775809), + getFloat80(+9223372036854775808), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int64($0)) +} + +FixedPointConversion_Release32_ToInt64 +.test("FromFloat80_AlwaysFails") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-9223372036854775809), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-0.5), + getFloat80(+0.5), + getFloat80(+127.5), + getFloat80(+255.5), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(+9223372036854775808), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectNil(Int64(exactly: $0)) } #endif // Float80 diff --git a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release32_ToInt8.swift b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release32_ToInt8.swift index 122d3d604f4d8..478d5d9347fc3 100644 --- a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release32_ToInt8.swift +++ b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release32_ToInt8.swift @@ -5,7 +5,7 @@ // //===----------------------------------------------------------------------===// // -// REQUIRES: executable_test, long_test +// REQUIRES: executable_test // REQUIRES: PTRSIZE=32 // RUN: %target-run-simple-swift(-O) // END. @@ -14,1860 +14,735 @@ import StdlibUnittest -let FixedPointConversion_Release32_ToInt8 = TestSuite("FixedPointConversion_Release32_ToInt8") +let FixedPointConversion_Release32_ToInt8 = TestSuite( + "FixedPointConversion_Release32_ToInt8" +) //===----------------------------------------------------------------------===// -// MARK: UInt8: (0)...(255) +// MARK: UInt8: (+0)...(+255) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt8.test("FromUInt8(0)_NeverTraps") { - let input = getUInt8(0) - let actual = Int8(input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToInt8 +.test("FromUInt8_NeverTraps") +.forEach(in: [ + (getInt8(+0), getUInt8(+0)), + (getInt8(+127), getUInt8(+127)), +]) { + expectEqual($0.0, Int8($0.1)) } -FixedPointConversion_Release32_ToInt8.test("FromUInt8(0)_NeverFails") { - let input = getUInt8(0) - let actual = Int8(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToInt8 +.test("FromUInt8_NeverFails") +.forEach(in: [ + (getInt8(+0), getUInt8(+0)), + (getInt8(+127), getUInt8(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) } -FixedPointConversion_Release32_ToInt8.test("FromUInt8(127)_NeverTraps") { - let input = getUInt8(127) - let actual = Int8(input) - expectEqual(127, actual) +FixedPointConversion_Release32_ToInt8 +.test("FromUInt8_AlwaysTraps") +.forEach(in: [ + getUInt8(+128), + getUInt8(+255), +]) { + expectCrashLater() + _blackHole(Int8($0)) } -FixedPointConversion_Release32_ToInt8.test("FromUInt8(127)_NeverFails") { - let input = getUInt8(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromUInt8(128)_AlwaysTraps") { - let input = getUInt8(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromUInt8(128)_AlwaysFails") { - let input = getUInt8(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromUInt8(255)_AlwaysTraps") { - let input = getUInt8(255) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromUInt8(255)_AlwaysFails") { - let input = getUInt8(255) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt8 +.test("FromUInt8_AlwaysFails") +.forEach(in: [ + getUInt8(+128), + getUInt8(+255), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int8: (-128)...(127) +// MARK: Int8: (-128)...(+127) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt8.test("FromInt8(-128)_NeverTraps") { - let input = getInt8(-128) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromInt8(-128)_NeverFails") { - let input = getInt8(-128) - let actual = Int8(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromInt8(0)_NeverTraps") { - let input = getInt8(0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromInt8(0)_NeverFails") { - let input = getInt8(0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromInt8(127)_NeverTraps") { - let input = getInt8(127) - let actual = Int8(input) - expectEqual(127, actual) +FixedPointConversion_Release32_ToInt8 +.test("FromInt8_NeverTraps") +.forEach(in: [ + (getInt8(-128), getInt8(-128)), + (getInt8(+0), getInt8(+0)), + (getInt8(+127), getInt8(+127)), +]) { + expectEqual($0.0, Int8($0.1)) } -FixedPointConversion_Release32_ToInt8.test("FromInt8(127)_NeverFails") { - let input = getInt8(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Release32_ToInt8 +.test("FromInt8_NeverFails") +.forEach(in: [ + (getInt8(-128), getInt8(-128)), + (getInt8(+0), getInt8(+0)), + (getInt8(+127), getInt8(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt16: (0)...(65535) +// MARK: UInt16: (+0)...(+65535) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt8.test("FromUInt16(0)_NeverTraps") { - let input = getUInt16(0) - let actual = Int8(input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToInt8 +.test("FromUInt16_NeverTraps") +.forEach(in: [ + (getInt8(+0), getUInt16(+0)), + (getInt8(+127), getUInt16(+127)), +]) { + expectEqual($0.0, Int8($0.1)) } -FixedPointConversion_Release32_ToInt8.test("FromUInt16(0)_NeverFails") { - let input = getUInt16(0) - let actual = Int8(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToInt8 +.test("FromUInt16_NeverFails") +.forEach(in: [ + (getInt8(+0), getUInt16(+0)), + (getInt8(+127), getUInt16(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) } -FixedPointConversion_Release32_ToInt8.test("FromUInt16(127)_NeverTraps") { - let input = getUInt16(127) - let actual = Int8(input) - expectEqual(127, actual) +FixedPointConversion_Release32_ToInt8 +.test("FromUInt16_AlwaysTraps") +.forEach(in: [ + getUInt16(+128), + getUInt16(+65535), +]) { + expectCrashLater() + _blackHole(Int8($0)) } -FixedPointConversion_Release32_ToInt8.test("FromUInt16(127)_NeverFails") { - let input = getUInt16(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromUInt16(128)_AlwaysTraps") { - let input = getUInt16(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromUInt16(128)_AlwaysFails") { - let input = getUInt16(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromUInt16(65535)_AlwaysTraps") { - let input = getUInt16(65535) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromUInt16(65535)_AlwaysFails") { - let input = getUInt16(65535) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt8 +.test("FromUInt16_AlwaysFails") +.forEach(in: [ + getUInt16(+128), + getUInt16(+65535), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int16: (-32768)...(32767) +// MARK: Int16: (-32768)...(+32767) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt8.test("FromInt16(-32768)_AlwaysTraps") { - let input = getInt16(-32768) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromInt16(-32768)_AlwaysFails") { - let input = getInt16(-32768) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromInt16(-129)_AlwaysTraps") { - let input = getInt16(-129) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromInt16(-129)_AlwaysFails") { - let input = getInt16(-129) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromInt16(-128)_NeverTraps") { - let input = getInt16(-128) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromInt16(-128)_NeverFails") { - let input = getInt16(-128) - let actual = Int8(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromInt16(0)_NeverTraps") { - let input = getInt16(0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromInt16(0)_NeverFails") { - let input = getInt16(0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromInt16(127)_NeverTraps") { - let input = getInt16(127) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromInt16(127)_NeverFails") { - let input = getInt16(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromInt16(128)_AlwaysTraps") { - let input = getInt16(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromInt16(128)_AlwaysFails") { - let input = getInt16(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromInt16(32767)_AlwaysTraps") { - let input = getInt16(32767) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromInt16(32767)_AlwaysFails") { - let input = getInt16(32767) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt8 +.test("FromInt16_NeverTraps") +.forEach(in: [ + (getInt8(-128), getInt16(-128)), + (getInt8(+0), getInt16(+0)), + (getInt8(+127), getInt16(+127)), +]) { + expectEqual($0.0, Int8($0.1)) +} + +FixedPointConversion_Release32_ToInt8 +.test("FromInt16_NeverFails") +.forEach(in: [ + (getInt8(-128), getInt16(-128)), + (getInt8(+0), getInt16(+0)), + (getInt8(+127), getInt16(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToInt8 +.test("FromInt16_AlwaysTraps") +.forEach(in: [ + getInt16(-32768), + getInt16(-129), + getInt16(+128), + getInt16(+32767), +]) { + expectCrashLater() + _blackHole(Int8($0)) +} + +FixedPointConversion_Release32_ToInt8 +.test("FromInt16_AlwaysFails") +.forEach(in: [ + getInt16(-32768), + getInt16(-129), + getInt16(+128), + getInt16(+32767), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt32: (0)...(4294967295) +// MARK: UInt32: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt8.test("FromUInt32(0)_NeverTraps") { - let input = getUInt32(0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromUInt32(0)_NeverFails") { - let input = getUInt32(0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromUInt32(127)_NeverTraps") { - let input = getUInt32(127) - let actual = Int8(input) - expectEqual(127, actual) +FixedPointConversion_Release32_ToInt8 +.test("FromUInt32_NeverTraps") +.forEach(in: [ + (getInt8(+0), getUInt32(+0)), + (getInt8(+127), getUInt32(+127)), +]) { + expectEqual($0.0, Int8($0.1)) } -FixedPointConversion_Release32_ToInt8.test("FromUInt32(127)_NeverFails") { - let input = getUInt32(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Release32_ToInt8 +.test("FromUInt32_NeverFails") +.forEach(in: [ + (getInt8(+0), getUInt32(+0)), + (getInt8(+127), getUInt32(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) } -FixedPointConversion_Release32_ToInt8.test("FromUInt32(128)_AlwaysTraps") { - let input = getUInt32(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } +FixedPointConversion_Release32_ToInt8 +.test("FromUInt32_AlwaysTraps") +.forEach(in: [ + getUInt32(+128), + getUInt32(+4294967295), +]) { + expectCrashLater() + _blackHole(Int8($0)) } -FixedPointConversion_Release32_ToInt8.test("FromUInt32(128)_AlwaysFails") { - let input = getUInt32(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromUInt32(4294967295)_AlwaysTraps") { - let input = getUInt32(4294967295) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromUInt32(4294967295)_AlwaysFails") { - let input = getUInt32(4294967295) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt8 +.test("FromUInt32_AlwaysFails") +.forEach(in: [ + getUInt32(+128), + getUInt32(+4294967295), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int32: (-2147483648)...(2147483647) +// MARK: Int32: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt8.test("FromInt32(-2147483648)_AlwaysTraps") { - let input = getInt32(-2147483648) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromInt32(-2147483648)_AlwaysFails") { - let input = getInt32(-2147483648) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromInt32(-129)_AlwaysTraps") { - let input = getInt32(-129) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromInt32(-129)_AlwaysFails") { - let input = getInt32(-129) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromInt32(-128)_NeverTraps") { - let input = getInt32(-128) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromInt32(-128)_NeverFails") { - let input = getInt32(-128) - let actual = Int8(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromInt32(0)_NeverTraps") { - let input = getInt32(0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromInt32(0)_NeverFails") { - let input = getInt32(0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromInt32(127)_NeverTraps") { - let input = getInt32(127) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromInt32(127)_NeverFails") { - let input = getInt32(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromInt32(128)_AlwaysTraps") { - let input = getInt32(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromInt32(128)_AlwaysFails") { - let input = getInt32(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromInt32(2147483647)_AlwaysTraps") { - let input = getInt32(2147483647) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromInt32(2147483647)_AlwaysFails") { - let input = getInt32(2147483647) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt8 +.test("FromInt32_NeverTraps") +.forEach(in: [ + (getInt8(-128), getInt32(-128)), + (getInt8(+0), getInt32(+0)), + (getInt8(+127), getInt32(+127)), +]) { + expectEqual($0.0, Int8($0.1)) +} + +FixedPointConversion_Release32_ToInt8 +.test("FromInt32_NeverFails") +.forEach(in: [ + (getInt8(-128), getInt32(-128)), + (getInt8(+0), getInt32(+0)), + (getInt8(+127), getInt32(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToInt8 +.test("FromInt32_AlwaysTraps") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-129), + getInt32(+128), + getInt32(+2147483647), +]) { + expectCrashLater() + _blackHole(Int8($0)) +} + +FixedPointConversion_Release32_ToInt8 +.test("FromInt32_AlwaysFails") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-129), + getInt32(+128), + getInt32(+2147483647), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt64: (0)...(18446744073709551615) +// MARK: UInt64: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt8.test("FromUInt64(0)_NeverTraps") { - let input = getUInt64(0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromUInt64(0)_NeverFails") { - let input = getUInt64(0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromUInt64(127)_NeverTraps") { - let input = getUInt64(127) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromUInt64(127)_NeverFails") { - let input = getUInt64(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromUInt64(128)_AlwaysTraps") { - let input = getUInt64(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } +FixedPointConversion_Release32_ToInt8 +.test("FromUInt64_NeverTraps") +.forEach(in: [ + (getInt8(+0), getUInt64(+0)), + (getInt8(+127), getUInt64(+127)), +]) { + expectEqual($0.0, Int8($0.1)) } -FixedPointConversion_Release32_ToInt8.test("FromUInt64(128)_AlwaysFails") { - let input = getUInt64(128) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt8 +.test("FromUInt64_NeverFails") +.forEach(in: [ + (getInt8(+0), getUInt64(+0)), + (getInt8(+127), getUInt64(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) } -FixedPointConversion_Release32_ToInt8.test("FromUInt64(18446744073709551615)_AlwaysTraps") { - let input = getUInt64(18446744073709551615) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } +FixedPointConversion_Release32_ToInt8 +.test("FromUInt64_AlwaysTraps") +.forEach(in: [ + getUInt64(+128), + getUInt64(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(Int8($0)) } -FixedPointConversion_Release32_ToInt8.test("FromUInt64(18446744073709551615)_AlwaysFails") { - let input = getUInt64(18446744073709551615) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt8 +.test("FromUInt64_AlwaysFails") +.forEach(in: [ + getUInt64(+128), + getUInt64(+18446744073709551615), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int64: (-9223372036854775808)...(9223372036854775807) +// MARK: Int64: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt8.test("FromInt64(-9223372036854775808)_AlwaysTraps") { - let input = getInt64(-9223372036854775808) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromInt64(-9223372036854775808)_AlwaysFails") { - let input = getInt64(-9223372036854775808) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromInt64(-129)_AlwaysTraps") { - let input = getInt64(-129) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromInt64(-129)_AlwaysFails") { - let input = getInt64(-129) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromInt64(-128)_NeverTraps") { - let input = getInt64(-128) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromInt64(-128)_NeverFails") { - let input = getInt64(-128) - let actual = Int8(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromInt64(0)_NeverTraps") { - let input = getInt64(0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromInt64(0)_NeverFails") { - let input = getInt64(0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromInt64(127)_NeverTraps") { - let input = getInt64(127) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromInt64(127)_NeverFails") { - let input = getInt64(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromInt64(128)_AlwaysTraps") { - let input = getInt64(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromInt64(128)_AlwaysFails") { - let input = getInt64(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromInt64(9223372036854775807)_AlwaysTraps") { - let input = getInt64(9223372036854775807) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromInt64(9223372036854775807)_AlwaysFails") { - let input = getInt64(9223372036854775807) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt8 +.test("FromInt64_NeverTraps") +.forEach(in: [ + (getInt8(-128), getInt64(-128)), + (getInt8(+0), getInt64(+0)), + (getInt8(+127), getInt64(+127)), +]) { + expectEqual($0.0, Int8($0.1)) +} + +FixedPointConversion_Release32_ToInt8 +.test("FromInt64_NeverFails") +.forEach(in: [ + (getInt8(-128), getInt64(-128)), + (getInt8(+0), getInt64(+0)), + (getInt8(+127), getInt64(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToInt8 +.test("FromInt64_AlwaysTraps") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-129), + getInt64(+128), + getInt64(+9223372036854775807), +]) { + expectCrashLater() + _blackHole(Int8($0)) +} + +FixedPointConversion_Release32_ToInt8 +.test("FromInt64_AlwaysFails") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-129), + getInt64(+128), + getInt64(+9223372036854775807), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt: (0)...(4294967295) +// MARK: UInt: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt8.test("FromUInt(0)_NeverTraps") { - let input = getUInt(0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromUInt(0)_NeverFails") { - let input = getUInt(0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromUInt(127)_NeverTraps") { - let input = getUInt(127) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromUInt(127)_NeverFails") { - let input = getUInt(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromUInt(128)_AlwaysTraps") { - let input = getUInt(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } +FixedPointConversion_Release32_ToInt8 +.test("FromUInt_NeverTraps") +.forEach(in: [ + (getInt8(+0), getUInt(+0)), + (getInt8(+127), getUInt(+127)), +]) { + expectEqual($0.0, Int8($0.1)) } -FixedPointConversion_Release32_ToInt8.test("FromUInt(128)_AlwaysFails") { - let input = getUInt(128) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt8 +.test("FromUInt_NeverFails") +.forEach(in: [ + (getInt8(+0), getUInt(+0)), + (getInt8(+127), getUInt(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) } -FixedPointConversion_Release32_ToInt8.test("FromUInt(4294967295)_AlwaysTraps") { - let input = getUInt(4294967295) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } +FixedPointConversion_Release32_ToInt8 +.test("FromUInt_AlwaysTraps") +.forEach(in: [ + getUInt(+128), + getUInt(+4294967295), +]) { + expectCrashLater() + _blackHole(Int8($0)) } -FixedPointConversion_Release32_ToInt8.test("FromUInt(4294967295)_AlwaysFails") { - let input = getUInt(4294967295) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt8 +.test("FromUInt_AlwaysFails") +.forEach(in: [ + getUInt(+128), + getUInt(+4294967295), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int: (-2147483648)...(2147483647) +// MARK: Int: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt8.test("FromInt(-2147483648)_AlwaysTraps") { - let input = getInt(-2147483648) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromInt(-2147483648)_AlwaysFails") { - let input = getInt(-2147483648) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromInt(-129)_AlwaysTraps") { - let input = getInt(-129) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromInt(-129)_AlwaysFails") { - let input = getInt(-129) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromInt(-128)_NeverTraps") { - let input = getInt(-128) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromInt(-128)_NeverFails") { - let input = getInt(-128) - let actual = Int8(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromInt(0)_NeverTraps") { - let input = getInt(0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromInt(0)_NeverFails") { - let input = getInt(0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromInt(127)_NeverTraps") { - let input = getInt(127) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromInt(127)_NeverFails") { - let input = getInt(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromInt(128)_AlwaysTraps") { - let input = getInt(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromInt(128)_AlwaysFails") { - let input = getInt(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromInt(2147483647)_AlwaysTraps") { - let input = getInt(2147483647) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromInt(2147483647)_AlwaysFails") { - let input = getInt(2147483647) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt8 +.test("FromInt_NeverTraps") +.forEach(in: [ + (getInt8(-128), getInt(-128)), + (getInt8(+0), getInt(+0)), + (getInt8(+127), getInt(+127)), +]) { + expectEqual($0.0, Int8($0.1)) +} + +FixedPointConversion_Release32_ToInt8 +.test("FromInt_NeverFails") +.forEach(in: [ + (getInt8(-128), getInt(-128)), + (getInt8(+0), getInt(+0)), + (getInt8(+127), getInt(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToInt8 +.test("FromInt_AlwaysTraps") +.forEach(in: [ + getInt(-2147483648), + getInt(-129), + getInt(+128), + getInt(+2147483647), +]) { + expectCrashLater() + _blackHole(Int8($0)) +} + +FixedPointConversion_Release32_ToInt8 +.test("FromInt_AlwaysFails") +.forEach(in: [ + getInt(-2147483648), + getInt(-129), + getInt(+128), + getInt(+2147483647), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float16: (-2047)...(2047) +// MARK: Float16: (-2047)...(+2047) //===----------------------------------------------------------------------===// #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -FixedPointConversion_Release32_ToInt8.test("FromFloat16(-2047)_AlwaysTraps") { - let input = getFloat16(-2047) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat16(-2047)_AlwaysFails") { - let input = getFloat16(-2047) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat16(-129)_AlwaysTraps") { - let input = getFloat16(-129) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat16(-129)_AlwaysFails") { - let input = getFloat16(-129) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat16(-128.5)_NeverTraps") { - let input = getFloat16(-128.5) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat16(-128.5)_AlwaysFails") { - let input = getFloat16(-128.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat16(-128)_NeverTraps") { - let input = getFloat16(-128) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat16(-128)_NeverFails") { - let input = getFloat16(-128) - let actual = Int8(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat16(-0.5)_NeverTraps") { - let input = getFloat16(-0.5) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat16(-0.5)_AlwaysFails") { - let input = getFloat16(-0.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat16(-0.0)_NeverTraps") { - let input = getFloat16(-0.0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat16(-0.0)_NeverFails") { - let input = getFloat16(-0.0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat16(0.0)_NeverTraps") { - let input = getFloat16(0.0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat16(0.0)_NeverFails") { - let input = getFloat16(0.0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat16(0.5)_NeverTraps") { - let input = getFloat16(0.5) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat16(0.5)_AlwaysFails") { - let input = getFloat16(0.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat16(127)_NeverTraps") { - let input = getFloat16(127) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat16(127)_NeverFails") { - let input = getFloat16(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat16(127.5)_NeverTraps") { - let input = getFloat16(127.5) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat16(127.5)_AlwaysFails") { - let input = getFloat16(127.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat16(128)_AlwaysTraps") { - let input = getFloat16(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat16(128)_AlwaysFails") { - let input = getFloat16(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat16(255.5)_AlwaysTraps") { - let input = getFloat16(255.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat16(255.5)_AlwaysFails") { - let input = getFloat16(255.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat16(2047)_AlwaysTraps") { - let input = getFloat16(2047) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat16(2047)_AlwaysFails") { - let input = getFloat16(2047) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat16(-.infinity)_AlwaysTraps") { - let input = getFloat16(-.infinity) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat16(-.infinity)_AlwaysFails") { - let input = getFloat16(-.infinity) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat16(+.infinity)_AlwaysTraps") { - let input = getFloat16(+.infinity) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat16(+.infinity)_AlwaysFails") { - let input = getFloat16(+.infinity) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat16(-.nan)_AlwaysTraps") { - let input = getFloat16(-.nan) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat16(-.nan)_AlwaysFails") { - let input = getFloat16(-.nan) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat16(+.nan)_AlwaysTraps") { - let input = getFloat16(+.nan) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat16(+.nan)_AlwaysFails") { - let input = getFloat16(+.nan) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat16(-.signalingNaN)_AlwaysTraps") { - let input = getFloat16(-.signalingNaN) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat16(-.signalingNaN)_AlwaysFails") { - let input = getFloat16(-.signalingNaN) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat16(+.signalingNaN)_AlwaysTraps") { - let input = getFloat16(+.signalingNaN) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat16(+.signalingNaN)_AlwaysFails") { - let input = getFloat16(+.signalingNaN) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt8 +.test("FromFloat16_NeverTraps") +.forEach(in: [ + (getInt8(-128), getFloat16(-128.5)), + (getInt8(-128), getFloat16(-128)), + (getInt8(+0), getFloat16(-0.5)), + (getInt8(+0), getFloat16(-0)), + (getInt8(+0), getFloat16(+0)), + (getInt8(+0), getFloat16(+0.5)), + (getInt8(+127), getFloat16(+127)), + (getInt8(+127), getFloat16(+127.5)), +]) { + expectEqual($0.0, Int8($0.1)) +} + +FixedPointConversion_Release32_ToInt8 +.test("FromFloat16_NeverFails") +.forEach(in: [ + (getInt8(-128), getFloat16(-128)), + (getInt8(+0), getFloat16(-0)), + (getInt8(+0), getFloat16(+0)), + (getInt8(+127), getFloat16(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToInt8 +.test("FromFloat16_AlwaysTraps") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-129), + getFloat16(+128), + getFloat16(+255.5), + getFloat16(+2047), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int8($0)) +} + +FixedPointConversion_Release32_ToInt8 +.test("FromFloat16_AlwaysFails") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-129), + getFloat16(-128.5), + getFloat16(-0.5), + getFloat16(+0.5), + getFloat16(+127.5), + getFloat16(+128), + getFloat16(+255.5), + getFloat16(+2047), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectNil(Int8(exactly: $0)) } } #endif // Float16 //===----------------------------------------------------------------------===// -// MARK: Float32: (-16777215)...(16777215) +// MARK: Float32: (-16777215)...(+16777215) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt8.test("FromFloat32(-16777215)_AlwaysTraps") { - let input = getFloat32(-16777215) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(-16777215)_AlwaysFails") { - let input = getFloat32(-16777215) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(-32768.5)_AlwaysTraps") { - let input = getFloat32(-32768.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(-32768.5)_AlwaysFails") { - let input = getFloat32(-32768.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(-129)_AlwaysTraps") { - let input = getFloat32(-129) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(-129)_AlwaysFails") { - let input = getFloat32(-129) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(-128.5)_NeverTraps") { - let input = getFloat32(-128.5) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(-128.5)_AlwaysFails") { - let input = getFloat32(-128.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(-128)_NeverTraps") { - let input = getFloat32(-128) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(-128)_NeverFails") { - let input = getFloat32(-128) - let actual = Int8(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(-0.5)_NeverTraps") { - let input = getFloat32(-0.5) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(-0.5)_AlwaysFails") { - let input = getFloat32(-0.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(-0.0)_NeverTraps") { - let input = getFloat32(-0.0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(-0.0)_NeverFails") { - let input = getFloat32(-0.0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(0.0)_NeverTraps") { - let input = getFloat32(0.0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(0.0)_NeverFails") { - let input = getFloat32(0.0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(0.5)_NeverTraps") { - let input = getFloat32(0.5) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(0.5)_AlwaysFails") { - let input = getFloat32(0.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(127)_NeverTraps") { - let input = getFloat32(127) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(127)_NeverFails") { - let input = getFloat32(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(127.5)_NeverTraps") { - let input = getFloat32(127.5) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(127.5)_AlwaysFails") { - let input = getFloat32(127.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(128)_AlwaysTraps") { - let input = getFloat32(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(128)_AlwaysFails") { - let input = getFloat32(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(255.5)_AlwaysTraps") { - let input = getFloat32(255.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(255.5)_AlwaysFails") { - let input = getFloat32(255.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(32767.5)_AlwaysTraps") { - let input = getFloat32(32767.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(32767.5)_AlwaysFails") { - let input = getFloat32(32767.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(65535.5)_AlwaysTraps") { - let input = getFloat32(65535.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(65535.5)_AlwaysFails") { - let input = getFloat32(65535.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(16777215)_AlwaysTraps") { - let input = getFloat32(16777215) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(16777215)_AlwaysFails") { - let input = getFloat32(16777215) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(-.infinity)_AlwaysTraps") { - let input = getFloat32(-.infinity) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(-.infinity)_AlwaysFails") { - let input = getFloat32(-.infinity) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(+.infinity)_AlwaysTraps") { - let input = getFloat32(+.infinity) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(+.infinity)_AlwaysFails") { - let input = getFloat32(+.infinity) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(-.nan)_AlwaysTraps") { - let input = getFloat32(-.nan) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(-.nan)_AlwaysFails") { - let input = getFloat32(-.nan) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(+.nan)_AlwaysTraps") { - let input = getFloat32(+.nan) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(+.nan)_AlwaysFails") { - let input = getFloat32(+.nan) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(-.signalingNaN)_AlwaysTraps") { - let input = getFloat32(-.signalingNaN) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(-.signalingNaN)_AlwaysFails") { - let input = getFloat32(-.signalingNaN) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(+.signalingNaN)_AlwaysTraps") { - let input = getFloat32(+.signalingNaN) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat32(+.signalingNaN)_AlwaysFails") { - let input = getFloat32(+.signalingNaN) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt8 +.test("FromFloat32_NeverTraps") +.forEach(in: [ + (getInt8(-128), getFloat32(-128.5)), + (getInt8(-128), getFloat32(-128)), + (getInt8(+0), getFloat32(-0.5)), + (getInt8(+0), getFloat32(+0)), + (getInt8(+0), getFloat32(-0)), + (getInt8(+0), getFloat32(+0.5)), + (getInt8(+127), getFloat32(+127)), + (getInt8(+127), getFloat32(+127.5)), +]) { + expectEqual($0.0, Int8($0.1)) +} + +FixedPointConversion_Release32_ToInt8 +.test("FromFloat32_NeverFails") +.forEach(in: [ + (getInt8(-128), getFloat32(-128)), + (getInt8(+0), getFloat32(+0)), + (getInt8(+0), getFloat32(-0)), + (getInt8(+127), getFloat32(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToInt8 +.test("FromFloat32_AlwaysTraps") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-129), + getFloat32(+128), + getFloat32(+255.5), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(+16777215), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int8($0)) +} + +FixedPointConversion_Release32_ToInt8 +.test("FromFloat32_AlwaysFails") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-129), + getFloat32(-128.5), + getFloat32(-0.5), + getFloat32(+0.5), + getFloat32(+127.5), + getFloat32(+128), + getFloat32(+255.5), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(+16777215), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float64: (-9007199254740991)...(9007199254740991) +// MARK: Float64: (-9007199254740991)...(+9007199254740991) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToInt8.test("FromFloat64(-9007199254740991)_AlwaysTraps") { - let input = getFloat64(-9007199254740991) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(-9007199254740991)_AlwaysFails") { - let input = getFloat64(-9007199254740991) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(-32768.5)_AlwaysTraps") { - let input = getFloat64(-32768.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(-32768.5)_AlwaysFails") { - let input = getFloat64(-32768.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(-129)_AlwaysTraps") { - let input = getFloat64(-129) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(-129)_AlwaysFails") { - let input = getFloat64(-129) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(-128.5)_NeverTraps") { - let input = getFloat64(-128.5) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(-128.5)_AlwaysFails") { - let input = getFloat64(-128.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(-128)_NeverTraps") { - let input = getFloat64(-128) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(-128)_NeverFails") { - let input = getFloat64(-128) - let actual = Int8(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(-0.5)_NeverTraps") { - let input = getFloat64(-0.5) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(-0.5)_AlwaysFails") { - let input = getFloat64(-0.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(-0.0)_NeverTraps") { - let input = getFloat64(-0.0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(-0.0)_NeverFails") { - let input = getFloat64(-0.0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(0.0)_NeverTraps") { - let input = getFloat64(0.0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(0.0)_NeverFails") { - let input = getFloat64(0.0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(0.5)_NeverTraps") { - let input = getFloat64(0.5) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(0.5)_AlwaysFails") { - let input = getFloat64(0.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(127)_NeverTraps") { - let input = getFloat64(127) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(127)_NeverFails") { - let input = getFloat64(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(127.5)_NeverTraps") { - let input = getFloat64(127.5) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(127.5)_AlwaysFails") { - let input = getFloat64(127.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(128)_AlwaysTraps") { - let input = getFloat64(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(128)_AlwaysFails") { - let input = getFloat64(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(255.5)_AlwaysTraps") { - let input = getFloat64(255.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(255.5)_AlwaysFails") { - let input = getFloat64(255.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(32767.5)_AlwaysTraps") { - let input = getFloat64(32767.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(32767.5)_AlwaysFails") { - let input = getFloat64(32767.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(65535.5)_AlwaysTraps") { - let input = getFloat64(65535.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(65535.5)_AlwaysFails") { - let input = getFloat64(65535.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(9007199254740991)_AlwaysTraps") { - let input = getFloat64(9007199254740991) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(9007199254740991)_AlwaysFails") { - let input = getFloat64(9007199254740991) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(-.infinity)_AlwaysTraps") { - let input = getFloat64(-.infinity) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(-.infinity)_AlwaysFails") { - let input = getFloat64(-.infinity) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(+.infinity)_AlwaysTraps") { - let input = getFloat64(+.infinity) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(+.infinity)_AlwaysFails") { - let input = getFloat64(+.infinity) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(-.nan)_AlwaysTraps") { - let input = getFloat64(-.nan) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(-.nan)_AlwaysFails") { - let input = getFloat64(-.nan) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(+.nan)_AlwaysTraps") { - let input = getFloat64(+.nan) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(+.nan)_AlwaysFails") { - let input = getFloat64(+.nan) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(-.signalingNaN)_AlwaysTraps") { - let input = getFloat64(-.signalingNaN) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(-.signalingNaN)_AlwaysFails") { - let input = getFloat64(-.signalingNaN) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(+.signalingNaN)_AlwaysTraps") { - let input = getFloat64(+.signalingNaN) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat64(+.signalingNaN)_AlwaysFails") { - let input = getFloat64(+.signalingNaN) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt8 +.test("FromFloat64_NeverTraps") +.forEach(in: [ + (getInt8(-128), getFloat64(-128.5)), + (getInt8(-128), getFloat64(-128)), + (getInt8(+0), getFloat64(-0.5)), + (getInt8(+0), getFloat64(+0)), + (getInt8(+0), getFloat64(-0)), + (getInt8(+0), getFloat64(+0.5)), + (getInt8(+127), getFloat64(+127)), + (getInt8(+127), getFloat64(+127.5)), +]) { + expectEqual($0.0, Int8($0.1)) +} + +FixedPointConversion_Release32_ToInt8 +.test("FromFloat64_NeverFails") +.forEach(in: [ + (getInt8(-128), getFloat64(-128)), + (getInt8(+0), getFloat64(+0)), + (getInt8(+0), getFloat64(-0)), + (getInt8(+127), getFloat64(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToInt8 +.test("FromFloat64_AlwaysTraps") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-129), + getFloat64(+128), + getFloat64(+255.5), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int8($0)) +} + +FixedPointConversion_Release32_ToInt8 +.test("FromFloat64_AlwaysFails") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-129), + getFloat64(-128.5), + getFloat64(-0.5), + getFloat64(+0.5), + getFloat64(+127.5), + getFloat64(+128), + getFloat64(+255.5), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float80: (-18446744073709551615)...(18446744073709551615) +// MARK: Float80: (-18446744073709551615)...(+18446744073709551615) //===----------------------------------------------------------------------===// #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) -FixedPointConversion_Release32_ToInt8.test("FromFloat80(-18446744073709551615)_AlwaysTraps") { - let input = getFloat80(-18446744073709551615) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(-18446744073709551615)_AlwaysFails") { - let input = getFloat80(-18446744073709551615) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(-32768.5)_AlwaysTraps") { - let input = getFloat80(-32768.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(-32768.5)_AlwaysFails") { - let input = getFloat80(-32768.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(-129)_AlwaysTraps") { - let input = getFloat80(-129) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(-129)_AlwaysFails") { - let input = getFloat80(-129) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(-128.5)_NeverTraps") { - let input = getFloat80(-128.5) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(-128.5)_AlwaysFails") { - let input = getFloat80(-128.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(-128)_NeverTraps") { - let input = getFloat80(-128) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(-128)_NeverFails") { - let input = getFloat80(-128) - let actual = Int8(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(-0.5)_NeverTraps") { - let input = getFloat80(-0.5) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(-0.5)_AlwaysFails") { - let input = getFloat80(-0.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(-0.0)_NeverTraps") { - let input = getFloat80(-0.0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(-0.0)_NeverFails") { - let input = getFloat80(-0.0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(0.0)_NeverTraps") { - let input = getFloat80(0.0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(0.0)_NeverFails") { - let input = getFloat80(0.0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(0.5)_NeverTraps") { - let input = getFloat80(0.5) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(0.5)_AlwaysFails") { - let input = getFloat80(0.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(127)_NeverTraps") { - let input = getFloat80(127) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(127)_NeverFails") { - let input = getFloat80(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(127.5)_NeverTraps") { - let input = getFloat80(127.5) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(127.5)_AlwaysFails") { - let input = getFloat80(127.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(128)_AlwaysTraps") { - let input = getFloat80(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(128)_AlwaysFails") { - let input = getFloat80(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(255.5)_AlwaysTraps") { - let input = getFloat80(255.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(255.5)_AlwaysFails") { - let input = getFloat80(255.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(32767.5)_AlwaysTraps") { - let input = getFloat80(32767.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(32767.5)_AlwaysFails") { - let input = getFloat80(32767.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(65535.5)_AlwaysTraps") { - let input = getFloat80(65535.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(65535.5)_AlwaysFails") { - let input = getFloat80(65535.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(18446744073709551615)_AlwaysTraps") { - let input = getFloat80(18446744073709551615) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(18446744073709551615)_AlwaysFails") { - let input = getFloat80(18446744073709551615) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(-.infinity)_AlwaysTraps") { - let input = getFloat80(-.infinity) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(-.infinity)_AlwaysFails") { - let input = getFloat80(-.infinity) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(+.infinity)_AlwaysTraps") { - let input = getFloat80(+.infinity) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(+.infinity)_AlwaysFails") { - let input = getFloat80(+.infinity) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(-.nan)_AlwaysTraps") { - let input = getFloat80(-.nan) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(-.nan)_AlwaysFails") { - let input = getFloat80(-.nan) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(+.nan)_AlwaysTraps") { - let input = getFloat80(+.nan) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(+.nan)_AlwaysFails") { - let input = getFloat80(+.nan) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(-.signalingNaN)_AlwaysTraps") { - let input = getFloat80(-.signalingNaN) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(-.signalingNaN)_AlwaysFails") { - let input = getFloat80(-.signalingNaN) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(+.signalingNaN)_AlwaysTraps") { - let input = getFloat80(+.signalingNaN) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToInt8.test("FromFloat80(+.signalingNaN)_AlwaysFails") { - let input = getFloat80(+.signalingNaN) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToInt8 +.test("FromFloat80_NeverTraps") +.forEach(in: [ + (getInt8(-128), getFloat80(-128.5)), + (getInt8(-128), getFloat80(-128)), + (getInt8(+0), getFloat80(-0.5)), + (getInt8(+0), getFloat80(-0)), + (getInt8(+0), getFloat80(+0)), + (getInt8(+0), getFloat80(+0.5)), + (getInt8(+127), getFloat80(+127)), + (getInt8(+127), getFloat80(+127.5)), +]) { + expectEqual($0.0, Int8($0.1)) +} + +FixedPointConversion_Release32_ToInt8 +.test("FromFloat80_NeverFails") +.forEach(in: [ + (getInt8(-128), getFloat80(-128)), + (getInt8(+0), getFloat80(-0)), + (getInt8(+0), getFloat80(+0)), + (getInt8(+127), getFloat80(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToInt8 +.test("FromFloat80_AlwaysTraps") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-129), + getFloat80(+128), + getFloat80(+255.5), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int8($0)) +} + +FixedPointConversion_Release32_ToInt8 +.test("FromFloat80_AlwaysFails") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-129), + getFloat80(-128.5), + getFloat80(-0.5), + getFloat80(+0.5), + getFloat80(+127.5), + getFloat80(+128), + getFloat80(+255.5), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectNil(Int8(exactly: $0)) } #endif // Float80 diff --git a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release32_ToUInt.swift b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release32_ToUInt.swift index f11cf53533b62..3c5b958be115e 100644 --- a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release32_ToUInt.swift +++ b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release32_ToUInt.swift @@ -5,7 +5,7 @@ // //===----------------------------------------------------------------------===// // -// REQUIRES: executable_test, long_test +// REQUIRES: executable_test // REQUIRES: PTRSIZE=32 // RUN: %target-run-simple-swift(-O) // END. @@ -14,1564 +14,640 @@ import StdlibUnittest -let FixedPointConversion_Release32_ToUInt = TestSuite("FixedPointConversion_Release32_ToUInt") +let FixedPointConversion_Release32_ToUInt = TestSuite( + "FixedPointConversion_Release32_ToUInt" +) //===----------------------------------------------------------------------===// -// MARK: UInt8: (0)...(255) +// MARK: UInt8: (+0)...(+255) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt.test("FromUInt8(0)_NeverTraps") { - let input = getUInt8(0) - let actual = UInt(input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToUInt +.test("FromUInt8_NeverTraps") +.forEach(in: [ + (getUInt(+0), getUInt8(+0)), + (getUInt(+255), getUInt8(+255)), +]) { + expectEqual($0.0, UInt($0.1)) } -FixedPointConversion_Release32_ToUInt.test("FromUInt8(0)_NeverFails") { - let input = getUInt8(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromUInt8(255)_NeverTraps") { - let input = getUInt8(255) - let actual = UInt(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromUInt8(255)_NeverFails") { - let input = getUInt8(255) - let actual = UInt(exactly: input) - expectEqual(255, actual) +FixedPointConversion_Release32_ToUInt +.test("FromUInt8_NeverFails") +.forEach(in: [ + (getUInt(+0), getUInt8(+0)), + (getUInt(+255), getUInt8(+255)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int8: (-128)...(127) +// MARK: Int8: (-128)...(+127) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt.test("FromInt8(-128)_AlwaysTraps") { - let input = getInt8(-128) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } +FixedPointConversion_Release32_ToUInt +.test("FromInt8_NeverTraps") +.forEach(in: [ + (getUInt(+0), getInt8(+0)), + (getUInt(+127), getInt8(+127)), +]) { + expectEqual($0.0, UInt($0.1)) } -FixedPointConversion_Release32_ToUInt.test("FromInt8(-128)_AlwaysFails") { - let input = getInt8(-128) - let actual = UInt(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt +.test("FromInt8_NeverFails") +.forEach(in: [ + (getUInt(+0), getInt8(+0)), + (getUInt(+127), getInt8(+127)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) } -FixedPointConversion_Release32_ToUInt.test("FromInt8(-1)_AlwaysTraps") { - let input = getInt8(-1) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } +FixedPointConversion_Release32_ToUInt +.test("FromInt8_AlwaysTraps") +.forEach(in: [ + getInt8(-128), + getInt8(-1), +]) { + expectCrashLater() + _blackHole(UInt($0)) } -FixedPointConversion_Release32_ToUInt.test("FromInt8(-1)_AlwaysFails") { - let input = getInt8(-1) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromInt8(0)_NeverTraps") { - let input = getInt8(0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromInt8(0)_NeverFails") { - let input = getInt8(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromInt8(127)_NeverTraps") { - let input = getInt8(127) - let actual = UInt(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromInt8(127)_NeverFails") { - let input = getInt8(127) - let actual = UInt(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Release32_ToUInt +.test("FromInt8_AlwaysFails") +.forEach(in: [ + getInt8(-128), + getInt8(-1), +]) { + expectNil(UInt(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt16: (0)...(65535) +// MARK: UInt16: (+0)...(+65535) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt.test("FromUInt16(0)_NeverTraps") { - let input = getUInt16(0) - let actual = UInt(input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToUInt +.test("FromUInt16_NeverTraps") +.forEach(in: [ + (getUInt(+0), getUInt16(+0)), + (getUInt(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, UInt($0.1)) } -FixedPointConversion_Release32_ToUInt.test("FromUInt16(0)_NeverFails") { - let input = getUInt16(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromUInt16(65535)_NeverTraps") { - let input = getUInt16(65535) - let actual = UInt(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromUInt16(65535)_NeverFails") { - let input = getUInt16(65535) - let actual = UInt(exactly: input) - expectEqual(65535, actual) +FixedPointConversion_Release32_ToUInt +.test("FromUInt16_NeverFails") +.forEach(in: [ + (getUInt(+0), getUInt16(+0)), + (getUInt(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int16: (-32768)...(32767) +// MARK: Int16: (-32768)...(+32767) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt.test("FromInt16(-32768)_AlwaysTraps") { - let input = getInt16(-32768) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromInt16(-32768)_AlwaysFails") { - let input = getInt16(-32768) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromInt16(-1)_AlwaysTraps") { - let input = getInt16(-1) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromInt16(-1)_AlwaysFails") { - let input = getInt16(-1) - let actual = UInt(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt +.test("FromInt16_NeverTraps") +.forEach(in: [ + (getUInt(+0), getInt16(+0)), + (getUInt(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, UInt($0.1)) } -FixedPointConversion_Release32_ToUInt.test("FromInt16(0)_NeverTraps") { - let input = getInt16(0) - let actual = UInt(input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToUInt +.test("FromInt16_NeverFails") +.forEach(in: [ + (getUInt(+0), getInt16(+0)), + (getUInt(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) } -FixedPointConversion_Release32_ToUInt.test("FromInt16(0)_NeverFails") { - let input = getInt16(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToUInt +.test("FromInt16_AlwaysTraps") +.forEach(in: [ + getInt16(-32768), + getInt16(-1), +]) { + expectCrashLater() + _blackHole(UInt($0)) } -FixedPointConversion_Release32_ToUInt.test("FromInt16(32767)_NeverTraps") { - let input = getInt16(32767) - let actual = UInt(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromInt16(32767)_NeverFails") { - let input = getInt16(32767) - let actual = UInt(exactly: input) - expectEqual(32767, actual) +FixedPointConversion_Release32_ToUInt +.test("FromInt16_AlwaysFails") +.forEach(in: [ + getInt16(-32768), + getInt16(-1), +]) { + expectNil(UInt(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt32: (0)...(4294967295) +// MARK: UInt32: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt.test("FromUInt32(0)_NeverTraps") { - let input = getUInt32(0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromUInt32(0)_NeverFails") { - let input = getUInt32(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromUInt32(4294967295)_NeverTraps") { - let input = getUInt32(4294967295) - let actual = UInt(input) - expectEqual(4294967295, actual) +FixedPointConversion_Release32_ToUInt +.test("FromUInt32_NeverTraps") +.forEach(in: [ + (getUInt(+0), getUInt32(+0)), + (getUInt(+4294967295), getUInt32(+4294967295)), +]) { + expectEqual($0.0, UInt($0.1)) } -FixedPointConversion_Release32_ToUInt.test("FromUInt32(4294967295)_NeverFails") { - let input = getUInt32(4294967295) - let actual = UInt(exactly: input) - expectEqual(4294967295, actual) +FixedPointConversion_Release32_ToUInt +.test("FromUInt32_NeverFails") +.forEach(in: [ + (getUInt(+0), getUInt32(+0)), + (getUInt(+4294967295), getUInt32(+4294967295)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int32: (-2147483648)...(2147483647) +// MARK: Int32: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt.test("FromInt32(-2147483648)_AlwaysTraps") { - let input = getInt32(-2147483648) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromInt32(-2147483648)_AlwaysFails") { - let input = getInt32(-2147483648) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromInt32(-1)_AlwaysTraps") { - let input = getInt32(-1) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } +FixedPointConversion_Release32_ToUInt +.test("FromInt32_NeverTraps") +.forEach(in: [ + (getUInt(+0), getInt32(+0)), + (getUInt(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, UInt($0.1)) } -FixedPointConversion_Release32_ToUInt.test("FromInt32(-1)_AlwaysFails") { - let input = getInt32(-1) - let actual = UInt(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt +.test("FromInt32_NeverFails") +.forEach(in: [ + (getUInt(+0), getInt32(+0)), + (getUInt(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) } -FixedPointConversion_Release32_ToUInt.test("FromInt32(0)_NeverTraps") { - let input = getInt32(0) - let actual = UInt(input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToUInt +.test("FromInt32_AlwaysTraps") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-1), +]) { + expectCrashLater() + _blackHole(UInt($0)) } -FixedPointConversion_Release32_ToUInt.test("FromInt32(0)_NeverFails") { - let input = getInt32(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromInt32(2147483647)_NeverTraps") { - let input = getInt32(2147483647) - let actual = UInt(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromInt32(2147483647)_NeverFails") { - let input = getInt32(2147483647) - let actual = UInt(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Release32_ToUInt +.test("FromInt32_AlwaysFails") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-1), +]) { + expectNil(UInt(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt64: (0)...(18446744073709551615) +// MARK: UInt64: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt.test("FromUInt64(0)_NeverTraps") { - let input = getUInt64(0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromUInt64(0)_NeverFails") { - let input = getUInt64(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToUInt +.test("FromUInt64_NeverTraps") +.forEach(in: [ + (getUInt(+0), getUInt64(+0)), + (getUInt(+4294967295), getUInt64(+4294967295)), +]) { + expectEqual($0.0, UInt($0.1)) } -FixedPointConversion_Release32_ToUInt.test("FromUInt64(4294967295)_NeverTraps") { - let input = getUInt64(4294967295) - let actual = UInt(input) - expectEqual(4294967295, actual) +FixedPointConversion_Release32_ToUInt +.test("FromUInt64_NeverFails") +.forEach(in: [ + (getUInt(+0), getUInt64(+0)), + (getUInt(+4294967295), getUInt64(+4294967295)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) } -FixedPointConversion_Release32_ToUInt.test("FromUInt64(4294967295)_NeverFails") { - let input = getUInt64(4294967295) - let actual = UInt(exactly: input) - expectEqual(4294967295, actual) +FixedPointConversion_Release32_ToUInt +.test("FromUInt64_AlwaysTraps") +.forEach(in: [ + getUInt64(+4294967296), + getUInt64(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(UInt($0)) } -FixedPointConversion_Release32_ToUInt.test("FromUInt64(4294967296)_AlwaysTraps") { - let input = getUInt64(4294967296) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromUInt64(4294967296)_AlwaysFails") { - let input = getUInt64(4294967296) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromUInt64(18446744073709551615)_AlwaysTraps") { - let input = getUInt64(18446744073709551615) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromUInt64(18446744073709551615)_AlwaysFails") { - let input = getUInt64(18446744073709551615) - let actual = UInt(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt +.test("FromUInt64_AlwaysFails") +.forEach(in: [ + getUInt64(+4294967296), + getUInt64(+18446744073709551615), +]) { + expectNil(UInt(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int64: (-9223372036854775808)...(9223372036854775807) +// MARK: Int64: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt.test("FromInt64(-9223372036854775808)_AlwaysTraps") { - let input = getInt64(-9223372036854775808) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromInt64(-9223372036854775808)_AlwaysFails") { - let input = getInt64(-9223372036854775808) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromInt64(-1)_AlwaysTraps") { - let input = getInt64(-1) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromInt64(-1)_AlwaysFails") { - let input = getInt64(-1) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromInt64(0)_NeverTraps") { - let input = getInt64(0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromInt64(0)_NeverFails") { - let input = getInt64(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromInt64(4294967295)_NeverTraps") { - let input = getInt64(4294967295) - let actual = UInt(input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromInt64(4294967295)_NeverFails") { - let input = getInt64(4294967295) - let actual = UInt(exactly: input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromInt64(4294967296)_AlwaysTraps") { - let input = getInt64(4294967296) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromInt64(4294967296)_AlwaysFails") { - let input = getInt64(4294967296) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromInt64(9223372036854775807)_AlwaysTraps") { - let input = getInt64(9223372036854775807) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromInt64(9223372036854775807)_AlwaysFails") { - let input = getInt64(9223372036854775807) - let actual = UInt(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt +.test("FromInt64_NeverTraps") +.forEach(in: [ + (getUInt(+0), getInt64(+0)), + (getUInt(+4294967295), getInt64(+4294967295)), +]) { + expectEqual($0.0, UInt($0.1)) +} + +FixedPointConversion_Release32_ToUInt +.test("FromInt64_NeverFails") +.forEach(in: [ + (getUInt(+0), getInt64(+0)), + (getUInt(+4294967295), getInt64(+4294967295)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToUInt +.test("FromInt64_AlwaysTraps") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-1), + getInt64(+4294967296), + getInt64(+9223372036854775807), +]) { + expectCrashLater() + _blackHole(UInt($0)) +} + +FixedPointConversion_Release32_ToUInt +.test("FromInt64_AlwaysFails") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-1), + getInt64(+4294967296), + getInt64(+9223372036854775807), +]) { + expectNil(UInt(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt: (0)...(4294967295) +// MARK: UInt: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt.test("FromUInt(0)_NeverTraps") { - let input = getUInt(0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromUInt(0)_NeverFails") { - let input = getUInt(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromUInt(4294967295)_NeverTraps") { - let input = getUInt(4294967295) - let actual = UInt(input) - expectEqual(4294967295, actual) +FixedPointConversion_Release32_ToUInt +.test("FromUInt_NeverTraps") +.forEach(in: [ + (getUInt(+0), getUInt(+0)), + (getUInt(+4294967295), getUInt(+4294967295)), +]) { + expectEqual($0.0, UInt($0.1)) } -FixedPointConversion_Release32_ToUInt.test("FromUInt(4294967295)_NeverFails") { - let input = getUInt(4294967295) - let actual = UInt(exactly: input) - expectEqual(4294967295, actual) +FixedPointConversion_Release32_ToUInt +.test("FromUInt_NeverFails") +.forEach(in: [ + (getUInt(+0), getUInt(+0)), + (getUInt(+4294967295), getUInt(+4294967295)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int: (-2147483648)...(2147483647) +// MARK: Int: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt.test("FromInt(-2147483648)_AlwaysTraps") { - let input = getInt(-2147483648) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromInt(-2147483648)_AlwaysFails") { - let input = getInt(-2147483648) - let actual = UInt(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt +.test("FromInt_NeverTraps") +.forEach(in: [ + (getUInt(+0), getInt(+0)), + (getUInt(+2147483647), getInt(+2147483647)), +]) { + expectEqual($0.0, UInt($0.1)) } -FixedPointConversion_Release32_ToUInt.test("FromInt(-1)_AlwaysTraps") { - let input = getInt(-1) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } +FixedPointConversion_Release32_ToUInt +.test("FromInt_NeverFails") +.forEach(in: [ + (getUInt(+0), getInt(+0)), + (getUInt(+2147483647), getInt(+2147483647)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) } -FixedPointConversion_Release32_ToUInt.test("FromInt(-1)_AlwaysFails") { - let input = getInt(-1) - let actual = UInt(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt +.test("FromInt_AlwaysTraps") +.forEach(in: [ + getInt(-2147483648), + getInt(-1), +]) { + expectCrashLater() + _blackHole(UInt($0)) } -FixedPointConversion_Release32_ToUInt.test("FromInt(0)_NeverTraps") { - let input = getInt(0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromInt(0)_NeverFails") { - let input = getInt(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromInt(2147483647)_NeverTraps") { - let input = getInt(2147483647) - let actual = UInt(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromInt(2147483647)_NeverFails") { - let input = getInt(2147483647) - let actual = UInt(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Release32_ToUInt +.test("FromInt_AlwaysFails") +.forEach(in: [ + getInt(-2147483648), + getInt(-1), +]) { + expectNil(UInt(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float16: (-2047)...(2047) +// MARK: Float16: (-2047)...(+2047) //===----------------------------------------------------------------------===// #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -FixedPointConversion_Release32_ToUInt.test("FromFloat16(-2047)_AlwaysTraps") { - let input = getFloat16(-2047) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat16(-2047)_AlwaysFails") { - let input = getFloat16(-2047) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat16(-128.5)_AlwaysTraps") { - let input = getFloat16(-128.5) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat16(-128.5)_AlwaysFails") { - let input = getFloat16(-128.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat16(-1)_AlwaysTraps") { - let input = getFloat16(-1) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat16(-1)_AlwaysFails") { - let input = getFloat16(-1) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat16(-0.5)_NeverTraps") { - let input = getFloat16(-0.5) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat16(-0.5)_AlwaysFails") { - let input = getFloat16(-0.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat16(0)_NeverTraps") { - let input = getFloat16(0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat16(0)_NeverFails") { - let input = getFloat16(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat16(-0.0)_NeverTraps") { - let input = getFloat16(-0.0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat16(-0.0)_NeverFails") { - let input = getFloat16(-0.0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat16(0.0)_NeverTraps") { - let input = getFloat16(0.0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat16(0.0)_NeverFails") { - let input = getFloat16(0.0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat16(0.5)_NeverTraps") { - let input = getFloat16(0.5) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat16(0.5)_AlwaysFails") { - let input = getFloat16(0.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat16(127.5)_NeverTraps") { - let input = getFloat16(127.5) - let actual = UInt(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat16(127.5)_AlwaysFails") { - let input = getFloat16(127.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat16(255.5)_NeverTraps") { - let input = getFloat16(255.5) - let actual = UInt(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat16(255.5)_AlwaysFails") { - let input = getFloat16(255.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat16(2047)_NeverTraps") { - let input = getFloat16(2047) - let actual = UInt(input) - expectEqual(2047, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat16(2047)_NeverFails") { - let input = getFloat16(2047) - let actual = UInt(exactly: input) - expectEqual(2047, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat16(-.infinity)_AlwaysTraps") { - let input = getFloat16(-.infinity) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat16(-.infinity)_AlwaysFails") { - let input = getFloat16(-.infinity) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat16(+.infinity)_AlwaysTraps") { - let input = getFloat16(+.infinity) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat16(+.infinity)_AlwaysFails") { - let input = getFloat16(+.infinity) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat16(-.nan)_AlwaysTraps") { - let input = getFloat16(-.nan) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat16(-.nan)_AlwaysFails") { - let input = getFloat16(-.nan) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat16(+.nan)_AlwaysTraps") { - let input = getFloat16(+.nan) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat16(+.nan)_AlwaysFails") { - let input = getFloat16(+.nan) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat16(-.signalingNaN)_AlwaysTraps") { - let input = getFloat16(-.signalingNaN) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat16(-.signalingNaN)_AlwaysFails") { - let input = getFloat16(-.signalingNaN) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat16(+.signalingNaN)_AlwaysTraps") { - let input = getFloat16(+.signalingNaN) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat16(+.signalingNaN)_AlwaysFails") { - let input = getFloat16(+.signalingNaN) - let actual = UInt(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt +.test("FromFloat16_NeverTraps") +.forEach(in: [ + (getUInt(+0), getFloat16(-0.5)), + (getUInt(+0), getFloat16(+0)), + (getUInt(+0), getFloat16(-0)), + (getUInt(+0), getFloat16(+0.5)), + (getUInt(+127), getFloat16(+127.5)), + (getUInt(+255), getFloat16(+255.5)), + (getUInt(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, UInt($0.1)) +} + +FixedPointConversion_Release32_ToUInt +.test("FromFloat16_NeverFails") +.forEach(in: [ + (getUInt(+0), getFloat16(+0)), + (getUInt(+0), getFloat16(-0)), + (getUInt(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToUInt +.test("FromFloat16_AlwaysTraps") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-128.5), + getFloat16(-1), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt($0)) +} + +FixedPointConversion_Release32_ToUInt +.test("FromFloat16_AlwaysFails") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-128.5), + getFloat16(-1), + getFloat16(-0.5), + getFloat16(+0.5), + getFloat16(+127.5), + getFloat16(+255.5), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectNil(UInt(exactly: $0)) } } #endif // Float16 //===----------------------------------------------------------------------===// -// MARK: Float32: (-16777215)...(16777215) +// MARK: Float32: (-16777215)...(+16777215) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt.test("FromFloat32(-16777215)_AlwaysTraps") { - let input = getFloat32(-16777215) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat32(-16777215)_AlwaysFails") { - let input = getFloat32(-16777215) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat32(-32768.5)_AlwaysTraps") { - let input = getFloat32(-32768.5) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat32(-32768.5)_AlwaysFails") { - let input = getFloat32(-32768.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat32(-128.5)_AlwaysTraps") { - let input = getFloat32(-128.5) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat32(-128.5)_AlwaysFails") { - let input = getFloat32(-128.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat32(-1)_AlwaysTraps") { - let input = getFloat32(-1) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat32(-1)_AlwaysFails") { - let input = getFloat32(-1) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat32(-0.5)_NeverTraps") { - let input = getFloat32(-0.5) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat32(-0.5)_AlwaysFails") { - let input = getFloat32(-0.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat32(0)_NeverTraps") { - let input = getFloat32(0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat32(0)_NeverFails") { - let input = getFloat32(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat32(-0.0)_NeverTraps") { - let input = getFloat32(-0.0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat32(-0.0)_NeverFails") { - let input = getFloat32(-0.0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat32(0.0)_NeverTraps") { - let input = getFloat32(0.0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat32(0.0)_NeverFails") { - let input = getFloat32(0.0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat32(0.5)_NeverTraps") { - let input = getFloat32(0.5) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat32(0.5)_AlwaysFails") { - let input = getFloat32(0.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat32(127.5)_NeverTraps") { - let input = getFloat32(127.5) - let actual = UInt(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat32(127.5)_AlwaysFails") { - let input = getFloat32(127.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat32(255.5)_NeverTraps") { - let input = getFloat32(255.5) - let actual = UInt(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat32(255.5)_AlwaysFails") { - let input = getFloat32(255.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat32(32767.5)_NeverTraps") { - let input = getFloat32(32767.5) - let actual = UInt(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat32(32767.5)_AlwaysFails") { - let input = getFloat32(32767.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat32(65535.5)_NeverTraps") { - let input = getFloat32(65535.5) - let actual = UInt(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat32(65535.5)_AlwaysFails") { - let input = getFloat32(65535.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat32(16777215)_NeverTraps") { - let input = getFloat32(16777215) - let actual = UInt(input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat32(16777215)_NeverFails") { - let input = getFloat32(16777215) - let actual = UInt(exactly: input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat32(-.infinity)_AlwaysTraps") { - let input = getFloat32(-.infinity) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat32(-.infinity)_AlwaysFails") { - let input = getFloat32(-.infinity) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat32(+.infinity)_AlwaysTraps") { - let input = getFloat32(+.infinity) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat32(+.infinity)_AlwaysFails") { - let input = getFloat32(+.infinity) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat32(-.nan)_AlwaysTraps") { - let input = getFloat32(-.nan) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat32(-.nan)_AlwaysFails") { - let input = getFloat32(-.nan) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat32(+.nan)_AlwaysTraps") { - let input = getFloat32(+.nan) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat32(+.nan)_AlwaysFails") { - let input = getFloat32(+.nan) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat32(-.signalingNaN)_AlwaysTraps") { - let input = getFloat32(-.signalingNaN) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat32(-.signalingNaN)_AlwaysFails") { - let input = getFloat32(-.signalingNaN) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat32(+.signalingNaN)_AlwaysTraps") { - let input = getFloat32(+.signalingNaN) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat32(+.signalingNaN)_AlwaysFails") { - let input = getFloat32(+.signalingNaN) - let actual = UInt(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt +.test("FromFloat32_NeverTraps") +.forEach(in: [ + (getUInt(+0), getFloat32(-0.5)), + (getUInt(+0), getFloat32(+0)), + (getUInt(+0), getFloat32(-0)), + (getUInt(+0), getFloat32(+0.5)), + (getUInt(+127), getFloat32(+127.5)), + (getUInt(+255), getFloat32(+255.5)), + (getUInt(+32767), getFloat32(+32767.5)), + (getUInt(+65535), getFloat32(+65535.5)), + (getUInt(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, UInt($0.1)) +} + +FixedPointConversion_Release32_ToUInt +.test("FromFloat32_NeverFails") +.forEach(in: [ + (getUInt(+0), getFloat32(+0)), + (getUInt(+0), getFloat32(-0)), + (getUInt(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToUInt +.test("FromFloat32_AlwaysTraps") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-1), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt($0)) +} + +FixedPointConversion_Release32_ToUInt +.test("FromFloat32_AlwaysFails") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-1), + getFloat32(-0.5), + getFloat32(+0.5), + getFloat32(+127.5), + getFloat32(+255.5), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectNil(UInt(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float64: (-9007199254740991)...(9007199254740991) +// MARK: Float64: (-9007199254740991)...(+9007199254740991) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt.test("FromFloat64(-9007199254740991)_AlwaysTraps") { - let input = getFloat64(-9007199254740991) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(-9007199254740991)_AlwaysFails") { - let input = getFloat64(-9007199254740991) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(-32768.5)_AlwaysTraps") { - let input = getFloat64(-32768.5) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(-32768.5)_AlwaysFails") { - let input = getFloat64(-32768.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(-128.5)_AlwaysTraps") { - let input = getFloat64(-128.5) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(-128.5)_AlwaysFails") { - let input = getFloat64(-128.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(-1)_AlwaysTraps") { - let input = getFloat64(-1) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(-1)_AlwaysFails") { - let input = getFloat64(-1) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(-0.5)_NeverTraps") { - let input = getFloat64(-0.5) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(-0.5)_AlwaysFails") { - let input = getFloat64(-0.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(0)_NeverTraps") { - let input = getFloat64(0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(0)_NeverFails") { - let input = getFloat64(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(-0.0)_NeverTraps") { - let input = getFloat64(-0.0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(-0.0)_NeverFails") { - let input = getFloat64(-0.0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(0.0)_NeverTraps") { - let input = getFloat64(0.0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(0.0)_NeverFails") { - let input = getFloat64(0.0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(0.5)_NeverTraps") { - let input = getFloat64(0.5) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(0.5)_AlwaysFails") { - let input = getFloat64(0.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(127.5)_NeverTraps") { - let input = getFloat64(127.5) - let actual = UInt(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(127.5)_AlwaysFails") { - let input = getFloat64(127.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(255.5)_NeverTraps") { - let input = getFloat64(255.5) - let actual = UInt(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(255.5)_AlwaysFails") { - let input = getFloat64(255.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(32767.5)_NeverTraps") { - let input = getFloat64(32767.5) - let actual = UInt(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(32767.5)_AlwaysFails") { - let input = getFloat64(32767.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(65535.5)_NeverTraps") { - let input = getFloat64(65535.5) - let actual = UInt(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(65535.5)_AlwaysFails") { - let input = getFloat64(65535.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(4294967295)_NeverTraps") { - let input = getFloat64(4294967295) - let actual = UInt(input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(4294967295)_NeverFails") { - let input = getFloat64(4294967295) - let actual = UInt(exactly: input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(4294967296)_AlwaysTraps") { - let input = getFloat64(4294967296) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(4294967296)_AlwaysFails") { - let input = getFloat64(4294967296) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(9007199254740991)_AlwaysTraps") { - let input = getFloat64(9007199254740991) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(9007199254740991)_AlwaysFails") { - let input = getFloat64(9007199254740991) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(-.infinity)_AlwaysTraps") { - let input = getFloat64(-.infinity) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(-.infinity)_AlwaysFails") { - let input = getFloat64(-.infinity) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(+.infinity)_AlwaysTraps") { - let input = getFloat64(+.infinity) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(+.infinity)_AlwaysFails") { - let input = getFloat64(+.infinity) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(-.nan)_AlwaysTraps") { - let input = getFloat64(-.nan) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(-.nan)_AlwaysFails") { - let input = getFloat64(-.nan) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(+.nan)_AlwaysTraps") { - let input = getFloat64(+.nan) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(+.nan)_AlwaysFails") { - let input = getFloat64(+.nan) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(-.signalingNaN)_AlwaysTraps") { - let input = getFloat64(-.signalingNaN) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(-.signalingNaN)_AlwaysFails") { - let input = getFloat64(-.signalingNaN) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(+.signalingNaN)_AlwaysTraps") { - let input = getFloat64(+.signalingNaN) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat64(+.signalingNaN)_AlwaysFails") { - let input = getFloat64(+.signalingNaN) - let actual = UInt(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt +.test("FromFloat64_NeverTraps") +.forEach(in: [ + (getUInt(+0), getFloat64(-0.5)), + (getUInt(+0), getFloat64(+0)), + (getUInt(+0), getFloat64(-0)), + (getUInt(+0), getFloat64(+0.5)), + (getUInt(+127), getFloat64(+127.5)), + (getUInt(+255), getFloat64(+255.5)), + (getUInt(+32767), getFloat64(+32767.5)), + (getUInt(+65535), getFloat64(+65535.5)), + (getUInt(+4294967295), getFloat64(+4294967295)), +]) { + expectEqual($0.0, UInt($0.1)) +} + +FixedPointConversion_Release32_ToUInt +.test("FromFloat64_NeverFails") +.forEach(in: [ + (getUInt(+0), getFloat64(+0)), + (getUInt(+0), getFloat64(-0)), + (getUInt(+4294967295), getFloat64(+4294967295)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToUInt +.test("FromFloat64_AlwaysTraps") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-1), + getFloat64(+4294967296), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt($0)) +} + +FixedPointConversion_Release32_ToUInt +.test("FromFloat64_AlwaysFails") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-1), + getFloat64(-0.5), + getFloat64(+0.5), + getFloat64(+127.5), + getFloat64(+255.5), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(+4294967296), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectNil(UInt(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float80: (-18446744073709551615)...(18446744073709551615) +// MARK: Float80: (-18446744073709551615)...(+18446744073709551615) //===----------------------------------------------------------------------===// #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) -FixedPointConversion_Release32_ToUInt.test("FromFloat80(-18446744073709551615)_AlwaysTraps") { - let input = getFloat80(-18446744073709551615) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(-18446744073709551615)_AlwaysFails") { - let input = getFloat80(-18446744073709551615) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(-32768.5)_AlwaysTraps") { - let input = getFloat80(-32768.5) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(-32768.5)_AlwaysFails") { - let input = getFloat80(-32768.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(-128.5)_AlwaysTraps") { - let input = getFloat80(-128.5) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(-128.5)_AlwaysFails") { - let input = getFloat80(-128.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(-1)_AlwaysTraps") { - let input = getFloat80(-1) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(-1)_AlwaysFails") { - let input = getFloat80(-1) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(-0.5)_NeverTraps") { - let input = getFloat80(-0.5) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(-0.5)_AlwaysFails") { - let input = getFloat80(-0.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(0)_NeverTraps") { - let input = getFloat80(0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(0)_NeverFails") { - let input = getFloat80(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(-0.0)_NeverTraps") { - let input = getFloat80(-0.0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(-0.0)_NeverFails") { - let input = getFloat80(-0.0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(0.0)_NeverTraps") { - let input = getFloat80(0.0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(0.0)_NeverFails") { - let input = getFloat80(0.0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(0.5)_NeverTraps") { - let input = getFloat80(0.5) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(0.5)_AlwaysFails") { - let input = getFloat80(0.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(127.5)_NeverTraps") { - let input = getFloat80(127.5) - let actual = UInt(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(127.5)_AlwaysFails") { - let input = getFloat80(127.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(255.5)_NeverTraps") { - let input = getFloat80(255.5) - let actual = UInt(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(255.5)_AlwaysFails") { - let input = getFloat80(255.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(32767.5)_NeverTraps") { - let input = getFloat80(32767.5) - let actual = UInt(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(32767.5)_AlwaysFails") { - let input = getFloat80(32767.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(65535.5)_NeverTraps") { - let input = getFloat80(65535.5) - let actual = UInt(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(65535.5)_AlwaysFails") { - let input = getFloat80(65535.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(4294967295)_NeverTraps") { - let input = getFloat80(4294967295) - let actual = UInt(input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(4294967295)_NeverFails") { - let input = getFloat80(4294967295) - let actual = UInt(exactly: input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(4294967296)_AlwaysTraps") { - let input = getFloat80(4294967296) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(4294967296)_AlwaysFails") { - let input = getFloat80(4294967296) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(18446744073709551615)_AlwaysTraps") { - let input = getFloat80(18446744073709551615) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(18446744073709551615)_AlwaysFails") { - let input = getFloat80(18446744073709551615) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(-.infinity)_AlwaysTraps") { - let input = getFloat80(-.infinity) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(-.infinity)_AlwaysFails") { - let input = getFloat80(-.infinity) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(+.infinity)_AlwaysTraps") { - let input = getFloat80(+.infinity) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(+.infinity)_AlwaysFails") { - let input = getFloat80(+.infinity) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(-.nan)_AlwaysTraps") { - let input = getFloat80(-.nan) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(-.nan)_AlwaysFails") { - let input = getFloat80(-.nan) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(+.nan)_AlwaysTraps") { - let input = getFloat80(+.nan) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(+.nan)_AlwaysFails") { - let input = getFloat80(+.nan) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(-.signalingNaN)_AlwaysTraps") { - let input = getFloat80(-.signalingNaN) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(-.signalingNaN)_AlwaysFails") { - let input = getFloat80(-.signalingNaN) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(+.signalingNaN)_AlwaysTraps") { - let input = getFloat80(+.signalingNaN) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt.test("FromFloat80(+.signalingNaN)_AlwaysFails") { - let input = getFloat80(+.signalingNaN) - let actual = UInt(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt +.test("FromFloat80_NeverTraps") +.forEach(in: [ + (getUInt(+0), getFloat80(-0.5)), + (getUInt(+0), getFloat80(+0)), + (getUInt(+0), getFloat80(-0)), + (getUInt(+0), getFloat80(+0.5)), + (getUInt(+127), getFloat80(+127.5)), + (getUInt(+255), getFloat80(+255.5)), + (getUInt(+32767), getFloat80(+32767.5)), + (getUInt(+65535), getFloat80(+65535.5)), + (getUInt(+4294967295), getFloat80(+4294967295)), +]) { + expectEqual($0.0, UInt($0.1)) +} + +FixedPointConversion_Release32_ToUInt +.test("FromFloat80_NeverFails") +.forEach(in: [ + (getUInt(+0), getFloat80(+0)), + (getUInt(+0), getFloat80(-0)), + (getUInt(+4294967295), getFloat80(+4294967295)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToUInt +.test("FromFloat80_AlwaysTraps") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-1), + getFloat80(+4294967296), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt($0)) +} + +FixedPointConversion_Release32_ToUInt +.test("FromFloat80_AlwaysFails") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-1), + getFloat80(-0.5), + getFloat80(+0.5), + getFloat80(+127.5), + getFloat80(+255.5), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(+4294967296), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectNil(UInt(exactly: $0)) } #endif // Float80 diff --git a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release32_ToUInt16.swift b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release32_ToUInt16.swift index b1618cccbfdef..73662307c23ff 100644 --- a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release32_ToUInt16.swift +++ b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release32_ToUInt16.swift @@ -5,7 +5,7 @@ // //===----------------------------------------------------------------------===// // -// REQUIRES: executable_test, long_test +// REQUIRES: executable_test // REQUIRES: PTRSIZE=32 // RUN: %target-run-simple-swift(-O) // END. @@ -14,1704 +14,690 @@ import StdlibUnittest -let FixedPointConversion_Release32_ToUInt16 = TestSuite("FixedPointConversion_Release32_ToUInt16") +let FixedPointConversion_Release32_ToUInt16 = TestSuite( + "FixedPointConversion_Release32_ToUInt16" +) //===----------------------------------------------------------------------===// -// MARK: UInt8: (0)...(255) +// MARK: UInt8: (+0)...(+255) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt16.test("FromUInt8(0)_NeverTraps") { - let input = getUInt8(0) - let actual = UInt16(input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToUInt16 +.test("FromUInt8_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getUInt8(+0)), + (getUInt16(+255), getUInt8(+255)), +]) { + expectEqual($0.0, UInt16($0.1)) } -FixedPointConversion_Release32_ToUInt16.test("FromUInt8(0)_NeverFails") { - let input = getUInt8(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromUInt8(255)_NeverTraps") { - let input = getUInt8(255) - let actual = UInt16(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromUInt8(255)_NeverFails") { - let input = getUInt8(255) - let actual = UInt16(exactly: input) - expectEqual(255, actual) +FixedPointConversion_Release32_ToUInt16 +.test("FromUInt8_NeverFails") +.forEach(in: [ + (getUInt16(+0), getUInt8(+0)), + (getUInt16(+255), getUInt8(+255)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int8: (-128)...(127) +// MARK: Int8: (-128)...(+127) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt16.test("FromInt8(-128)_AlwaysTraps") { - let input = getInt8(-128) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt8(-128)_AlwaysFails") { - let input = getInt8(-128) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt8(-1)_AlwaysTraps") { - let input = getInt8(-1) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt8(-1)_AlwaysFails") { - let input = getInt8(-1) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt16 +.test("FromInt8_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getInt8(+0)), + (getUInt16(+127), getInt8(+127)), +]) { + expectEqual($0.0, UInt16($0.1)) } -FixedPointConversion_Release32_ToUInt16.test("FromInt8(0)_NeverTraps") { - let input = getInt8(0) - let actual = UInt16(input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToUInt16 +.test("FromInt8_NeverFails") +.forEach(in: [ + (getUInt16(+0), getInt8(+0)), + (getUInt16(+127), getInt8(+127)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) } -FixedPointConversion_Release32_ToUInt16.test("FromInt8(0)_NeverFails") { - let input = getInt8(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToUInt16 +.test("FromInt8_AlwaysTraps") +.forEach(in: [ + getInt8(-128), + getInt8(-1), +]) { + expectCrashLater() + _blackHole(UInt16($0)) } -FixedPointConversion_Release32_ToUInt16.test("FromInt8(127)_NeverTraps") { - let input = getInt8(127) - let actual = UInt16(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt8(127)_NeverFails") { - let input = getInt8(127) - let actual = UInt16(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Release32_ToUInt16 +.test("FromInt8_AlwaysFails") +.forEach(in: [ + getInt8(-128), + getInt8(-1), +]) { + expectNil(UInt16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt16: (0)...(65535) +// MARK: UInt16: (+0)...(+65535) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt16.test("FromUInt16(0)_NeverTraps") { - let input = getUInt16(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromUInt16(0)_NeverFails") { - let input = getUInt16(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToUInt16 +.test("FromUInt16_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getUInt16(+0)), + (getUInt16(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, UInt16($0.1)) } -FixedPointConversion_Release32_ToUInt16.test("FromUInt16(65535)_NeverTraps") { - let input = getUInt16(65535) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromUInt16(65535)_NeverFails") { - let input = getUInt16(65535) - let actual = UInt16(exactly: input) - expectEqual(65535, actual) +FixedPointConversion_Release32_ToUInt16 +.test("FromUInt16_NeverFails") +.forEach(in: [ + (getUInt16(+0), getUInt16(+0)), + (getUInt16(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int16: (-32768)...(32767) +// MARK: Int16: (-32768)...(+32767) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt16.test("FromInt16(-32768)_AlwaysTraps") { - let input = getInt16(-32768) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt16(-32768)_AlwaysFails") { - let input = getInt16(-32768) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt16(-1)_AlwaysTraps") { - let input = getInt16(-1) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt16(-1)_AlwaysFails") { - let input = getInt16(-1) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt16(0)_NeverTraps") { - let input = getInt16(0) - let actual = UInt16(input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToUInt16 +.test("FromInt16_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getInt16(+0)), + (getUInt16(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, UInt16($0.1)) } -FixedPointConversion_Release32_ToUInt16.test("FromInt16(0)_NeverFails") { - let input = getInt16(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToUInt16 +.test("FromInt16_NeverFails") +.forEach(in: [ + (getUInt16(+0), getInt16(+0)), + (getUInt16(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) } -FixedPointConversion_Release32_ToUInt16.test("FromInt16(32767)_NeverTraps") { - let input = getInt16(32767) - let actual = UInt16(input) - expectEqual(32767, actual) +FixedPointConversion_Release32_ToUInt16 +.test("FromInt16_AlwaysTraps") +.forEach(in: [ + getInt16(-32768), + getInt16(-1), +]) { + expectCrashLater() + _blackHole(UInt16($0)) } -FixedPointConversion_Release32_ToUInt16.test("FromInt16(32767)_NeverFails") { - let input = getInt16(32767) - let actual = UInt16(exactly: input) - expectEqual(32767, actual) +FixedPointConversion_Release32_ToUInt16 +.test("FromInt16_AlwaysFails") +.forEach(in: [ + getInt16(-32768), + getInt16(-1), +]) { + expectNil(UInt16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt32: (0)...(4294967295) +// MARK: UInt32: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt16.test("FromUInt32(0)_NeverTraps") { - let input = getUInt32(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromUInt32(0)_NeverFails") { - let input = getUInt32(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromUInt32(65535)_NeverTraps") { - let input = getUInt32(65535) - let actual = UInt16(input) - expectEqual(65535, actual) +FixedPointConversion_Release32_ToUInt16 +.test("FromUInt32_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getUInt32(+0)), + (getUInt16(+65535), getUInt32(+65535)), +]) { + expectEqual($0.0, UInt16($0.1)) } -FixedPointConversion_Release32_ToUInt16.test("FromUInt32(65535)_NeverFails") { - let input = getUInt32(65535) - let actual = UInt16(exactly: input) - expectEqual(65535, actual) +FixedPointConversion_Release32_ToUInt16 +.test("FromUInt32_NeverFails") +.forEach(in: [ + (getUInt16(+0), getUInt32(+0)), + (getUInt16(+65535), getUInt32(+65535)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) } -FixedPointConversion_Release32_ToUInt16.test("FromUInt32(65536)_AlwaysTraps") { - let input = getUInt32(65536) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } +FixedPointConversion_Release32_ToUInt16 +.test("FromUInt32_AlwaysTraps") +.forEach(in: [ + getUInt32(+65536), + getUInt32(+4294967295), +]) { + expectCrashLater() + _blackHole(UInt16($0)) } -FixedPointConversion_Release32_ToUInt16.test("FromUInt32(65536)_AlwaysFails") { - let input = getUInt32(65536) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromUInt32(4294967295)_AlwaysTraps") { - let input = getUInt32(4294967295) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromUInt32(4294967295)_AlwaysFails") { - let input = getUInt32(4294967295) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt16 +.test("FromUInt32_AlwaysFails") +.forEach(in: [ + getUInt32(+65536), + getUInt32(+4294967295), +]) { + expectNil(UInt16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int32: (-2147483648)...(2147483647) +// MARK: Int32: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt16.test("FromInt32(-2147483648)_AlwaysTraps") { - let input = getInt32(-2147483648) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt32(-2147483648)_AlwaysFails") { - let input = getInt32(-2147483648) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt32(-1)_AlwaysTraps") { - let input = getInt32(-1) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt32(-1)_AlwaysFails") { - let input = getInt32(-1) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt32(0)_NeverTraps") { - let input = getInt32(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt32(0)_NeverFails") { - let input = getInt32(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt32(65535)_NeverTraps") { - let input = getInt32(65535) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt32(65535)_NeverFails") { - let input = getInt32(65535) - let actual = UInt16(exactly: input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt32(65536)_AlwaysTraps") { - let input = getInt32(65536) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt32(65536)_AlwaysFails") { - let input = getInt32(65536) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt32(2147483647)_AlwaysTraps") { - let input = getInt32(2147483647) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt32(2147483647)_AlwaysFails") { - let input = getInt32(2147483647) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt16 +.test("FromInt32_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getInt32(+0)), + (getUInt16(+65535), getInt32(+65535)), +]) { + expectEqual($0.0, UInt16($0.1)) +} + +FixedPointConversion_Release32_ToUInt16 +.test("FromInt32_NeverFails") +.forEach(in: [ + (getUInt16(+0), getInt32(+0)), + (getUInt16(+65535), getInt32(+65535)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToUInt16 +.test("FromInt32_AlwaysTraps") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-1), + getInt32(+65536), + getInt32(+2147483647), +]) { + expectCrashLater() + _blackHole(UInt16($0)) +} + +FixedPointConversion_Release32_ToUInt16 +.test("FromInt32_AlwaysFails") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-1), + getInt32(+65536), + getInt32(+2147483647), +]) { + expectNil(UInt16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt64: (0)...(18446744073709551615) +// MARK: UInt64: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt16.test("FromUInt64(0)_NeverTraps") { - let input = getUInt64(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromUInt64(0)_NeverFails") { - let input = getUInt64(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromUInt64(65535)_NeverTraps") { - let input = getUInt64(65535) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromUInt64(65535)_NeverFails") { - let input = getUInt64(65535) - let actual = UInt16(exactly: input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromUInt64(65536)_AlwaysTraps") { - let input = getUInt64(65536) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } +FixedPointConversion_Release32_ToUInt16 +.test("FromUInt64_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getUInt64(+0)), + (getUInt16(+65535), getUInt64(+65535)), +]) { + expectEqual($0.0, UInt16($0.1)) } -FixedPointConversion_Release32_ToUInt16.test("FromUInt64(65536)_AlwaysFails") { - let input = getUInt64(65536) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt16 +.test("FromUInt64_NeverFails") +.forEach(in: [ + (getUInt16(+0), getUInt64(+0)), + (getUInt16(+65535), getUInt64(+65535)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) } -FixedPointConversion_Release32_ToUInt16.test("FromUInt64(18446744073709551615)_AlwaysTraps") { - let input = getUInt64(18446744073709551615) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } +FixedPointConversion_Release32_ToUInt16 +.test("FromUInt64_AlwaysTraps") +.forEach(in: [ + getUInt64(+65536), + getUInt64(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(UInt16($0)) } -FixedPointConversion_Release32_ToUInt16.test("FromUInt64(18446744073709551615)_AlwaysFails") { - let input = getUInt64(18446744073709551615) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt16 +.test("FromUInt64_AlwaysFails") +.forEach(in: [ + getUInt64(+65536), + getUInt64(+18446744073709551615), +]) { + expectNil(UInt16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int64: (-9223372036854775808)...(9223372036854775807) +// MARK: Int64: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt16.test("FromInt64(-9223372036854775808)_AlwaysTraps") { - let input = getInt64(-9223372036854775808) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt64(-9223372036854775808)_AlwaysFails") { - let input = getInt64(-9223372036854775808) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt64(-1)_AlwaysTraps") { - let input = getInt64(-1) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt64(-1)_AlwaysFails") { - let input = getInt64(-1) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt64(0)_NeverTraps") { - let input = getInt64(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt64(0)_NeverFails") { - let input = getInt64(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt64(65535)_NeverTraps") { - let input = getInt64(65535) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt64(65535)_NeverFails") { - let input = getInt64(65535) - let actual = UInt16(exactly: input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt64(65536)_AlwaysTraps") { - let input = getInt64(65536) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt64(65536)_AlwaysFails") { - let input = getInt64(65536) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt64(9223372036854775807)_AlwaysTraps") { - let input = getInt64(9223372036854775807) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt64(9223372036854775807)_AlwaysFails") { - let input = getInt64(9223372036854775807) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt16 +.test("FromInt64_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getInt64(+0)), + (getUInt16(+65535), getInt64(+65535)), +]) { + expectEqual($0.0, UInt16($0.1)) +} + +FixedPointConversion_Release32_ToUInt16 +.test("FromInt64_NeverFails") +.forEach(in: [ + (getUInt16(+0), getInt64(+0)), + (getUInt16(+65535), getInt64(+65535)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToUInt16 +.test("FromInt64_AlwaysTraps") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-1), + getInt64(+65536), + getInt64(+9223372036854775807), +]) { + expectCrashLater() + _blackHole(UInt16($0)) +} + +FixedPointConversion_Release32_ToUInt16 +.test("FromInt64_AlwaysFails") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-1), + getInt64(+65536), + getInt64(+9223372036854775807), +]) { + expectNil(UInt16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt: (0)...(4294967295) +// MARK: UInt: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt16.test("FromUInt(0)_NeverTraps") { - let input = getUInt(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromUInt(0)_NeverFails") { - let input = getUInt(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromUInt(65535)_NeverTraps") { - let input = getUInt(65535) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromUInt(65535)_NeverFails") { - let input = getUInt(65535) - let actual = UInt16(exactly: input) - expectEqual(65535, actual) +FixedPointConversion_Release32_ToUInt16 +.test("FromUInt_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getUInt(+0)), + (getUInt16(+65535), getUInt(+65535)), +]) { + expectEqual($0.0, UInt16($0.1)) } -FixedPointConversion_Release32_ToUInt16.test("FromUInt(65536)_AlwaysTraps") { - let input = getUInt(65536) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } +FixedPointConversion_Release32_ToUInt16 +.test("FromUInt_NeverFails") +.forEach(in: [ + (getUInt16(+0), getUInt(+0)), + (getUInt16(+65535), getUInt(+65535)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) } -FixedPointConversion_Release32_ToUInt16.test("FromUInt(65536)_AlwaysFails") { - let input = getUInt(65536) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt16 +.test("FromUInt_AlwaysTraps") +.forEach(in: [ + getUInt(+65536), + getUInt(+4294967295), +]) { + expectCrashLater() + _blackHole(UInt16($0)) } -FixedPointConversion_Release32_ToUInt16.test("FromUInt(4294967295)_AlwaysTraps") { - let input = getUInt(4294967295) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromUInt(4294967295)_AlwaysFails") { - let input = getUInt(4294967295) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt16 +.test("FromUInt_AlwaysFails") +.forEach(in: [ + getUInt(+65536), + getUInt(+4294967295), +]) { + expectNil(UInt16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int: (-2147483648)...(2147483647) +// MARK: Int: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt16.test("FromInt(-2147483648)_AlwaysTraps") { - let input = getInt(-2147483648) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt(-2147483648)_AlwaysFails") { - let input = getInt(-2147483648) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt(-1)_AlwaysTraps") { - let input = getInt(-1) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt(-1)_AlwaysFails") { - let input = getInt(-1) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt(0)_NeverTraps") { - let input = getInt(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt(0)_NeverFails") { - let input = getInt(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt(65535)_NeverTraps") { - let input = getInt(65535) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt(65535)_NeverFails") { - let input = getInt(65535) - let actual = UInt16(exactly: input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt(65536)_AlwaysTraps") { - let input = getInt(65536) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt(65536)_AlwaysFails") { - let input = getInt(65536) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt(2147483647)_AlwaysTraps") { - let input = getInt(2147483647) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromInt(2147483647)_AlwaysFails") { - let input = getInt(2147483647) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt16 +.test("FromInt_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getInt(+0)), + (getUInt16(+65535), getInt(+65535)), +]) { + expectEqual($0.0, UInt16($0.1)) +} + +FixedPointConversion_Release32_ToUInt16 +.test("FromInt_NeverFails") +.forEach(in: [ + (getUInt16(+0), getInt(+0)), + (getUInt16(+65535), getInt(+65535)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToUInt16 +.test("FromInt_AlwaysTraps") +.forEach(in: [ + getInt(-2147483648), + getInt(-1), + getInt(+65536), + getInt(+2147483647), +]) { + expectCrashLater() + _blackHole(UInt16($0)) +} + +FixedPointConversion_Release32_ToUInt16 +.test("FromInt_AlwaysFails") +.forEach(in: [ + getInt(-2147483648), + getInt(-1), + getInt(+65536), + getInt(+2147483647), +]) { + expectNil(UInt16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float16: (-2047)...(2047) +// MARK: Float16: (-2047)...(+2047) //===----------------------------------------------------------------------===// #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -FixedPointConversion_Release32_ToUInt16.test("FromFloat16(-2047)_AlwaysTraps") { - let input = getFloat16(-2047) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat16(-2047)_AlwaysFails") { - let input = getFloat16(-2047) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat16(-128.5)_AlwaysTraps") { - let input = getFloat16(-128.5) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat16(-128.5)_AlwaysFails") { - let input = getFloat16(-128.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat16(-1)_AlwaysTraps") { - let input = getFloat16(-1) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat16(-1)_AlwaysFails") { - let input = getFloat16(-1) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat16(-0.5)_NeverTraps") { - let input = getFloat16(-0.5) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat16(-0.5)_AlwaysFails") { - let input = getFloat16(-0.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat16(0)_NeverTraps") { - let input = getFloat16(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat16(0)_NeverFails") { - let input = getFloat16(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat16(-0.0)_NeverTraps") { - let input = getFloat16(-0.0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat16(-0.0)_NeverFails") { - let input = getFloat16(-0.0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat16(0.0)_NeverTraps") { - let input = getFloat16(0.0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat16(0.0)_NeverFails") { - let input = getFloat16(0.0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat16(0.5)_NeverTraps") { - let input = getFloat16(0.5) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat16(0.5)_AlwaysFails") { - let input = getFloat16(0.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat16(127.5)_NeverTraps") { - let input = getFloat16(127.5) - let actual = UInt16(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat16(127.5)_AlwaysFails") { - let input = getFloat16(127.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat16(255.5)_NeverTraps") { - let input = getFloat16(255.5) - let actual = UInt16(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat16(255.5)_AlwaysFails") { - let input = getFloat16(255.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat16(2047)_NeverTraps") { - let input = getFloat16(2047) - let actual = UInt16(input) - expectEqual(2047, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat16(2047)_NeverFails") { - let input = getFloat16(2047) - let actual = UInt16(exactly: input) - expectEqual(2047, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat16(-.infinity)_AlwaysTraps") { - let input = getFloat16(-.infinity) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat16(-.infinity)_AlwaysFails") { - let input = getFloat16(-.infinity) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat16(+.infinity)_AlwaysTraps") { - let input = getFloat16(+.infinity) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat16(+.infinity)_AlwaysFails") { - let input = getFloat16(+.infinity) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat16(-.nan)_AlwaysTraps") { - let input = getFloat16(-.nan) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat16(-.nan)_AlwaysFails") { - let input = getFloat16(-.nan) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat16(+.nan)_AlwaysTraps") { - let input = getFloat16(+.nan) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat16(+.nan)_AlwaysFails") { - let input = getFloat16(+.nan) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat16(-.signalingNaN)_AlwaysTraps") { - let input = getFloat16(-.signalingNaN) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat16(-.signalingNaN)_AlwaysFails") { - let input = getFloat16(-.signalingNaN) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat16(+.signalingNaN)_AlwaysTraps") { - let input = getFloat16(+.signalingNaN) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat16(+.signalingNaN)_AlwaysFails") { - let input = getFloat16(+.signalingNaN) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt16 +.test("FromFloat16_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getFloat16(-0.5)), + (getUInt16(+0), getFloat16(+0)), + (getUInt16(+0), getFloat16(-0)), + (getUInt16(+0), getFloat16(+0.5)), + (getUInt16(+127), getFloat16(+127.5)), + (getUInt16(+255), getFloat16(+255.5)), + (getUInt16(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, UInt16($0.1)) +} + +FixedPointConversion_Release32_ToUInt16 +.test("FromFloat16_NeverFails") +.forEach(in: [ + (getUInt16(+0), getFloat16(+0)), + (getUInt16(+0), getFloat16(-0)), + (getUInt16(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToUInt16 +.test("FromFloat16_AlwaysTraps") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-128.5), + getFloat16(-1), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt16($0)) +} + +FixedPointConversion_Release32_ToUInt16 +.test("FromFloat16_AlwaysFails") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-128.5), + getFloat16(-1), + getFloat16(-0.5), + getFloat16(+0.5), + getFloat16(+127.5), + getFloat16(+255.5), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectNil(UInt16(exactly: $0)) } } #endif // Float16 //===----------------------------------------------------------------------===// -// MARK: Float32: (-16777215)...(16777215) +// MARK: Float32: (-16777215)...(+16777215) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(-16777215)_AlwaysTraps") { - let input = getFloat32(-16777215) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(-16777215)_AlwaysFails") { - let input = getFloat32(-16777215) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(-32768.5)_AlwaysTraps") { - let input = getFloat32(-32768.5) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(-32768.5)_AlwaysFails") { - let input = getFloat32(-32768.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(-128.5)_AlwaysTraps") { - let input = getFloat32(-128.5) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(-128.5)_AlwaysFails") { - let input = getFloat32(-128.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(-1)_AlwaysTraps") { - let input = getFloat32(-1) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(-1)_AlwaysFails") { - let input = getFloat32(-1) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(-0.5)_NeverTraps") { - let input = getFloat32(-0.5) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(-0.5)_AlwaysFails") { - let input = getFloat32(-0.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(0)_NeverTraps") { - let input = getFloat32(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(0)_NeverFails") { - let input = getFloat32(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(-0.0)_NeverTraps") { - let input = getFloat32(-0.0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(-0.0)_NeverFails") { - let input = getFloat32(-0.0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(0.0)_NeverTraps") { - let input = getFloat32(0.0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(0.0)_NeverFails") { - let input = getFloat32(0.0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(0.5)_NeverTraps") { - let input = getFloat32(0.5) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(0.5)_AlwaysFails") { - let input = getFloat32(0.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(127.5)_NeverTraps") { - let input = getFloat32(127.5) - let actual = UInt16(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(127.5)_AlwaysFails") { - let input = getFloat32(127.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(255.5)_NeverTraps") { - let input = getFloat32(255.5) - let actual = UInt16(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(255.5)_AlwaysFails") { - let input = getFloat32(255.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(32767.5)_NeverTraps") { - let input = getFloat32(32767.5) - let actual = UInt16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(32767.5)_AlwaysFails") { - let input = getFloat32(32767.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(65535)_NeverTraps") { - let input = getFloat32(65535) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(65535)_NeverFails") { - let input = getFloat32(65535) - let actual = UInt16(exactly: input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(65535.5)_NeverTraps") { - let input = getFloat32(65535.5) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(65535.5)_AlwaysFails") { - let input = getFloat32(65535.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(65536)_AlwaysTraps") { - let input = getFloat32(65536) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(65536)_AlwaysFails") { - let input = getFloat32(65536) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(16777215)_AlwaysTraps") { - let input = getFloat32(16777215) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(16777215)_AlwaysFails") { - let input = getFloat32(16777215) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(-.infinity)_AlwaysTraps") { - let input = getFloat32(-.infinity) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(-.infinity)_AlwaysFails") { - let input = getFloat32(-.infinity) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(+.infinity)_AlwaysTraps") { - let input = getFloat32(+.infinity) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(+.infinity)_AlwaysFails") { - let input = getFloat32(+.infinity) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(-.nan)_AlwaysTraps") { - let input = getFloat32(-.nan) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(-.nan)_AlwaysFails") { - let input = getFloat32(-.nan) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(+.nan)_AlwaysTraps") { - let input = getFloat32(+.nan) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(+.nan)_AlwaysFails") { - let input = getFloat32(+.nan) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(-.signalingNaN)_AlwaysTraps") { - let input = getFloat32(-.signalingNaN) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(-.signalingNaN)_AlwaysFails") { - let input = getFloat32(-.signalingNaN) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(+.signalingNaN)_AlwaysTraps") { - let input = getFloat32(+.signalingNaN) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat32(+.signalingNaN)_AlwaysFails") { - let input = getFloat32(+.signalingNaN) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt16 +.test("FromFloat32_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getFloat32(-0.5)), + (getUInt16(+0), getFloat32(+0)), + (getUInt16(+0), getFloat32(-0)), + (getUInt16(+0), getFloat32(+0.5)), + (getUInt16(+127), getFloat32(+127.5)), + (getUInt16(+255), getFloat32(+255.5)), + (getUInt16(+32767), getFloat32(+32767.5)), + (getUInt16(+65535), getFloat32(+65535)), + (getUInt16(+65535), getFloat32(+65535.5)), +]) { + expectEqual($0.0, UInt16($0.1)) +} + +FixedPointConversion_Release32_ToUInt16 +.test("FromFloat32_NeverFails") +.forEach(in: [ + (getUInt16(+0), getFloat32(+0)), + (getUInt16(+0), getFloat32(-0)), + (getUInt16(+65535), getFloat32(+65535)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToUInt16 +.test("FromFloat32_AlwaysTraps") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-1), + getFloat32(+65536), + getFloat32(+16777215), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt16($0)) +} + +FixedPointConversion_Release32_ToUInt16 +.test("FromFloat32_AlwaysFails") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-1), + getFloat32(-0.5), + getFloat32(+0.5), + getFloat32(+127.5), + getFloat32(+255.5), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(+65536), + getFloat32(+16777215), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectNil(UInt16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float64: (-9007199254740991)...(9007199254740991) +// MARK: Float64: (-9007199254740991)...(+9007199254740991) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(-9007199254740991)_AlwaysTraps") { - let input = getFloat64(-9007199254740991) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(-9007199254740991)_AlwaysFails") { - let input = getFloat64(-9007199254740991) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(-32768.5)_AlwaysTraps") { - let input = getFloat64(-32768.5) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(-32768.5)_AlwaysFails") { - let input = getFloat64(-32768.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(-128.5)_AlwaysTraps") { - let input = getFloat64(-128.5) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(-128.5)_AlwaysFails") { - let input = getFloat64(-128.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(-1)_AlwaysTraps") { - let input = getFloat64(-1) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(-1)_AlwaysFails") { - let input = getFloat64(-1) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(-0.5)_NeverTraps") { - let input = getFloat64(-0.5) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(-0.5)_AlwaysFails") { - let input = getFloat64(-0.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(0)_NeverTraps") { - let input = getFloat64(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(0)_NeverFails") { - let input = getFloat64(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(-0.0)_NeverTraps") { - let input = getFloat64(-0.0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(-0.0)_NeverFails") { - let input = getFloat64(-0.0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(0.0)_NeverTraps") { - let input = getFloat64(0.0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(0.0)_NeverFails") { - let input = getFloat64(0.0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(0.5)_NeverTraps") { - let input = getFloat64(0.5) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(0.5)_AlwaysFails") { - let input = getFloat64(0.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(127.5)_NeverTraps") { - let input = getFloat64(127.5) - let actual = UInt16(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(127.5)_AlwaysFails") { - let input = getFloat64(127.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(255.5)_NeverTraps") { - let input = getFloat64(255.5) - let actual = UInt16(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(255.5)_AlwaysFails") { - let input = getFloat64(255.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(32767.5)_NeverTraps") { - let input = getFloat64(32767.5) - let actual = UInt16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(32767.5)_AlwaysFails") { - let input = getFloat64(32767.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(65535)_NeverTraps") { - let input = getFloat64(65535) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(65535)_NeverFails") { - let input = getFloat64(65535) - let actual = UInt16(exactly: input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(65535.5)_NeverTraps") { - let input = getFloat64(65535.5) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(65535.5)_AlwaysFails") { - let input = getFloat64(65535.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(65536)_AlwaysTraps") { - let input = getFloat64(65536) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(65536)_AlwaysFails") { - let input = getFloat64(65536) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(9007199254740991)_AlwaysTraps") { - let input = getFloat64(9007199254740991) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(9007199254740991)_AlwaysFails") { - let input = getFloat64(9007199254740991) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(-.infinity)_AlwaysTraps") { - let input = getFloat64(-.infinity) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(-.infinity)_AlwaysFails") { - let input = getFloat64(-.infinity) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(+.infinity)_AlwaysTraps") { - let input = getFloat64(+.infinity) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(+.infinity)_AlwaysFails") { - let input = getFloat64(+.infinity) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(-.nan)_AlwaysTraps") { - let input = getFloat64(-.nan) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(-.nan)_AlwaysFails") { - let input = getFloat64(-.nan) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(+.nan)_AlwaysTraps") { - let input = getFloat64(+.nan) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(+.nan)_AlwaysFails") { - let input = getFloat64(+.nan) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(-.signalingNaN)_AlwaysTraps") { - let input = getFloat64(-.signalingNaN) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(-.signalingNaN)_AlwaysFails") { - let input = getFloat64(-.signalingNaN) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(+.signalingNaN)_AlwaysTraps") { - let input = getFloat64(+.signalingNaN) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat64(+.signalingNaN)_AlwaysFails") { - let input = getFloat64(+.signalingNaN) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt16 +.test("FromFloat64_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getFloat64(-0.5)), + (getUInt16(+0), getFloat64(+0)), + (getUInt16(+0), getFloat64(-0)), + (getUInt16(+0), getFloat64(+0.5)), + (getUInt16(+127), getFloat64(+127.5)), + (getUInt16(+255), getFloat64(+255.5)), + (getUInt16(+32767), getFloat64(+32767.5)), + (getUInt16(+65535), getFloat64(+65535)), + (getUInt16(+65535), getFloat64(+65535.5)), +]) { + expectEqual($0.0, UInt16($0.1)) +} + +FixedPointConversion_Release32_ToUInt16 +.test("FromFloat64_NeverFails") +.forEach(in: [ + (getUInt16(+0), getFloat64(+0)), + (getUInt16(+0), getFloat64(-0)), + (getUInt16(+65535), getFloat64(+65535)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToUInt16 +.test("FromFloat64_AlwaysTraps") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-1), + getFloat64(+65536), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt16($0)) +} + +FixedPointConversion_Release32_ToUInt16 +.test("FromFloat64_AlwaysFails") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-1), + getFloat64(-0.5), + getFloat64(+0.5), + getFloat64(+127.5), + getFloat64(+255.5), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(+65536), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectNil(UInt16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float80: (-18446744073709551615)...(18446744073709551615) +// MARK: Float80: (-18446744073709551615)...(+18446744073709551615) //===----------------------------------------------------------------------===// #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(-18446744073709551615)_AlwaysTraps") { - let input = getFloat80(-18446744073709551615) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(-18446744073709551615)_AlwaysFails") { - let input = getFloat80(-18446744073709551615) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(-32768.5)_AlwaysTraps") { - let input = getFloat80(-32768.5) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(-32768.5)_AlwaysFails") { - let input = getFloat80(-32768.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(-128.5)_AlwaysTraps") { - let input = getFloat80(-128.5) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(-128.5)_AlwaysFails") { - let input = getFloat80(-128.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(-1)_AlwaysTraps") { - let input = getFloat80(-1) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(-1)_AlwaysFails") { - let input = getFloat80(-1) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(-0.5)_NeverTraps") { - let input = getFloat80(-0.5) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(-0.5)_AlwaysFails") { - let input = getFloat80(-0.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(0)_NeverTraps") { - let input = getFloat80(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(0)_NeverFails") { - let input = getFloat80(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(-0.0)_NeverTraps") { - let input = getFloat80(-0.0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(-0.0)_NeverFails") { - let input = getFloat80(-0.0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(0.0)_NeverTraps") { - let input = getFloat80(0.0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(0.0)_NeverFails") { - let input = getFloat80(0.0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(0.5)_NeverTraps") { - let input = getFloat80(0.5) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(0.5)_AlwaysFails") { - let input = getFloat80(0.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(127.5)_NeverTraps") { - let input = getFloat80(127.5) - let actual = UInt16(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(127.5)_AlwaysFails") { - let input = getFloat80(127.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(255.5)_NeverTraps") { - let input = getFloat80(255.5) - let actual = UInt16(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(255.5)_AlwaysFails") { - let input = getFloat80(255.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(32767.5)_NeverTraps") { - let input = getFloat80(32767.5) - let actual = UInt16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(32767.5)_AlwaysFails") { - let input = getFloat80(32767.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(65535)_NeverTraps") { - let input = getFloat80(65535) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(65535)_NeverFails") { - let input = getFloat80(65535) - let actual = UInt16(exactly: input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(65535.5)_NeverTraps") { - let input = getFloat80(65535.5) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(65535.5)_AlwaysFails") { - let input = getFloat80(65535.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(65536)_AlwaysTraps") { - let input = getFloat80(65536) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(65536)_AlwaysFails") { - let input = getFloat80(65536) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(18446744073709551615)_AlwaysTraps") { - let input = getFloat80(18446744073709551615) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(18446744073709551615)_AlwaysFails") { - let input = getFloat80(18446744073709551615) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(-.infinity)_AlwaysTraps") { - let input = getFloat80(-.infinity) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(-.infinity)_AlwaysFails") { - let input = getFloat80(-.infinity) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(+.infinity)_AlwaysTraps") { - let input = getFloat80(+.infinity) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(+.infinity)_AlwaysFails") { - let input = getFloat80(+.infinity) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(-.nan)_AlwaysTraps") { - let input = getFloat80(-.nan) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(-.nan)_AlwaysFails") { - let input = getFloat80(-.nan) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(+.nan)_AlwaysTraps") { - let input = getFloat80(+.nan) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(+.nan)_AlwaysFails") { - let input = getFloat80(+.nan) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(-.signalingNaN)_AlwaysTraps") { - let input = getFloat80(-.signalingNaN) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(-.signalingNaN)_AlwaysFails") { - let input = getFloat80(-.signalingNaN) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(+.signalingNaN)_AlwaysTraps") { - let input = getFloat80(+.signalingNaN) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt16.test("FromFloat80(+.signalingNaN)_AlwaysFails") { - let input = getFloat80(+.signalingNaN) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt16 +.test("FromFloat80_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getFloat80(-0.5)), + (getUInt16(+0), getFloat80(+0)), + (getUInt16(+0), getFloat80(-0)), + (getUInt16(+0), getFloat80(+0.5)), + (getUInt16(+127), getFloat80(+127.5)), + (getUInt16(+255), getFloat80(+255.5)), + (getUInt16(+32767), getFloat80(+32767.5)), + (getUInt16(+65535), getFloat80(+65535)), + (getUInt16(+65535), getFloat80(+65535.5)), +]) { + expectEqual($0.0, UInt16($0.1)) +} + +FixedPointConversion_Release32_ToUInt16 +.test("FromFloat80_NeverFails") +.forEach(in: [ + (getUInt16(+0), getFloat80(+0)), + (getUInt16(+0), getFloat80(-0)), + (getUInt16(+65535), getFloat80(+65535)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToUInt16 +.test("FromFloat80_AlwaysTraps") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-1), + getFloat80(+65536), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt16($0)) +} + +FixedPointConversion_Release32_ToUInt16 +.test("FromFloat80_AlwaysFails") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-1), + getFloat80(-0.5), + getFloat80(+0.5), + getFloat80(+127.5), + getFloat80(+255.5), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(+65536), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectNil(UInt16(exactly: $0)) } #endif // Float80 diff --git a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release32_ToUInt32.swift b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release32_ToUInt32.swift index 30ec298fbd44f..7bee031441fda 100644 --- a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release32_ToUInt32.swift +++ b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release32_ToUInt32.swift @@ -5,7 +5,7 @@ // //===----------------------------------------------------------------------===// // -// REQUIRES: executable_test, long_test +// REQUIRES: executable_test // REQUIRES: PTRSIZE=32 // RUN: %target-run-simple-swift(-O) // END. @@ -14,1564 +14,640 @@ import StdlibUnittest -let FixedPointConversion_Release32_ToUInt32 = TestSuite("FixedPointConversion_Release32_ToUInt32") +let FixedPointConversion_Release32_ToUInt32 = TestSuite( + "FixedPointConversion_Release32_ToUInt32" +) //===----------------------------------------------------------------------===// -// MARK: UInt8: (0)...(255) +// MARK: UInt8: (+0)...(+255) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt32.test("FromUInt8(0)_NeverTraps") { - let input = getUInt8(0) - let actual = UInt32(input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToUInt32 +.test("FromUInt8_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getUInt8(+0)), + (getUInt32(+255), getUInt8(+255)), +]) { + expectEqual($0.0, UInt32($0.1)) } -FixedPointConversion_Release32_ToUInt32.test("FromUInt8(0)_NeverFails") { - let input = getUInt8(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromUInt8(255)_NeverTraps") { - let input = getUInt8(255) - let actual = UInt32(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromUInt8(255)_NeverFails") { - let input = getUInt8(255) - let actual = UInt32(exactly: input) - expectEqual(255, actual) +FixedPointConversion_Release32_ToUInt32 +.test("FromUInt8_NeverFails") +.forEach(in: [ + (getUInt32(+0), getUInt8(+0)), + (getUInt32(+255), getUInt8(+255)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int8: (-128)...(127) +// MARK: Int8: (-128)...(+127) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt32.test("FromInt8(-128)_AlwaysTraps") { - let input = getInt8(-128) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } +FixedPointConversion_Release32_ToUInt32 +.test("FromInt8_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getInt8(+0)), + (getUInt32(+127), getInt8(+127)), +]) { + expectEqual($0.0, UInt32($0.1)) } -FixedPointConversion_Release32_ToUInt32.test("FromInt8(-128)_AlwaysFails") { - let input = getInt8(-128) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt32 +.test("FromInt8_NeverFails") +.forEach(in: [ + (getUInt32(+0), getInt8(+0)), + (getUInt32(+127), getInt8(+127)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) } -FixedPointConversion_Release32_ToUInt32.test("FromInt8(-1)_AlwaysTraps") { - let input = getInt8(-1) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } +FixedPointConversion_Release32_ToUInt32 +.test("FromInt8_AlwaysTraps") +.forEach(in: [ + getInt8(-128), + getInt8(-1), +]) { + expectCrashLater() + _blackHole(UInt32($0)) } -FixedPointConversion_Release32_ToUInt32.test("FromInt8(-1)_AlwaysFails") { - let input = getInt8(-1) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromInt8(0)_NeverTraps") { - let input = getInt8(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromInt8(0)_NeverFails") { - let input = getInt8(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromInt8(127)_NeverTraps") { - let input = getInt8(127) - let actual = UInt32(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromInt8(127)_NeverFails") { - let input = getInt8(127) - let actual = UInt32(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Release32_ToUInt32 +.test("FromInt8_AlwaysFails") +.forEach(in: [ + getInt8(-128), + getInt8(-1), +]) { + expectNil(UInt32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt16: (0)...(65535) +// MARK: UInt16: (+0)...(+65535) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt32.test("FromUInt16(0)_NeverTraps") { - let input = getUInt16(0) - let actual = UInt32(input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToUInt32 +.test("FromUInt16_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getUInt16(+0)), + (getUInt32(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, UInt32($0.1)) } -FixedPointConversion_Release32_ToUInt32.test("FromUInt16(0)_NeverFails") { - let input = getUInt16(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromUInt16(65535)_NeverTraps") { - let input = getUInt16(65535) - let actual = UInt32(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromUInt16(65535)_NeverFails") { - let input = getUInt16(65535) - let actual = UInt32(exactly: input) - expectEqual(65535, actual) +FixedPointConversion_Release32_ToUInt32 +.test("FromUInt16_NeverFails") +.forEach(in: [ + (getUInt32(+0), getUInt16(+0)), + (getUInt32(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int16: (-32768)...(32767) +// MARK: Int16: (-32768)...(+32767) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt32.test("FromInt16(-32768)_AlwaysTraps") { - let input = getInt16(-32768) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromInt16(-32768)_AlwaysFails") { - let input = getInt16(-32768) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromInt16(-1)_AlwaysTraps") { - let input = getInt16(-1) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromInt16(-1)_AlwaysFails") { - let input = getInt16(-1) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt32 +.test("FromInt16_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getInt16(+0)), + (getUInt32(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, UInt32($0.1)) } -FixedPointConversion_Release32_ToUInt32.test("FromInt16(0)_NeverTraps") { - let input = getInt16(0) - let actual = UInt32(input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToUInt32 +.test("FromInt16_NeverFails") +.forEach(in: [ + (getUInt32(+0), getInt16(+0)), + (getUInt32(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) } -FixedPointConversion_Release32_ToUInt32.test("FromInt16(0)_NeverFails") { - let input = getInt16(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToUInt32 +.test("FromInt16_AlwaysTraps") +.forEach(in: [ + getInt16(-32768), + getInt16(-1), +]) { + expectCrashLater() + _blackHole(UInt32($0)) } -FixedPointConversion_Release32_ToUInt32.test("FromInt16(32767)_NeverTraps") { - let input = getInt16(32767) - let actual = UInt32(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromInt16(32767)_NeverFails") { - let input = getInt16(32767) - let actual = UInt32(exactly: input) - expectEqual(32767, actual) +FixedPointConversion_Release32_ToUInt32 +.test("FromInt16_AlwaysFails") +.forEach(in: [ + getInt16(-32768), + getInt16(-1), +]) { + expectNil(UInt32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt32: (0)...(4294967295) +// MARK: UInt32: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt32.test("FromUInt32(0)_NeverTraps") { - let input = getUInt32(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromUInt32(0)_NeverFails") { - let input = getUInt32(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromUInt32(4294967295)_NeverTraps") { - let input = getUInt32(4294967295) - let actual = UInt32(input) - expectEqual(4294967295, actual) +FixedPointConversion_Release32_ToUInt32 +.test("FromUInt32_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getUInt32(+0)), + (getUInt32(+4294967295), getUInt32(+4294967295)), +]) { + expectEqual($0.0, UInt32($0.1)) } -FixedPointConversion_Release32_ToUInt32.test("FromUInt32(4294967295)_NeverFails") { - let input = getUInt32(4294967295) - let actual = UInt32(exactly: input) - expectEqual(4294967295, actual) +FixedPointConversion_Release32_ToUInt32 +.test("FromUInt32_NeverFails") +.forEach(in: [ + (getUInt32(+0), getUInt32(+0)), + (getUInt32(+4294967295), getUInt32(+4294967295)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int32: (-2147483648)...(2147483647) +// MARK: Int32: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt32.test("FromInt32(-2147483648)_AlwaysTraps") { - let input = getInt32(-2147483648) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromInt32(-2147483648)_AlwaysFails") { - let input = getInt32(-2147483648) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromInt32(-1)_AlwaysTraps") { - let input = getInt32(-1) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } +FixedPointConversion_Release32_ToUInt32 +.test("FromInt32_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getInt32(+0)), + (getUInt32(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, UInt32($0.1)) } -FixedPointConversion_Release32_ToUInt32.test("FromInt32(-1)_AlwaysFails") { - let input = getInt32(-1) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt32 +.test("FromInt32_NeverFails") +.forEach(in: [ + (getUInt32(+0), getInt32(+0)), + (getUInt32(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) } -FixedPointConversion_Release32_ToUInt32.test("FromInt32(0)_NeverTraps") { - let input = getInt32(0) - let actual = UInt32(input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToUInt32 +.test("FromInt32_AlwaysTraps") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-1), +]) { + expectCrashLater() + _blackHole(UInt32($0)) } -FixedPointConversion_Release32_ToUInt32.test("FromInt32(0)_NeverFails") { - let input = getInt32(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromInt32(2147483647)_NeverTraps") { - let input = getInt32(2147483647) - let actual = UInt32(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromInt32(2147483647)_NeverFails") { - let input = getInt32(2147483647) - let actual = UInt32(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Release32_ToUInt32 +.test("FromInt32_AlwaysFails") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-1), +]) { + expectNil(UInt32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt64: (0)...(18446744073709551615) +// MARK: UInt64: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt32.test("FromUInt64(0)_NeverTraps") { - let input = getUInt64(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromUInt64(0)_NeverFails") { - let input = getUInt64(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToUInt32 +.test("FromUInt64_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getUInt64(+0)), + (getUInt32(+4294967295), getUInt64(+4294967295)), +]) { + expectEqual($0.0, UInt32($0.1)) } -FixedPointConversion_Release32_ToUInt32.test("FromUInt64(4294967295)_NeverTraps") { - let input = getUInt64(4294967295) - let actual = UInt32(input) - expectEqual(4294967295, actual) +FixedPointConversion_Release32_ToUInt32 +.test("FromUInt64_NeverFails") +.forEach(in: [ + (getUInt32(+0), getUInt64(+0)), + (getUInt32(+4294967295), getUInt64(+4294967295)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) } -FixedPointConversion_Release32_ToUInt32.test("FromUInt64(4294967295)_NeverFails") { - let input = getUInt64(4294967295) - let actual = UInt32(exactly: input) - expectEqual(4294967295, actual) +FixedPointConversion_Release32_ToUInt32 +.test("FromUInt64_AlwaysTraps") +.forEach(in: [ + getUInt64(+4294967296), + getUInt64(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(UInt32($0)) } -FixedPointConversion_Release32_ToUInt32.test("FromUInt64(4294967296)_AlwaysTraps") { - let input = getUInt64(4294967296) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromUInt64(4294967296)_AlwaysFails") { - let input = getUInt64(4294967296) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromUInt64(18446744073709551615)_AlwaysTraps") { - let input = getUInt64(18446744073709551615) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromUInt64(18446744073709551615)_AlwaysFails") { - let input = getUInt64(18446744073709551615) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt32 +.test("FromUInt64_AlwaysFails") +.forEach(in: [ + getUInt64(+4294967296), + getUInt64(+18446744073709551615), +]) { + expectNil(UInt32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int64: (-9223372036854775808)...(9223372036854775807) +// MARK: Int64: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt32.test("FromInt64(-9223372036854775808)_AlwaysTraps") { - let input = getInt64(-9223372036854775808) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromInt64(-9223372036854775808)_AlwaysFails") { - let input = getInt64(-9223372036854775808) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromInt64(-1)_AlwaysTraps") { - let input = getInt64(-1) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromInt64(-1)_AlwaysFails") { - let input = getInt64(-1) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromInt64(0)_NeverTraps") { - let input = getInt64(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromInt64(0)_NeverFails") { - let input = getInt64(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromInt64(4294967295)_NeverTraps") { - let input = getInt64(4294967295) - let actual = UInt32(input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromInt64(4294967295)_NeverFails") { - let input = getInt64(4294967295) - let actual = UInt32(exactly: input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromInt64(4294967296)_AlwaysTraps") { - let input = getInt64(4294967296) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromInt64(4294967296)_AlwaysFails") { - let input = getInt64(4294967296) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromInt64(9223372036854775807)_AlwaysTraps") { - let input = getInt64(9223372036854775807) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromInt64(9223372036854775807)_AlwaysFails") { - let input = getInt64(9223372036854775807) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt32 +.test("FromInt64_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getInt64(+0)), + (getUInt32(+4294967295), getInt64(+4294967295)), +]) { + expectEqual($0.0, UInt32($0.1)) +} + +FixedPointConversion_Release32_ToUInt32 +.test("FromInt64_NeverFails") +.forEach(in: [ + (getUInt32(+0), getInt64(+0)), + (getUInt32(+4294967295), getInt64(+4294967295)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToUInt32 +.test("FromInt64_AlwaysTraps") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-1), + getInt64(+4294967296), + getInt64(+9223372036854775807), +]) { + expectCrashLater() + _blackHole(UInt32($0)) +} + +FixedPointConversion_Release32_ToUInt32 +.test("FromInt64_AlwaysFails") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-1), + getInt64(+4294967296), + getInt64(+9223372036854775807), +]) { + expectNil(UInt32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt: (0)...(4294967295) +// MARK: UInt: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt32.test("FromUInt(0)_NeverTraps") { - let input = getUInt(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromUInt(0)_NeverFails") { - let input = getUInt(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromUInt(4294967295)_NeverTraps") { - let input = getUInt(4294967295) - let actual = UInt32(input) - expectEqual(4294967295, actual) +FixedPointConversion_Release32_ToUInt32 +.test("FromUInt_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getUInt(+0)), + (getUInt32(+4294967295), getUInt(+4294967295)), +]) { + expectEqual($0.0, UInt32($0.1)) } -FixedPointConversion_Release32_ToUInt32.test("FromUInt(4294967295)_NeverFails") { - let input = getUInt(4294967295) - let actual = UInt32(exactly: input) - expectEqual(4294967295, actual) +FixedPointConversion_Release32_ToUInt32 +.test("FromUInt_NeverFails") +.forEach(in: [ + (getUInt32(+0), getUInt(+0)), + (getUInt32(+4294967295), getUInt(+4294967295)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int: (-2147483648)...(2147483647) +// MARK: Int: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt32.test("FromInt(-2147483648)_AlwaysTraps") { - let input = getInt(-2147483648) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromInt(-2147483648)_AlwaysFails") { - let input = getInt(-2147483648) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt32 +.test("FromInt_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getInt(+0)), + (getUInt32(+2147483647), getInt(+2147483647)), +]) { + expectEqual($0.0, UInt32($0.1)) } -FixedPointConversion_Release32_ToUInt32.test("FromInt(-1)_AlwaysTraps") { - let input = getInt(-1) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } +FixedPointConversion_Release32_ToUInt32 +.test("FromInt_NeverFails") +.forEach(in: [ + (getUInt32(+0), getInt(+0)), + (getUInt32(+2147483647), getInt(+2147483647)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) } -FixedPointConversion_Release32_ToUInt32.test("FromInt(-1)_AlwaysFails") { - let input = getInt(-1) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt32 +.test("FromInt_AlwaysTraps") +.forEach(in: [ + getInt(-2147483648), + getInt(-1), +]) { + expectCrashLater() + _blackHole(UInt32($0)) } -FixedPointConversion_Release32_ToUInt32.test("FromInt(0)_NeverTraps") { - let input = getInt(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromInt(0)_NeverFails") { - let input = getInt(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromInt(2147483647)_NeverTraps") { - let input = getInt(2147483647) - let actual = UInt32(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromInt(2147483647)_NeverFails") { - let input = getInt(2147483647) - let actual = UInt32(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Release32_ToUInt32 +.test("FromInt_AlwaysFails") +.forEach(in: [ + getInt(-2147483648), + getInt(-1), +]) { + expectNil(UInt32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float16: (-2047)...(2047) +// MARK: Float16: (-2047)...(+2047) //===----------------------------------------------------------------------===// #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -FixedPointConversion_Release32_ToUInt32.test("FromFloat16(-2047)_AlwaysTraps") { - let input = getFloat16(-2047) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat16(-2047)_AlwaysFails") { - let input = getFloat16(-2047) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat16(-128.5)_AlwaysTraps") { - let input = getFloat16(-128.5) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat16(-128.5)_AlwaysFails") { - let input = getFloat16(-128.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat16(-1)_AlwaysTraps") { - let input = getFloat16(-1) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat16(-1)_AlwaysFails") { - let input = getFloat16(-1) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat16(-0.5)_NeverTraps") { - let input = getFloat16(-0.5) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat16(-0.5)_AlwaysFails") { - let input = getFloat16(-0.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat16(0)_NeverTraps") { - let input = getFloat16(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat16(0)_NeverFails") { - let input = getFloat16(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat16(-0.0)_NeverTraps") { - let input = getFloat16(-0.0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat16(-0.0)_NeverFails") { - let input = getFloat16(-0.0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat16(0.0)_NeverTraps") { - let input = getFloat16(0.0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat16(0.0)_NeverFails") { - let input = getFloat16(0.0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat16(0.5)_NeverTraps") { - let input = getFloat16(0.5) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat16(0.5)_AlwaysFails") { - let input = getFloat16(0.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat16(127.5)_NeverTraps") { - let input = getFloat16(127.5) - let actual = UInt32(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat16(127.5)_AlwaysFails") { - let input = getFloat16(127.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat16(255.5)_NeverTraps") { - let input = getFloat16(255.5) - let actual = UInt32(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat16(255.5)_AlwaysFails") { - let input = getFloat16(255.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat16(2047)_NeverTraps") { - let input = getFloat16(2047) - let actual = UInt32(input) - expectEqual(2047, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat16(2047)_NeverFails") { - let input = getFloat16(2047) - let actual = UInt32(exactly: input) - expectEqual(2047, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat16(-.infinity)_AlwaysTraps") { - let input = getFloat16(-.infinity) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat16(-.infinity)_AlwaysFails") { - let input = getFloat16(-.infinity) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat16(+.infinity)_AlwaysTraps") { - let input = getFloat16(+.infinity) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat16(+.infinity)_AlwaysFails") { - let input = getFloat16(+.infinity) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat16(-.nan)_AlwaysTraps") { - let input = getFloat16(-.nan) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat16(-.nan)_AlwaysFails") { - let input = getFloat16(-.nan) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat16(+.nan)_AlwaysTraps") { - let input = getFloat16(+.nan) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat16(+.nan)_AlwaysFails") { - let input = getFloat16(+.nan) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat16(-.signalingNaN)_AlwaysTraps") { - let input = getFloat16(-.signalingNaN) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat16(-.signalingNaN)_AlwaysFails") { - let input = getFloat16(-.signalingNaN) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat16(+.signalingNaN)_AlwaysTraps") { - let input = getFloat16(+.signalingNaN) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat16(+.signalingNaN)_AlwaysFails") { - let input = getFloat16(+.signalingNaN) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt32 +.test("FromFloat16_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getFloat16(-0.5)), + (getUInt32(+0), getFloat16(+0)), + (getUInt32(+0), getFloat16(-0)), + (getUInt32(+0), getFloat16(+0.5)), + (getUInt32(+127), getFloat16(+127.5)), + (getUInt32(+255), getFloat16(+255.5)), + (getUInt32(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, UInt32($0.1)) +} + +FixedPointConversion_Release32_ToUInt32 +.test("FromFloat16_NeverFails") +.forEach(in: [ + (getUInt32(+0), getFloat16(+0)), + (getUInt32(+0), getFloat16(-0)), + (getUInt32(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToUInt32 +.test("FromFloat16_AlwaysTraps") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-128.5), + getFloat16(-1), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt32($0)) +} + +FixedPointConversion_Release32_ToUInt32 +.test("FromFloat16_AlwaysFails") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-128.5), + getFloat16(-1), + getFloat16(-0.5), + getFloat16(+0.5), + getFloat16(+127.5), + getFloat16(+255.5), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectNil(UInt32(exactly: $0)) } } #endif // Float16 //===----------------------------------------------------------------------===// -// MARK: Float32: (-16777215)...(16777215) +// MARK: Float32: (-16777215)...(+16777215) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt32.test("FromFloat32(-16777215)_AlwaysTraps") { - let input = getFloat32(-16777215) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat32(-16777215)_AlwaysFails") { - let input = getFloat32(-16777215) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat32(-32768.5)_AlwaysTraps") { - let input = getFloat32(-32768.5) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat32(-32768.5)_AlwaysFails") { - let input = getFloat32(-32768.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat32(-128.5)_AlwaysTraps") { - let input = getFloat32(-128.5) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat32(-128.5)_AlwaysFails") { - let input = getFloat32(-128.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat32(-1)_AlwaysTraps") { - let input = getFloat32(-1) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat32(-1)_AlwaysFails") { - let input = getFloat32(-1) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat32(-0.5)_NeverTraps") { - let input = getFloat32(-0.5) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat32(-0.5)_AlwaysFails") { - let input = getFloat32(-0.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat32(0)_NeverTraps") { - let input = getFloat32(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat32(0)_NeverFails") { - let input = getFloat32(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat32(-0.0)_NeverTraps") { - let input = getFloat32(-0.0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat32(-0.0)_NeverFails") { - let input = getFloat32(-0.0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat32(0.0)_NeverTraps") { - let input = getFloat32(0.0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat32(0.0)_NeverFails") { - let input = getFloat32(0.0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat32(0.5)_NeverTraps") { - let input = getFloat32(0.5) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat32(0.5)_AlwaysFails") { - let input = getFloat32(0.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat32(127.5)_NeverTraps") { - let input = getFloat32(127.5) - let actual = UInt32(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat32(127.5)_AlwaysFails") { - let input = getFloat32(127.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat32(255.5)_NeverTraps") { - let input = getFloat32(255.5) - let actual = UInt32(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat32(255.5)_AlwaysFails") { - let input = getFloat32(255.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat32(32767.5)_NeverTraps") { - let input = getFloat32(32767.5) - let actual = UInt32(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat32(32767.5)_AlwaysFails") { - let input = getFloat32(32767.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat32(65535.5)_NeverTraps") { - let input = getFloat32(65535.5) - let actual = UInt32(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat32(65535.5)_AlwaysFails") { - let input = getFloat32(65535.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat32(16777215)_NeverTraps") { - let input = getFloat32(16777215) - let actual = UInt32(input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat32(16777215)_NeverFails") { - let input = getFloat32(16777215) - let actual = UInt32(exactly: input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat32(-.infinity)_AlwaysTraps") { - let input = getFloat32(-.infinity) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat32(-.infinity)_AlwaysFails") { - let input = getFloat32(-.infinity) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat32(+.infinity)_AlwaysTraps") { - let input = getFloat32(+.infinity) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat32(+.infinity)_AlwaysFails") { - let input = getFloat32(+.infinity) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat32(-.nan)_AlwaysTraps") { - let input = getFloat32(-.nan) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat32(-.nan)_AlwaysFails") { - let input = getFloat32(-.nan) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat32(+.nan)_AlwaysTraps") { - let input = getFloat32(+.nan) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat32(+.nan)_AlwaysFails") { - let input = getFloat32(+.nan) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat32(-.signalingNaN)_AlwaysTraps") { - let input = getFloat32(-.signalingNaN) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat32(-.signalingNaN)_AlwaysFails") { - let input = getFloat32(-.signalingNaN) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat32(+.signalingNaN)_AlwaysTraps") { - let input = getFloat32(+.signalingNaN) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat32(+.signalingNaN)_AlwaysFails") { - let input = getFloat32(+.signalingNaN) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt32 +.test("FromFloat32_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getFloat32(-0.5)), + (getUInt32(+0), getFloat32(+0)), + (getUInt32(+0), getFloat32(-0)), + (getUInt32(+0), getFloat32(+0.5)), + (getUInt32(+127), getFloat32(+127.5)), + (getUInt32(+255), getFloat32(+255.5)), + (getUInt32(+32767), getFloat32(+32767.5)), + (getUInt32(+65535), getFloat32(+65535.5)), + (getUInt32(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, UInt32($0.1)) +} + +FixedPointConversion_Release32_ToUInt32 +.test("FromFloat32_NeverFails") +.forEach(in: [ + (getUInt32(+0), getFloat32(+0)), + (getUInt32(+0), getFloat32(-0)), + (getUInt32(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToUInt32 +.test("FromFloat32_AlwaysTraps") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-1), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt32($0)) +} + +FixedPointConversion_Release32_ToUInt32 +.test("FromFloat32_AlwaysFails") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-1), + getFloat32(-0.5), + getFloat32(+0.5), + getFloat32(+127.5), + getFloat32(+255.5), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectNil(UInt32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float64: (-9007199254740991)...(9007199254740991) +// MARK: Float64: (-9007199254740991)...(+9007199254740991) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(-9007199254740991)_AlwaysTraps") { - let input = getFloat64(-9007199254740991) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(-9007199254740991)_AlwaysFails") { - let input = getFloat64(-9007199254740991) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(-32768.5)_AlwaysTraps") { - let input = getFloat64(-32768.5) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(-32768.5)_AlwaysFails") { - let input = getFloat64(-32768.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(-128.5)_AlwaysTraps") { - let input = getFloat64(-128.5) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(-128.5)_AlwaysFails") { - let input = getFloat64(-128.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(-1)_AlwaysTraps") { - let input = getFloat64(-1) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(-1)_AlwaysFails") { - let input = getFloat64(-1) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(-0.5)_NeverTraps") { - let input = getFloat64(-0.5) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(-0.5)_AlwaysFails") { - let input = getFloat64(-0.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(0)_NeverTraps") { - let input = getFloat64(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(0)_NeverFails") { - let input = getFloat64(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(-0.0)_NeverTraps") { - let input = getFloat64(-0.0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(-0.0)_NeverFails") { - let input = getFloat64(-0.0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(0.0)_NeverTraps") { - let input = getFloat64(0.0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(0.0)_NeverFails") { - let input = getFloat64(0.0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(0.5)_NeverTraps") { - let input = getFloat64(0.5) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(0.5)_AlwaysFails") { - let input = getFloat64(0.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(127.5)_NeverTraps") { - let input = getFloat64(127.5) - let actual = UInt32(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(127.5)_AlwaysFails") { - let input = getFloat64(127.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(255.5)_NeverTraps") { - let input = getFloat64(255.5) - let actual = UInt32(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(255.5)_AlwaysFails") { - let input = getFloat64(255.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(32767.5)_NeverTraps") { - let input = getFloat64(32767.5) - let actual = UInt32(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(32767.5)_AlwaysFails") { - let input = getFloat64(32767.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(65535.5)_NeverTraps") { - let input = getFloat64(65535.5) - let actual = UInt32(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(65535.5)_AlwaysFails") { - let input = getFloat64(65535.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(4294967295)_NeverTraps") { - let input = getFloat64(4294967295) - let actual = UInt32(input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(4294967295)_NeverFails") { - let input = getFloat64(4294967295) - let actual = UInt32(exactly: input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(4294967296)_AlwaysTraps") { - let input = getFloat64(4294967296) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(4294967296)_AlwaysFails") { - let input = getFloat64(4294967296) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(9007199254740991)_AlwaysTraps") { - let input = getFloat64(9007199254740991) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(9007199254740991)_AlwaysFails") { - let input = getFloat64(9007199254740991) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(-.infinity)_AlwaysTraps") { - let input = getFloat64(-.infinity) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(-.infinity)_AlwaysFails") { - let input = getFloat64(-.infinity) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(+.infinity)_AlwaysTraps") { - let input = getFloat64(+.infinity) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(+.infinity)_AlwaysFails") { - let input = getFloat64(+.infinity) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(-.nan)_AlwaysTraps") { - let input = getFloat64(-.nan) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(-.nan)_AlwaysFails") { - let input = getFloat64(-.nan) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(+.nan)_AlwaysTraps") { - let input = getFloat64(+.nan) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(+.nan)_AlwaysFails") { - let input = getFloat64(+.nan) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(-.signalingNaN)_AlwaysTraps") { - let input = getFloat64(-.signalingNaN) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(-.signalingNaN)_AlwaysFails") { - let input = getFloat64(-.signalingNaN) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(+.signalingNaN)_AlwaysTraps") { - let input = getFloat64(+.signalingNaN) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat64(+.signalingNaN)_AlwaysFails") { - let input = getFloat64(+.signalingNaN) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt32 +.test("FromFloat64_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getFloat64(-0.5)), + (getUInt32(+0), getFloat64(+0)), + (getUInt32(+0), getFloat64(-0)), + (getUInt32(+0), getFloat64(+0.5)), + (getUInt32(+127), getFloat64(+127.5)), + (getUInt32(+255), getFloat64(+255.5)), + (getUInt32(+32767), getFloat64(+32767.5)), + (getUInt32(+65535), getFloat64(+65535.5)), + (getUInt32(+4294967295), getFloat64(+4294967295)), +]) { + expectEqual($0.0, UInt32($0.1)) +} + +FixedPointConversion_Release32_ToUInt32 +.test("FromFloat64_NeverFails") +.forEach(in: [ + (getUInt32(+0), getFloat64(+0)), + (getUInt32(+0), getFloat64(-0)), + (getUInt32(+4294967295), getFloat64(+4294967295)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToUInt32 +.test("FromFloat64_AlwaysTraps") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-1), + getFloat64(+4294967296), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt32($0)) +} + +FixedPointConversion_Release32_ToUInt32 +.test("FromFloat64_AlwaysFails") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-1), + getFloat64(-0.5), + getFloat64(+0.5), + getFloat64(+127.5), + getFloat64(+255.5), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(+4294967296), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectNil(UInt32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float80: (-18446744073709551615)...(18446744073709551615) +// MARK: Float80: (-18446744073709551615)...(+18446744073709551615) //===----------------------------------------------------------------------===// #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(-18446744073709551615)_AlwaysTraps") { - let input = getFloat80(-18446744073709551615) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(-18446744073709551615)_AlwaysFails") { - let input = getFloat80(-18446744073709551615) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(-32768.5)_AlwaysTraps") { - let input = getFloat80(-32768.5) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(-32768.5)_AlwaysFails") { - let input = getFloat80(-32768.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(-128.5)_AlwaysTraps") { - let input = getFloat80(-128.5) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(-128.5)_AlwaysFails") { - let input = getFloat80(-128.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(-1)_AlwaysTraps") { - let input = getFloat80(-1) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(-1)_AlwaysFails") { - let input = getFloat80(-1) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(-0.5)_NeverTraps") { - let input = getFloat80(-0.5) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(-0.5)_AlwaysFails") { - let input = getFloat80(-0.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(0)_NeverTraps") { - let input = getFloat80(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(0)_NeverFails") { - let input = getFloat80(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(-0.0)_NeverTraps") { - let input = getFloat80(-0.0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(-0.0)_NeverFails") { - let input = getFloat80(-0.0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(0.0)_NeverTraps") { - let input = getFloat80(0.0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(0.0)_NeverFails") { - let input = getFloat80(0.0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(0.5)_NeverTraps") { - let input = getFloat80(0.5) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(0.5)_AlwaysFails") { - let input = getFloat80(0.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(127.5)_NeverTraps") { - let input = getFloat80(127.5) - let actual = UInt32(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(127.5)_AlwaysFails") { - let input = getFloat80(127.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(255.5)_NeverTraps") { - let input = getFloat80(255.5) - let actual = UInt32(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(255.5)_AlwaysFails") { - let input = getFloat80(255.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(32767.5)_NeverTraps") { - let input = getFloat80(32767.5) - let actual = UInt32(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(32767.5)_AlwaysFails") { - let input = getFloat80(32767.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(65535.5)_NeverTraps") { - let input = getFloat80(65535.5) - let actual = UInt32(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(65535.5)_AlwaysFails") { - let input = getFloat80(65535.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(4294967295)_NeverTraps") { - let input = getFloat80(4294967295) - let actual = UInt32(input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(4294967295)_NeverFails") { - let input = getFloat80(4294967295) - let actual = UInt32(exactly: input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(4294967296)_AlwaysTraps") { - let input = getFloat80(4294967296) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(4294967296)_AlwaysFails") { - let input = getFloat80(4294967296) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(18446744073709551615)_AlwaysTraps") { - let input = getFloat80(18446744073709551615) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(18446744073709551615)_AlwaysFails") { - let input = getFloat80(18446744073709551615) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(-.infinity)_AlwaysTraps") { - let input = getFloat80(-.infinity) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(-.infinity)_AlwaysFails") { - let input = getFloat80(-.infinity) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(+.infinity)_AlwaysTraps") { - let input = getFloat80(+.infinity) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(+.infinity)_AlwaysFails") { - let input = getFloat80(+.infinity) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(-.nan)_AlwaysTraps") { - let input = getFloat80(-.nan) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(-.nan)_AlwaysFails") { - let input = getFloat80(-.nan) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(+.nan)_AlwaysTraps") { - let input = getFloat80(+.nan) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(+.nan)_AlwaysFails") { - let input = getFloat80(+.nan) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(-.signalingNaN)_AlwaysTraps") { - let input = getFloat80(-.signalingNaN) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(-.signalingNaN)_AlwaysFails") { - let input = getFloat80(-.signalingNaN) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(+.signalingNaN)_AlwaysTraps") { - let input = getFloat80(+.signalingNaN) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt32.test("FromFloat80(+.signalingNaN)_AlwaysFails") { - let input = getFloat80(+.signalingNaN) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt32 +.test("FromFloat80_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getFloat80(-0.5)), + (getUInt32(+0), getFloat80(+0)), + (getUInt32(+0), getFloat80(-0)), + (getUInt32(+0), getFloat80(+0.5)), + (getUInt32(+127), getFloat80(+127.5)), + (getUInt32(+255), getFloat80(+255.5)), + (getUInt32(+32767), getFloat80(+32767.5)), + (getUInt32(+65535), getFloat80(+65535.5)), + (getUInt32(+4294967295), getFloat80(+4294967295)), +]) { + expectEqual($0.0, UInt32($0.1)) +} + +FixedPointConversion_Release32_ToUInt32 +.test("FromFloat80_NeverFails") +.forEach(in: [ + (getUInt32(+0), getFloat80(+0)), + (getUInt32(+0), getFloat80(-0)), + (getUInt32(+4294967295), getFloat80(+4294967295)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToUInt32 +.test("FromFloat80_AlwaysTraps") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-1), + getFloat80(+4294967296), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt32($0)) +} + +FixedPointConversion_Release32_ToUInt32 +.test("FromFloat80_AlwaysFails") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-1), + getFloat80(-0.5), + getFloat80(+0.5), + getFloat80(+127.5), + getFloat80(+255.5), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(+4294967296), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectNil(UInt32(exactly: $0)) } #endif // Float80 diff --git a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release32_ToUInt64.swift b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release32_ToUInt64.swift index 7c3af0cd23c09..c54ec1231691b 100644 --- a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release32_ToUInt64.swift +++ b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release32_ToUInt64.swift @@ -5,7 +5,7 @@ // //===----------------------------------------------------------------------===// // -// REQUIRES: executable_test, long_test +// REQUIRES: executable_test // REQUIRES: PTRSIZE=32 // RUN: %target-run-simple-swift(-O) // END. @@ -14,1464 +14,609 @@ import StdlibUnittest -let FixedPointConversion_Release32_ToUInt64 = TestSuite("FixedPointConversion_Release32_ToUInt64") +let FixedPointConversion_Release32_ToUInt64 = TestSuite( + "FixedPointConversion_Release32_ToUInt64" +) //===----------------------------------------------------------------------===// -// MARK: UInt8: (0)...(255) +// MARK: UInt8: (+0)...(+255) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt64.test("FromUInt8(0)_NeverTraps") { - let input = getUInt8(0) - let actual = UInt64(input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToUInt64 +.test("FromUInt8_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getUInt8(+0)), + (getUInt64(+255), getUInt8(+255)), +]) { + expectEqual($0.0, UInt64($0.1)) } -FixedPointConversion_Release32_ToUInt64.test("FromUInt8(0)_NeverFails") { - let input = getUInt8(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromUInt8(255)_NeverTraps") { - let input = getUInt8(255) - let actual = UInt64(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromUInt8(255)_NeverFails") { - let input = getUInt8(255) - let actual = UInt64(exactly: input) - expectEqual(255, actual) +FixedPointConversion_Release32_ToUInt64 +.test("FromUInt8_NeverFails") +.forEach(in: [ + (getUInt64(+0), getUInt8(+0)), + (getUInt64(+255), getUInt8(+255)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int8: (-128)...(127) +// MARK: Int8: (-128)...(+127) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt64.test("FromInt8(-128)_AlwaysTraps") { - let input = getInt8(-128) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromInt8(-128)_AlwaysFails") { - let input = getInt8(-128) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromInt8(-1)_AlwaysTraps") { - let input = getInt8(-1) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromInt8(-1)_AlwaysFails") { - let input = getInt8(-1) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromInt8(0)_NeverTraps") { - let input = getInt8(0) - let actual = UInt64(input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToUInt64 +.test("FromInt8_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getInt8(+0)), + (getUInt64(+127), getInt8(+127)), +]) { + expectEqual($0.0, UInt64($0.1)) } -FixedPointConversion_Release32_ToUInt64.test("FromInt8(0)_NeverFails") { - let input = getInt8(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToUInt64 +.test("FromInt8_NeverFails") +.forEach(in: [ + (getUInt64(+0), getInt8(+0)), + (getUInt64(+127), getInt8(+127)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) } -FixedPointConversion_Release32_ToUInt64.test("FromInt8(127)_NeverTraps") { - let input = getInt8(127) - let actual = UInt64(input) - expectEqual(127, actual) +FixedPointConversion_Release32_ToUInt64 +.test("FromInt8_AlwaysTraps") +.forEach(in: [ + getInt8(-128), + getInt8(-1), +]) { + expectCrashLater() + _blackHole(UInt64($0)) } -FixedPointConversion_Release32_ToUInt64.test("FromInt8(127)_NeverFails") { - let input = getInt8(127) - let actual = UInt64(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Release32_ToUInt64 +.test("FromInt8_AlwaysFails") +.forEach(in: [ + getInt8(-128), + getInt8(-1), +]) { + expectNil(UInt64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt16: (0)...(65535) +// MARK: UInt16: (+0)...(+65535) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt64.test("FromUInt16(0)_NeverTraps") { - let input = getUInt16(0) - let actual = UInt64(input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToUInt64 +.test("FromUInt16_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getUInt16(+0)), + (getUInt64(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, UInt64($0.1)) } -FixedPointConversion_Release32_ToUInt64.test("FromUInt16(0)_NeverFails") { - let input = getUInt16(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromUInt16(65535)_NeverTraps") { - let input = getUInt16(65535) - let actual = UInt64(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromUInt16(65535)_NeverFails") { - let input = getUInt16(65535) - let actual = UInt64(exactly: input) - expectEqual(65535, actual) +FixedPointConversion_Release32_ToUInt64 +.test("FromUInt16_NeverFails") +.forEach(in: [ + (getUInt64(+0), getUInt16(+0)), + (getUInt64(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int16: (-32768)...(32767) +// MARK: Int16: (-32768)...(+32767) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt64.test("FromInt16(-32768)_AlwaysTraps") { - let input = getInt16(-32768) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromInt16(-32768)_AlwaysFails") { - let input = getInt16(-32768) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromInt16(-1)_AlwaysTraps") { - let input = getInt16(-1) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromInt16(-1)_AlwaysFails") { - let input = getInt16(-1) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromInt16(0)_NeverTraps") { - let input = getInt16(0) - let actual = UInt64(input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToUInt64 +.test("FromInt16_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getInt16(+0)), + (getUInt64(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, UInt64($0.1)) } -FixedPointConversion_Release32_ToUInt64.test("FromInt16(0)_NeverFails") { - let input = getInt16(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToUInt64 +.test("FromInt16_NeverFails") +.forEach(in: [ + (getUInt64(+0), getInt16(+0)), + (getUInt64(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) } -FixedPointConversion_Release32_ToUInt64.test("FromInt16(32767)_NeverTraps") { - let input = getInt16(32767) - let actual = UInt64(input) - expectEqual(32767, actual) +FixedPointConversion_Release32_ToUInt64 +.test("FromInt16_AlwaysTraps") +.forEach(in: [ + getInt16(-32768), + getInt16(-1), +]) { + expectCrashLater() + _blackHole(UInt64($0)) } -FixedPointConversion_Release32_ToUInt64.test("FromInt16(32767)_NeverFails") { - let input = getInt16(32767) - let actual = UInt64(exactly: input) - expectEqual(32767, actual) +FixedPointConversion_Release32_ToUInt64 +.test("FromInt16_AlwaysFails") +.forEach(in: [ + getInt16(-32768), + getInt16(-1), +]) { + expectNil(UInt64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt32: (0)...(4294967295) +// MARK: UInt32: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt64.test("FromUInt32(0)_NeverTraps") { - let input = getUInt32(0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromUInt32(0)_NeverFails") { - let input = getUInt32(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToUInt64 +.test("FromUInt32_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getUInt32(+0)), + (getUInt64(+4294967295), getUInt32(+4294967295)), +]) { + expectEqual($0.0, UInt64($0.1)) } -FixedPointConversion_Release32_ToUInt64.test("FromUInt32(4294967295)_NeverTraps") { - let input = getUInt32(4294967295) - let actual = UInt64(input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromUInt32(4294967295)_NeverFails") { - let input = getUInt32(4294967295) - let actual = UInt64(exactly: input) - expectEqual(4294967295, actual) +FixedPointConversion_Release32_ToUInt64 +.test("FromUInt32_NeverFails") +.forEach(in: [ + (getUInt64(+0), getUInt32(+0)), + (getUInt64(+4294967295), getUInt32(+4294967295)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int32: (-2147483648)...(2147483647) +// MARK: Int32: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt64.test("FromInt32(-2147483648)_AlwaysTraps") { - let input = getInt32(-2147483648) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromInt32(-2147483648)_AlwaysFails") { - let input = getInt32(-2147483648) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromInt32(-1)_AlwaysTraps") { - let input = getInt32(-1) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } +FixedPointConversion_Release32_ToUInt64 +.test("FromInt32_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getInt32(+0)), + (getUInt64(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, UInt64($0.1)) } -FixedPointConversion_Release32_ToUInt64.test("FromInt32(-1)_AlwaysFails") { - let input = getInt32(-1) - let actual = UInt64(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt64 +.test("FromInt32_NeverFails") +.forEach(in: [ + (getUInt64(+0), getInt32(+0)), + (getUInt64(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) } -FixedPointConversion_Release32_ToUInt64.test("FromInt32(0)_NeverTraps") { - let input = getInt32(0) - let actual = UInt64(input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToUInt64 +.test("FromInt32_AlwaysTraps") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-1), +]) { + expectCrashLater() + _blackHole(UInt64($0)) } -FixedPointConversion_Release32_ToUInt64.test("FromInt32(0)_NeverFails") { - let input = getInt32(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromInt32(2147483647)_NeverTraps") { - let input = getInt32(2147483647) - let actual = UInt64(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromInt32(2147483647)_NeverFails") { - let input = getInt32(2147483647) - let actual = UInt64(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Release32_ToUInt64 +.test("FromInt32_AlwaysFails") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-1), +]) { + expectNil(UInt64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt64: (0)...(18446744073709551615) +// MARK: UInt64: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt64.test("FromUInt64(0)_NeverTraps") { - let input = getUInt64(0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromUInt64(0)_NeverFails") { - let input = getUInt64(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToUInt64 +.test("FromUInt64_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getUInt64(+0)), + (getUInt64(+18446744073709551615), getUInt64(+18446744073709551615)), +]) { + expectEqual($0.0, UInt64($0.1)) } -FixedPointConversion_Release32_ToUInt64.test("FromUInt64(18446744073709551615)_NeverTraps") { - let input = getUInt64(18446744073709551615) - let actual = UInt64(input) - expectEqual(18446744073709551615, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromUInt64(18446744073709551615)_NeverFails") { - let input = getUInt64(18446744073709551615) - let actual = UInt64(exactly: input) - expectEqual(18446744073709551615, actual) +FixedPointConversion_Release32_ToUInt64 +.test("FromUInt64_NeverFails") +.forEach(in: [ + (getUInt64(+0), getUInt64(+0)), + (getUInt64(+18446744073709551615), getUInt64(+18446744073709551615)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int64: (-9223372036854775808)...(9223372036854775807) +// MARK: Int64: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt64.test("FromInt64(-9223372036854775808)_AlwaysTraps") { - let input = getInt64(-9223372036854775808) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromInt64(-9223372036854775808)_AlwaysFails") { - let input = getInt64(-9223372036854775808) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromInt64(-1)_AlwaysTraps") { - let input = getInt64(-1) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromInt64(-1)_AlwaysFails") { - let input = getInt64(-1) - let actual = UInt64(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt64 +.test("FromInt64_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getInt64(+0)), + (getUInt64(+9223372036854775807), getInt64(+9223372036854775807)), +]) { + expectEqual($0.0, UInt64($0.1)) } -FixedPointConversion_Release32_ToUInt64.test("FromInt64(0)_NeverTraps") { - let input = getInt64(0) - let actual = UInt64(input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToUInt64 +.test("FromInt64_NeverFails") +.forEach(in: [ + (getUInt64(+0), getInt64(+0)), + (getUInt64(+9223372036854775807), getInt64(+9223372036854775807)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) } -FixedPointConversion_Release32_ToUInt64.test("FromInt64(0)_NeverFails") { - let input = getInt64(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToUInt64 +.test("FromInt64_AlwaysTraps") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-1), +]) { + expectCrashLater() + _blackHole(UInt64($0)) } -FixedPointConversion_Release32_ToUInt64.test("FromInt64(9223372036854775807)_NeverTraps") { - let input = getInt64(9223372036854775807) - let actual = UInt64(input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromInt64(9223372036854775807)_NeverFails") { - let input = getInt64(9223372036854775807) - let actual = UInt64(exactly: input) - expectEqual(9223372036854775807, actual) +FixedPointConversion_Release32_ToUInt64 +.test("FromInt64_AlwaysFails") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-1), +]) { + expectNil(UInt64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt: (0)...(4294967295) +// MARK: UInt: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt64.test("FromUInt(0)_NeverTraps") { - let input = getUInt(0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromUInt(0)_NeverFails") { - let input = getUInt(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromUInt(4294967295)_NeverTraps") { - let input = getUInt(4294967295) - let actual = UInt64(input) - expectEqual(4294967295, actual) +FixedPointConversion_Release32_ToUInt64 +.test("FromUInt_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getUInt(+0)), + (getUInt64(+4294967295), getUInt(+4294967295)), +]) { + expectEqual($0.0, UInt64($0.1)) } -FixedPointConversion_Release32_ToUInt64.test("FromUInt(4294967295)_NeverFails") { - let input = getUInt(4294967295) - let actual = UInt64(exactly: input) - expectEqual(4294967295, actual) +FixedPointConversion_Release32_ToUInt64 +.test("FromUInt_NeverFails") +.forEach(in: [ + (getUInt64(+0), getUInt(+0)), + (getUInt64(+4294967295), getUInt(+4294967295)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int: (-2147483648)...(2147483647) +// MARK: Int: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt64.test("FromInt(-2147483648)_AlwaysTraps") { - let input = getInt(-2147483648) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromInt(-2147483648)_AlwaysFails") { - let input = getInt(-2147483648) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromInt(-1)_AlwaysTraps") { - let input = getInt(-1) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromInt(-1)_AlwaysFails") { - let input = getInt(-1) - let actual = UInt64(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt64 +.test("FromInt_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getInt(+0)), + (getUInt64(+2147483647), getInt(+2147483647)), +]) { + expectEqual($0.0, UInt64($0.1)) } -FixedPointConversion_Release32_ToUInt64.test("FromInt(0)_NeverTraps") { - let input = getInt(0) - let actual = UInt64(input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToUInt64 +.test("FromInt_NeverFails") +.forEach(in: [ + (getUInt64(+0), getInt(+0)), + (getUInt64(+2147483647), getInt(+2147483647)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) } -FixedPointConversion_Release32_ToUInt64.test("FromInt(0)_NeverFails") { - let input = getInt(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToUInt64 +.test("FromInt_AlwaysTraps") +.forEach(in: [ + getInt(-2147483648), + getInt(-1), +]) { + expectCrashLater() + _blackHole(UInt64($0)) } -FixedPointConversion_Release32_ToUInt64.test("FromInt(2147483647)_NeverTraps") { - let input = getInt(2147483647) - let actual = UInt64(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromInt(2147483647)_NeverFails") { - let input = getInt(2147483647) - let actual = UInt64(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Release32_ToUInt64 +.test("FromInt_AlwaysFails") +.forEach(in: [ + getInt(-2147483648), + getInt(-1), +]) { + expectNil(UInt64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float16: (-2047)...(2047) +// MARK: Float16: (-2047)...(+2047) //===----------------------------------------------------------------------===// #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -FixedPointConversion_Release32_ToUInt64.test("FromFloat16(-2047)_AlwaysTraps") { - let input = getFloat16(-2047) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat16(-2047)_AlwaysFails") { - let input = getFloat16(-2047) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat16(-128.5)_AlwaysTraps") { - let input = getFloat16(-128.5) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat16(-128.5)_AlwaysFails") { - let input = getFloat16(-128.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat16(-1)_AlwaysTraps") { - let input = getFloat16(-1) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat16(-1)_AlwaysFails") { - let input = getFloat16(-1) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat16(-0.5)_NeverTraps") { - let input = getFloat16(-0.5) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat16(-0.5)_AlwaysFails") { - let input = getFloat16(-0.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat16(0)_NeverTraps") { - let input = getFloat16(0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat16(0)_NeverFails") { - let input = getFloat16(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat16(-0.0)_NeverTraps") { - let input = getFloat16(-0.0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat16(-0.0)_NeverFails") { - let input = getFloat16(-0.0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat16(0.0)_NeverTraps") { - let input = getFloat16(0.0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat16(0.0)_NeverFails") { - let input = getFloat16(0.0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat16(0.5)_NeverTraps") { - let input = getFloat16(0.5) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat16(0.5)_AlwaysFails") { - let input = getFloat16(0.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat16(127.5)_NeverTraps") { - let input = getFloat16(127.5) - let actual = UInt64(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat16(127.5)_AlwaysFails") { - let input = getFloat16(127.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat16(255.5)_NeverTraps") { - let input = getFloat16(255.5) - let actual = UInt64(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat16(255.5)_AlwaysFails") { - let input = getFloat16(255.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat16(2047)_NeverTraps") { - let input = getFloat16(2047) - let actual = UInt64(input) - expectEqual(2047, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat16(2047)_NeverFails") { - let input = getFloat16(2047) - let actual = UInt64(exactly: input) - expectEqual(2047, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat16(-.infinity)_AlwaysTraps") { - let input = getFloat16(-.infinity) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat16(-.infinity)_AlwaysFails") { - let input = getFloat16(-.infinity) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat16(+.infinity)_AlwaysTraps") { - let input = getFloat16(+.infinity) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat16(+.infinity)_AlwaysFails") { - let input = getFloat16(+.infinity) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat16(-.nan)_AlwaysTraps") { - let input = getFloat16(-.nan) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat16(-.nan)_AlwaysFails") { - let input = getFloat16(-.nan) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat16(+.nan)_AlwaysTraps") { - let input = getFloat16(+.nan) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat16(+.nan)_AlwaysFails") { - let input = getFloat16(+.nan) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat16(-.signalingNaN)_AlwaysTraps") { - let input = getFloat16(-.signalingNaN) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat16(-.signalingNaN)_AlwaysFails") { - let input = getFloat16(-.signalingNaN) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat16(+.signalingNaN)_AlwaysTraps") { - let input = getFloat16(+.signalingNaN) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat16(+.signalingNaN)_AlwaysFails") { - let input = getFloat16(+.signalingNaN) - let actual = UInt64(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt64 +.test("FromFloat16_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getFloat16(-0.5)), + (getUInt64(+0), getFloat16(+0)), + (getUInt64(+0), getFloat16(-0)), + (getUInt64(+0), getFloat16(+0.5)), + (getUInt64(+127), getFloat16(+127.5)), + (getUInt64(+255), getFloat16(+255.5)), + (getUInt64(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, UInt64($0.1)) +} + +FixedPointConversion_Release32_ToUInt64 +.test("FromFloat16_NeverFails") +.forEach(in: [ + (getUInt64(+0), getFloat16(+0)), + (getUInt64(+0), getFloat16(-0)), + (getUInt64(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToUInt64 +.test("FromFloat16_AlwaysTraps") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-128.5), + getFloat16(-1), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt64($0)) +} + +FixedPointConversion_Release32_ToUInt64 +.test("FromFloat16_AlwaysFails") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-128.5), + getFloat16(-1), + getFloat16(-0.5), + getFloat16(+0.5), + getFloat16(+127.5), + getFloat16(+255.5), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectNil(UInt64(exactly: $0)) } } #endif // Float16 //===----------------------------------------------------------------------===// -// MARK: Float32: (-16777215)...(16777215) +// MARK: Float32: (-16777215)...(+16777215) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt64.test("FromFloat32(-16777215)_AlwaysTraps") { - let input = getFloat32(-16777215) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat32(-16777215)_AlwaysFails") { - let input = getFloat32(-16777215) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat32(-32768.5)_AlwaysTraps") { - let input = getFloat32(-32768.5) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat32(-32768.5)_AlwaysFails") { - let input = getFloat32(-32768.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat32(-128.5)_AlwaysTraps") { - let input = getFloat32(-128.5) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat32(-128.5)_AlwaysFails") { - let input = getFloat32(-128.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat32(-1)_AlwaysTraps") { - let input = getFloat32(-1) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat32(-1)_AlwaysFails") { - let input = getFloat32(-1) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat32(-0.5)_NeverTraps") { - let input = getFloat32(-0.5) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat32(-0.5)_AlwaysFails") { - let input = getFloat32(-0.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat32(0)_NeverTraps") { - let input = getFloat32(0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat32(0)_NeverFails") { - let input = getFloat32(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat32(-0.0)_NeverTraps") { - let input = getFloat32(-0.0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat32(-0.0)_NeverFails") { - let input = getFloat32(-0.0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat32(0.0)_NeverTraps") { - let input = getFloat32(0.0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat32(0.0)_NeverFails") { - let input = getFloat32(0.0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat32(0.5)_NeverTraps") { - let input = getFloat32(0.5) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat32(0.5)_AlwaysFails") { - let input = getFloat32(0.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat32(127.5)_NeverTraps") { - let input = getFloat32(127.5) - let actual = UInt64(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat32(127.5)_AlwaysFails") { - let input = getFloat32(127.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat32(255.5)_NeverTraps") { - let input = getFloat32(255.5) - let actual = UInt64(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat32(255.5)_AlwaysFails") { - let input = getFloat32(255.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat32(32767.5)_NeverTraps") { - let input = getFloat32(32767.5) - let actual = UInt64(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat32(32767.5)_AlwaysFails") { - let input = getFloat32(32767.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat32(65535.5)_NeverTraps") { - let input = getFloat32(65535.5) - let actual = UInt64(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat32(65535.5)_AlwaysFails") { - let input = getFloat32(65535.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat32(16777215)_NeverTraps") { - let input = getFloat32(16777215) - let actual = UInt64(input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat32(16777215)_NeverFails") { - let input = getFloat32(16777215) - let actual = UInt64(exactly: input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat32(-.infinity)_AlwaysTraps") { - let input = getFloat32(-.infinity) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat32(-.infinity)_AlwaysFails") { - let input = getFloat32(-.infinity) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat32(+.infinity)_AlwaysTraps") { - let input = getFloat32(+.infinity) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat32(+.infinity)_AlwaysFails") { - let input = getFloat32(+.infinity) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat32(-.nan)_AlwaysTraps") { - let input = getFloat32(-.nan) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat32(-.nan)_AlwaysFails") { - let input = getFloat32(-.nan) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat32(+.nan)_AlwaysTraps") { - let input = getFloat32(+.nan) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat32(+.nan)_AlwaysFails") { - let input = getFloat32(+.nan) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat32(-.signalingNaN)_AlwaysTraps") { - let input = getFloat32(-.signalingNaN) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat32(-.signalingNaN)_AlwaysFails") { - let input = getFloat32(-.signalingNaN) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat32(+.signalingNaN)_AlwaysTraps") { - let input = getFloat32(+.signalingNaN) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat32(+.signalingNaN)_AlwaysFails") { - let input = getFloat32(+.signalingNaN) - let actual = UInt64(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt64 +.test("FromFloat32_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getFloat32(-0.5)), + (getUInt64(+0), getFloat32(+0)), + (getUInt64(+0), getFloat32(-0)), + (getUInt64(+0), getFloat32(+0.5)), + (getUInt64(+127), getFloat32(+127.5)), + (getUInt64(+255), getFloat32(+255.5)), + (getUInt64(+32767), getFloat32(+32767.5)), + (getUInt64(+65535), getFloat32(+65535.5)), + (getUInt64(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, UInt64($0.1)) +} + +FixedPointConversion_Release32_ToUInt64 +.test("FromFloat32_NeverFails") +.forEach(in: [ + (getUInt64(+0), getFloat32(+0)), + (getUInt64(+0), getFloat32(-0)), + (getUInt64(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToUInt64 +.test("FromFloat32_AlwaysTraps") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-1), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt64($0)) +} + +FixedPointConversion_Release32_ToUInt64 +.test("FromFloat32_AlwaysFails") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-1), + getFloat32(-0.5), + getFloat32(+0.5), + getFloat32(+127.5), + getFloat32(+255.5), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectNil(UInt64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float64: (-9007199254740991)...(9007199254740991) +// MARK: Float64: (-9007199254740991)...(+9007199254740991) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt64.test("FromFloat64(-9007199254740991)_AlwaysTraps") { - let input = getFloat64(-9007199254740991) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat64(-9007199254740991)_AlwaysFails") { - let input = getFloat64(-9007199254740991) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat64(-32768.5)_AlwaysTraps") { - let input = getFloat64(-32768.5) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat64(-32768.5)_AlwaysFails") { - let input = getFloat64(-32768.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat64(-128.5)_AlwaysTraps") { - let input = getFloat64(-128.5) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat64(-128.5)_AlwaysFails") { - let input = getFloat64(-128.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat64(-1)_AlwaysTraps") { - let input = getFloat64(-1) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat64(-1)_AlwaysFails") { - let input = getFloat64(-1) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat64(-0.5)_NeverTraps") { - let input = getFloat64(-0.5) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat64(-0.5)_AlwaysFails") { - let input = getFloat64(-0.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat64(0)_NeverTraps") { - let input = getFloat64(0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat64(0)_NeverFails") { - let input = getFloat64(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat64(-0.0)_NeverTraps") { - let input = getFloat64(-0.0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat64(-0.0)_NeverFails") { - let input = getFloat64(-0.0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat64(0.0)_NeverTraps") { - let input = getFloat64(0.0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat64(0.0)_NeverFails") { - let input = getFloat64(0.0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat64(0.5)_NeverTraps") { - let input = getFloat64(0.5) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat64(0.5)_AlwaysFails") { - let input = getFloat64(0.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat64(127.5)_NeverTraps") { - let input = getFloat64(127.5) - let actual = UInt64(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat64(127.5)_AlwaysFails") { - let input = getFloat64(127.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat64(255.5)_NeverTraps") { - let input = getFloat64(255.5) - let actual = UInt64(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat64(255.5)_AlwaysFails") { - let input = getFloat64(255.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat64(32767.5)_NeverTraps") { - let input = getFloat64(32767.5) - let actual = UInt64(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat64(32767.5)_AlwaysFails") { - let input = getFloat64(32767.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat64(65535.5)_NeverTraps") { - let input = getFloat64(65535.5) - let actual = UInt64(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat64(65535.5)_AlwaysFails") { - let input = getFloat64(65535.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat64(9007199254740991)_NeverTraps") { - let input = getFloat64(9007199254740991) - let actual = UInt64(input) - expectEqual(9007199254740991, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat64(9007199254740991)_NeverFails") { - let input = getFloat64(9007199254740991) - let actual = UInt64(exactly: input) - expectEqual(9007199254740991, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat64(-.infinity)_AlwaysTraps") { - let input = getFloat64(-.infinity) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat64(-.infinity)_AlwaysFails") { - let input = getFloat64(-.infinity) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat64(+.infinity)_AlwaysTraps") { - let input = getFloat64(+.infinity) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat64(+.infinity)_AlwaysFails") { - let input = getFloat64(+.infinity) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat64(-.nan)_AlwaysTraps") { - let input = getFloat64(-.nan) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat64(-.nan)_AlwaysFails") { - let input = getFloat64(-.nan) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat64(+.nan)_AlwaysTraps") { - let input = getFloat64(+.nan) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat64(+.nan)_AlwaysFails") { - let input = getFloat64(+.nan) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat64(-.signalingNaN)_AlwaysTraps") { - let input = getFloat64(-.signalingNaN) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat64(-.signalingNaN)_AlwaysFails") { - let input = getFloat64(-.signalingNaN) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat64(+.signalingNaN)_AlwaysTraps") { - let input = getFloat64(+.signalingNaN) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat64(+.signalingNaN)_AlwaysFails") { - let input = getFloat64(+.signalingNaN) - let actual = UInt64(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt64 +.test("FromFloat64_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getFloat64(-0.5)), + (getUInt64(+0), getFloat64(+0)), + (getUInt64(+0), getFloat64(-0)), + (getUInt64(+0), getFloat64(+0.5)), + (getUInt64(+127), getFloat64(+127.5)), + (getUInt64(+255), getFloat64(+255.5)), + (getUInt64(+32767), getFloat64(+32767.5)), + (getUInt64(+65535), getFloat64(+65535.5)), + (getUInt64(+9007199254740991), getFloat64(+9007199254740991)), +]) { + expectEqual($0.0, UInt64($0.1)) +} + +FixedPointConversion_Release32_ToUInt64 +.test("FromFloat64_NeverFails") +.forEach(in: [ + (getUInt64(+0), getFloat64(+0)), + (getUInt64(+0), getFloat64(-0)), + (getUInt64(+9007199254740991), getFloat64(+9007199254740991)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToUInt64 +.test("FromFloat64_AlwaysTraps") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-1), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt64($0)) +} + +FixedPointConversion_Release32_ToUInt64 +.test("FromFloat64_AlwaysFails") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-1), + getFloat64(-0.5), + getFloat64(+0.5), + getFloat64(+127.5), + getFloat64(+255.5), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectNil(UInt64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float80: (-18446744073709551615)...(18446744073709551615) +// MARK: Float80: (-18446744073709551615)...(+18446744073709551615) //===----------------------------------------------------------------------===// #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(-18446744073709551615)_AlwaysTraps") { - let input = getFloat80(-18446744073709551615) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(-18446744073709551615)_AlwaysFails") { - let input = getFloat80(-18446744073709551615) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(-32768.5)_AlwaysTraps") { - let input = getFloat80(-32768.5) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(-32768.5)_AlwaysFails") { - let input = getFloat80(-32768.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(-128.5)_AlwaysTraps") { - let input = getFloat80(-128.5) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(-128.5)_AlwaysFails") { - let input = getFloat80(-128.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(-1)_AlwaysTraps") { - let input = getFloat80(-1) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(-1)_AlwaysFails") { - let input = getFloat80(-1) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(-0.5)_NeverTraps") { - let input = getFloat80(-0.5) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(-0.5)_AlwaysFails") { - let input = getFloat80(-0.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(0)_NeverTraps") { - let input = getFloat80(0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(0)_NeverFails") { - let input = getFloat80(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(-0.0)_NeverTraps") { - let input = getFloat80(-0.0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(-0.0)_NeverFails") { - let input = getFloat80(-0.0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(0.0)_NeverTraps") { - let input = getFloat80(0.0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(0.0)_NeverFails") { - let input = getFloat80(0.0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(0.5)_NeverTraps") { - let input = getFloat80(0.5) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(0.5)_AlwaysFails") { - let input = getFloat80(0.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(127.5)_NeverTraps") { - let input = getFloat80(127.5) - let actual = UInt64(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(127.5)_AlwaysFails") { - let input = getFloat80(127.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(255.5)_NeverTraps") { - let input = getFloat80(255.5) - let actual = UInt64(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(255.5)_AlwaysFails") { - let input = getFloat80(255.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(32767.5)_NeverTraps") { - let input = getFloat80(32767.5) - let actual = UInt64(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(32767.5)_AlwaysFails") { - let input = getFloat80(32767.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(65535.5)_NeverTraps") { - let input = getFloat80(65535.5) - let actual = UInt64(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(65535.5)_AlwaysFails") { - let input = getFloat80(65535.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(18446744073709551615)_NeverTraps") { - let input = getFloat80(18446744073709551615) - let actual = UInt64(input) - expectEqual(18446744073709551615, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(18446744073709551615)_NeverFails") { - let input = getFloat80(18446744073709551615) - let actual = UInt64(exactly: input) - expectEqual(18446744073709551615, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(18446744073709551615)_NeverTraps") { - let input = getFloat80(18446744073709551615) - let actual = UInt64(input) - expectEqual(18446744073709551615, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(18446744073709551615)_NeverFails") { - let input = getFloat80(18446744073709551615) - let actual = UInt64(exactly: input) - expectEqual(18446744073709551615, actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(-.infinity)_AlwaysTraps") { - let input = getFloat80(-.infinity) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(-.infinity)_AlwaysFails") { - let input = getFloat80(-.infinity) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(+.infinity)_AlwaysTraps") { - let input = getFloat80(+.infinity) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(+.infinity)_AlwaysFails") { - let input = getFloat80(+.infinity) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(-.nan)_AlwaysTraps") { - let input = getFloat80(-.nan) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(-.nan)_AlwaysFails") { - let input = getFloat80(-.nan) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(+.nan)_AlwaysTraps") { - let input = getFloat80(+.nan) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(+.nan)_AlwaysFails") { - let input = getFloat80(+.nan) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(-.signalingNaN)_AlwaysTraps") { - let input = getFloat80(-.signalingNaN) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(-.signalingNaN)_AlwaysFails") { - let input = getFloat80(-.signalingNaN) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(+.signalingNaN)_AlwaysTraps") { - let input = getFloat80(+.signalingNaN) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt64.test("FromFloat80(+.signalingNaN)_AlwaysFails") { - let input = getFloat80(+.signalingNaN) - let actual = UInt64(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt64 +.test("FromFloat80_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getFloat80(-0.5)), + (getUInt64(+0), getFloat80(+0)), + (getUInt64(+0), getFloat80(-0)), + (getUInt64(+0), getFloat80(+0.5)), + (getUInt64(+127), getFloat80(+127.5)), + (getUInt64(+255), getFloat80(+255.5)), + (getUInt64(+32767), getFloat80(+32767.5)), + (getUInt64(+65535), getFloat80(+65535.5)), + (getUInt64(+18446744073709551615), getFloat80(+18446744073709551615)), +]) { + expectEqual($0.0, UInt64($0.1)) +} + +FixedPointConversion_Release32_ToUInt64 +.test("FromFloat80_NeverFails") +.forEach(in: [ + (getUInt64(+0), getFloat80(+0)), + (getUInt64(+0), getFloat80(-0)), + (getUInt64(+18446744073709551615), getFloat80(+18446744073709551615)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToUInt64 +.test("FromFloat80_AlwaysTraps") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-1), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt64($0)) +} + +FixedPointConversion_Release32_ToUInt64 +.test("FromFloat80_AlwaysFails") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-1), + getFloat80(-0.5), + getFloat80(+0.5), + getFloat80(+127.5), + getFloat80(+255.5), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectNil(UInt64(exactly: $0)) } #endif // Float80 diff --git a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release32_ToUInt8.swift b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release32_ToUInt8.swift index 8c2b2e7c8979a..d504548ae972c 100644 --- a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release32_ToUInt8.swift +++ b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release32_ToUInt8.swift @@ -5,7 +5,7 @@ // //===----------------------------------------------------------------------===// // -// REQUIRES: executable_test, long_test +// REQUIRES: executable_test // REQUIRES: PTRSIZE=32 // RUN: %target-run-simple-swift(-O) // END. @@ -14,1800 +14,717 @@ import StdlibUnittest -let FixedPointConversion_Release32_ToUInt8 = TestSuite("FixedPointConversion_Release32_ToUInt8") +let FixedPointConversion_Release32_ToUInt8 = TestSuite( + "FixedPointConversion_Release32_ToUInt8" +) //===----------------------------------------------------------------------===// -// MARK: UInt8: (0)...(255) +// MARK: UInt8: (+0)...(+255) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt8.test("FromUInt8(0)_NeverTraps") { - let input = getUInt8(0) - let actual = UInt8(input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToUInt8 +.test("FromUInt8_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getUInt8(+0)), + (getUInt8(+255), getUInt8(+255)), +]) { + expectEqual($0.0, UInt8($0.1)) } -FixedPointConversion_Release32_ToUInt8.test("FromUInt8(0)_NeverFails") { - let input = getUInt8(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromUInt8(255)_NeverTraps") { - let input = getUInt8(255) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromUInt8(255)_NeverFails") { - let input = getUInt8(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) +FixedPointConversion_Release32_ToUInt8 +.test("FromUInt8_NeverFails") +.forEach(in: [ + (getUInt8(+0), getUInt8(+0)), + (getUInt8(+255), getUInt8(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int8: (-128)...(127) +// MARK: Int8: (-128)...(+127) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt8.test("FromInt8(-128)_AlwaysTraps") { - let input = getInt8(-128) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt8(-128)_AlwaysFails") { - let input = getInt8(-128) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt8(-1)_AlwaysTraps") { - let input = getInt8(-1) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } +FixedPointConversion_Release32_ToUInt8 +.test("FromInt8_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getInt8(+0)), + (getUInt8(+127), getInt8(+127)), +]) { + expectEqual($0.0, UInt8($0.1)) } -FixedPointConversion_Release32_ToUInt8.test("FromInt8(-1)_AlwaysFails") { - let input = getInt8(-1) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt8 +.test("FromInt8_NeverFails") +.forEach(in: [ + (getUInt8(+0), getInt8(+0)), + (getUInt8(+127), getInt8(+127)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) } -FixedPointConversion_Release32_ToUInt8.test("FromInt8(0)_NeverTraps") { - let input = getInt8(0) - let actual = UInt8(input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToUInt8 +.test("FromInt8_AlwaysTraps") +.forEach(in: [ + getInt8(-128), + getInt8(-1), +]) { + expectCrashLater() + _blackHole(UInt8($0)) } -FixedPointConversion_Release32_ToUInt8.test("FromInt8(0)_NeverFails") { - let input = getInt8(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt8(127)_NeverTraps") { - let input = getInt8(127) - let actual = UInt8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt8(127)_NeverFails") { - let input = getInt8(127) - let actual = UInt8(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Release32_ToUInt8 +.test("FromInt8_AlwaysFails") +.forEach(in: [ + getInt8(-128), + getInt8(-1), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt16: (0)...(65535) +// MARK: UInt16: (+0)...(+65535) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt8.test("FromUInt16(0)_NeverTraps") { - let input = getUInt16(0) - let actual = UInt8(input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToUInt8 +.test("FromUInt16_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getUInt16(+0)), + (getUInt8(+255), getUInt16(+255)), +]) { + expectEqual($0.0, UInt8($0.1)) } -FixedPointConversion_Release32_ToUInt8.test("FromUInt16(0)_NeverFails") { - let input = getUInt16(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToUInt8 +.test("FromUInt16_NeverFails") +.forEach(in: [ + (getUInt8(+0), getUInt16(+0)), + (getUInt8(+255), getUInt16(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) } -FixedPointConversion_Release32_ToUInt8.test("FromUInt16(255)_NeverTraps") { - let input = getUInt16(255) - let actual = UInt8(input) - expectEqual(255, actual) +FixedPointConversion_Release32_ToUInt8 +.test("FromUInt16_AlwaysTraps") +.forEach(in: [ + getUInt16(+256), + getUInt16(+65535), +]) { + expectCrashLater() + _blackHole(UInt8($0)) } -FixedPointConversion_Release32_ToUInt8.test("FromUInt16(255)_NeverFails") { - let input = getUInt16(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromUInt16(256)_AlwaysTraps") { - let input = getUInt16(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromUInt16(256)_AlwaysFails") { - let input = getUInt16(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromUInt16(65535)_AlwaysTraps") { - let input = getUInt16(65535) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromUInt16(65535)_AlwaysFails") { - let input = getUInt16(65535) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt8 +.test("FromUInt16_AlwaysFails") +.forEach(in: [ + getUInt16(+256), + getUInt16(+65535), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int16: (-32768)...(32767) +// MARK: Int16: (-32768)...(+32767) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt8.test("FromInt16(-32768)_AlwaysTraps") { - let input = getInt16(-32768) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt16(-32768)_AlwaysFails") { - let input = getInt16(-32768) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt16(-1)_AlwaysTraps") { - let input = getInt16(-1) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt16(-1)_AlwaysFails") { - let input = getInt16(-1) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt16(0)_NeverTraps") { - let input = getInt16(0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt16(0)_NeverFails") { - let input = getInt16(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt16(255)_NeverTraps") { - let input = getInt16(255) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt16(255)_NeverFails") { - let input = getInt16(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt16(256)_AlwaysTraps") { - let input = getInt16(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt16(256)_AlwaysFails") { - let input = getInt16(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt16(32767)_AlwaysTraps") { - let input = getInt16(32767) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt16(32767)_AlwaysFails") { - let input = getInt16(32767) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt8 +.test("FromInt16_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getInt16(+0)), + (getUInt8(+255), getInt16(+255)), +]) { + expectEqual($0.0, UInt8($0.1)) +} + +FixedPointConversion_Release32_ToUInt8 +.test("FromInt16_NeverFails") +.forEach(in: [ + (getUInt8(+0), getInt16(+0)), + (getUInt8(+255), getInt16(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToUInt8 +.test("FromInt16_AlwaysTraps") +.forEach(in: [ + getInt16(-32768), + getInt16(-1), + getInt16(+256), + getInt16(+32767), +]) { + expectCrashLater() + _blackHole(UInt8($0)) +} + +FixedPointConversion_Release32_ToUInt8 +.test("FromInt16_AlwaysFails") +.forEach(in: [ + getInt16(-32768), + getInt16(-1), + getInt16(+256), + getInt16(+32767), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt32: (0)...(4294967295) +// MARK: UInt32: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt8.test("FromUInt32(0)_NeverTraps") { - let input = getUInt32(0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromUInt32(0)_NeverFails") { - let input = getUInt32(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToUInt8 +.test("FromUInt32_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getUInt32(+0)), + (getUInt8(+255), getUInt32(+255)), +]) { + expectEqual($0.0, UInt8($0.1)) } -FixedPointConversion_Release32_ToUInt8.test("FromUInt32(255)_NeverTraps") { - let input = getUInt32(255) - let actual = UInt8(input) - expectEqual(255, actual) +FixedPointConversion_Release32_ToUInt8 +.test("FromUInt32_NeverFails") +.forEach(in: [ + (getUInt8(+0), getUInt32(+0)), + (getUInt8(+255), getUInt32(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) } -FixedPointConversion_Release32_ToUInt8.test("FromUInt32(255)_NeverFails") { - let input = getUInt32(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) +FixedPointConversion_Release32_ToUInt8 +.test("FromUInt32_AlwaysTraps") +.forEach(in: [ + getUInt32(+256), + getUInt32(+4294967295), +]) { + expectCrashLater() + _blackHole(UInt8($0)) } -FixedPointConversion_Release32_ToUInt8.test("FromUInt32(256)_AlwaysTraps") { - let input = getUInt32(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromUInt32(256)_AlwaysFails") { - let input = getUInt32(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromUInt32(4294967295)_AlwaysTraps") { - let input = getUInt32(4294967295) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromUInt32(4294967295)_AlwaysFails") { - let input = getUInt32(4294967295) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt8 +.test("FromUInt32_AlwaysFails") +.forEach(in: [ + getUInt32(+256), + getUInt32(+4294967295), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int32: (-2147483648)...(2147483647) +// MARK: Int32: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt8.test("FromInt32(-2147483648)_AlwaysTraps") { - let input = getInt32(-2147483648) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt32(-2147483648)_AlwaysFails") { - let input = getInt32(-2147483648) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt32(-1)_AlwaysTraps") { - let input = getInt32(-1) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt32(-1)_AlwaysFails") { - let input = getInt32(-1) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt32(0)_NeverTraps") { - let input = getInt32(0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt32(0)_NeverFails") { - let input = getInt32(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt32(255)_NeverTraps") { - let input = getInt32(255) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt32(255)_NeverFails") { - let input = getInt32(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt32(256)_AlwaysTraps") { - let input = getInt32(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt32(256)_AlwaysFails") { - let input = getInt32(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt32(2147483647)_AlwaysTraps") { - let input = getInt32(2147483647) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt32(2147483647)_AlwaysFails") { - let input = getInt32(2147483647) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt8 +.test("FromInt32_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getInt32(+0)), + (getUInt8(+255), getInt32(+255)), +]) { + expectEqual($0.0, UInt8($0.1)) +} + +FixedPointConversion_Release32_ToUInt8 +.test("FromInt32_NeverFails") +.forEach(in: [ + (getUInt8(+0), getInt32(+0)), + (getUInt8(+255), getInt32(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToUInt8 +.test("FromInt32_AlwaysTraps") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-1), + getInt32(+256), + getInt32(+2147483647), +]) { + expectCrashLater() + _blackHole(UInt8($0)) +} + +FixedPointConversion_Release32_ToUInt8 +.test("FromInt32_AlwaysFails") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-1), + getInt32(+256), + getInt32(+2147483647), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt64: (0)...(18446744073709551615) +// MARK: UInt64: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt8.test("FromUInt64(0)_NeverTraps") { - let input = getUInt64(0) - let actual = UInt8(input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToUInt8 +.test("FromUInt64_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getUInt64(+0)), + (getUInt8(+255), getUInt64(+255)), +]) { + expectEqual($0.0, UInt8($0.1)) } -FixedPointConversion_Release32_ToUInt8.test("FromUInt64(0)_NeverFails") { - let input = getUInt64(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToUInt8 +.test("FromUInt64_NeverFails") +.forEach(in: [ + (getUInt8(+0), getUInt64(+0)), + (getUInt8(+255), getUInt64(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) } -FixedPointConversion_Release32_ToUInt8.test("FromUInt64(255)_NeverTraps") { - let input = getUInt64(255) - let actual = UInt8(input) - expectEqual(255, actual) +FixedPointConversion_Release32_ToUInt8 +.test("FromUInt64_AlwaysTraps") +.forEach(in: [ + getUInt64(+256), + getUInt64(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(UInt8($0)) } -FixedPointConversion_Release32_ToUInt8.test("FromUInt64(255)_NeverFails") { - let input = getUInt64(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromUInt64(256)_AlwaysTraps") { - let input = getUInt64(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromUInt64(256)_AlwaysFails") { - let input = getUInt64(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromUInt64(18446744073709551615)_AlwaysTraps") { - let input = getUInt64(18446744073709551615) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromUInt64(18446744073709551615)_AlwaysFails") { - let input = getUInt64(18446744073709551615) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt8 +.test("FromUInt64_AlwaysFails") +.forEach(in: [ + getUInt64(+256), + getUInt64(+18446744073709551615), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int64: (-9223372036854775808)...(9223372036854775807) +// MARK: Int64: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt8.test("FromInt64(-9223372036854775808)_AlwaysTraps") { - let input = getInt64(-9223372036854775808) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt64(-9223372036854775808)_AlwaysFails") { - let input = getInt64(-9223372036854775808) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt64(-1)_AlwaysTraps") { - let input = getInt64(-1) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt64(-1)_AlwaysFails") { - let input = getInt64(-1) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt64(0)_NeverTraps") { - let input = getInt64(0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt64(0)_NeverFails") { - let input = getInt64(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt64(255)_NeverTraps") { - let input = getInt64(255) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt64(255)_NeverFails") { - let input = getInt64(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt64(256)_AlwaysTraps") { - let input = getInt64(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt64(256)_AlwaysFails") { - let input = getInt64(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt64(9223372036854775807)_AlwaysTraps") { - let input = getInt64(9223372036854775807) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt64(9223372036854775807)_AlwaysFails") { - let input = getInt64(9223372036854775807) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt8 +.test("FromInt64_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getInt64(+0)), + (getUInt8(+255), getInt64(+255)), +]) { + expectEqual($0.0, UInt8($0.1)) +} + +FixedPointConversion_Release32_ToUInt8 +.test("FromInt64_NeverFails") +.forEach(in: [ + (getUInt8(+0), getInt64(+0)), + (getUInt8(+255), getInt64(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToUInt8 +.test("FromInt64_AlwaysTraps") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-1), + getInt64(+256), + getInt64(+9223372036854775807), +]) { + expectCrashLater() + _blackHole(UInt8($0)) +} + +FixedPointConversion_Release32_ToUInt8 +.test("FromInt64_AlwaysFails") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-1), + getInt64(+256), + getInt64(+9223372036854775807), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt: (0)...(4294967295) +// MARK: UInt: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt8.test("FromUInt(0)_NeverTraps") { - let input = getUInt(0) - let actual = UInt8(input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToUInt8 +.test("FromUInt_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getUInt(+0)), + (getUInt8(+255), getUInt(+255)), +]) { + expectEqual($0.0, UInt8($0.1)) } -FixedPointConversion_Release32_ToUInt8.test("FromUInt(0)_NeverFails") { - let input = getUInt(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release32_ToUInt8 +.test("FromUInt_NeverFails") +.forEach(in: [ + (getUInt8(+0), getUInt(+0)), + (getUInt8(+255), getUInt(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) } -FixedPointConversion_Release32_ToUInt8.test("FromUInt(255)_NeverTraps") { - let input = getUInt(255) - let actual = UInt8(input) - expectEqual(255, actual) +FixedPointConversion_Release32_ToUInt8 +.test("FromUInt_AlwaysTraps") +.forEach(in: [ + getUInt(+256), + getUInt(+4294967295), +]) { + expectCrashLater() + _blackHole(UInt8($0)) } -FixedPointConversion_Release32_ToUInt8.test("FromUInt(255)_NeverFails") { - let input = getUInt(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromUInt(256)_AlwaysTraps") { - let input = getUInt(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromUInt(256)_AlwaysFails") { - let input = getUInt(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromUInt(4294967295)_AlwaysTraps") { - let input = getUInt(4294967295) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromUInt(4294967295)_AlwaysFails") { - let input = getUInt(4294967295) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt8 +.test("FromUInt_AlwaysFails") +.forEach(in: [ + getUInt(+256), + getUInt(+4294967295), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int: (-2147483648)...(2147483647) +// MARK: Int: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt8.test("FromInt(-2147483648)_AlwaysTraps") { - let input = getInt(-2147483648) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt(-2147483648)_AlwaysFails") { - let input = getInt(-2147483648) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt(-1)_AlwaysTraps") { - let input = getInt(-1) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt(-1)_AlwaysFails") { - let input = getInt(-1) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt(0)_NeverTraps") { - let input = getInt(0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt(0)_NeverFails") { - let input = getInt(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt(255)_NeverTraps") { - let input = getInt(255) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt(255)_NeverFails") { - let input = getInt(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt(256)_AlwaysTraps") { - let input = getInt(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt(256)_AlwaysFails") { - let input = getInt(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt(2147483647)_AlwaysTraps") { - let input = getInt(2147483647) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromInt(2147483647)_AlwaysFails") { - let input = getInt(2147483647) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt8 +.test("FromInt_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getInt(+0)), + (getUInt8(+255), getInt(+255)), +]) { + expectEqual($0.0, UInt8($0.1)) +} + +FixedPointConversion_Release32_ToUInt8 +.test("FromInt_NeverFails") +.forEach(in: [ + (getUInt8(+0), getInt(+0)), + (getUInt8(+255), getInt(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToUInt8 +.test("FromInt_AlwaysTraps") +.forEach(in: [ + getInt(-2147483648), + getInt(-1), + getInt(+256), + getInt(+2147483647), +]) { + expectCrashLater() + _blackHole(UInt8($0)) +} + +FixedPointConversion_Release32_ToUInt8 +.test("FromInt_AlwaysFails") +.forEach(in: [ + getInt(-2147483648), + getInt(-1), + getInt(+256), + getInt(+2147483647), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float16: (-2047)...(2047) +// MARK: Float16: (-2047)...(+2047) //===----------------------------------------------------------------------===// #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -FixedPointConversion_Release32_ToUInt8.test("FromFloat16(-2047)_AlwaysTraps") { - let input = getFloat16(-2047) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat16(-2047)_AlwaysFails") { - let input = getFloat16(-2047) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat16(-128.5)_AlwaysTraps") { - let input = getFloat16(-128.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat16(-128.5)_AlwaysFails") { - let input = getFloat16(-128.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat16(-1)_AlwaysTraps") { - let input = getFloat16(-1) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat16(-1)_AlwaysFails") { - let input = getFloat16(-1) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat16(-0.5)_NeverTraps") { - let input = getFloat16(-0.5) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat16(-0.5)_AlwaysFails") { - let input = getFloat16(-0.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat16(0)_NeverTraps") { - let input = getFloat16(0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat16(0)_NeverFails") { - let input = getFloat16(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat16(-0.0)_NeverTraps") { - let input = getFloat16(-0.0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat16(-0.0)_NeverFails") { - let input = getFloat16(-0.0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat16(0.0)_NeverTraps") { - let input = getFloat16(0.0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat16(0.0)_NeverFails") { - let input = getFloat16(0.0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat16(0.5)_NeverTraps") { - let input = getFloat16(0.5) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat16(0.5)_AlwaysFails") { - let input = getFloat16(0.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat16(127.5)_NeverTraps") { - let input = getFloat16(127.5) - let actual = UInt8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat16(127.5)_AlwaysFails") { - let input = getFloat16(127.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat16(255)_NeverTraps") { - let input = getFloat16(255) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat16(255)_NeverFails") { - let input = getFloat16(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat16(255.5)_NeverTraps") { - let input = getFloat16(255.5) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat16(255.5)_AlwaysFails") { - let input = getFloat16(255.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat16(256)_AlwaysTraps") { - let input = getFloat16(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat16(256)_AlwaysFails") { - let input = getFloat16(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat16(2047)_AlwaysTraps") { - let input = getFloat16(2047) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat16(2047)_AlwaysFails") { - let input = getFloat16(2047) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat16(-.infinity)_AlwaysTraps") { - let input = getFloat16(-.infinity) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat16(-.infinity)_AlwaysFails") { - let input = getFloat16(-.infinity) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat16(+.infinity)_AlwaysTraps") { - let input = getFloat16(+.infinity) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat16(+.infinity)_AlwaysFails") { - let input = getFloat16(+.infinity) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat16(-.nan)_AlwaysTraps") { - let input = getFloat16(-.nan) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat16(-.nan)_AlwaysFails") { - let input = getFloat16(-.nan) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat16(+.nan)_AlwaysTraps") { - let input = getFloat16(+.nan) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat16(+.nan)_AlwaysFails") { - let input = getFloat16(+.nan) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat16(-.signalingNaN)_AlwaysTraps") { - let input = getFloat16(-.signalingNaN) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat16(-.signalingNaN)_AlwaysFails") { - let input = getFloat16(-.signalingNaN) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat16(+.signalingNaN)_AlwaysTraps") { - let input = getFloat16(+.signalingNaN) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat16(+.signalingNaN)_AlwaysFails") { - let input = getFloat16(+.signalingNaN) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt8 +.test("FromFloat16_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getFloat16(-0.5)), + (getUInt8(+0), getFloat16(-0)), + (getUInt8(+0), getFloat16(+0)), + (getUInt8(+0), getFloat16(+0.5)), + (getUInt8(+127), getFloat16(+127.5)), + (getUInt8(+255), getFloat16(+255)), + (getUInt8(+255), getFloat16(+255.5)), +]) { + expectEqual($0.0, UInt8($0.1)) +} + +FixedPointConversion_Release32_ToUInt8 +.test("FromFloat16_NeverFails") +.forEach(in: [ + (getUInt8(+0), getFloat16(-0)), + (getUInt8(+0), getFloat16(+0)), + (getUInt8(+255), getFloat16(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToUInt8 +.test("FromFloat16_AlwaysTraps") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-128.5), + getFloat16(-1), + getFloat16(+256), + getFloat16(+2047), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt8($0)) +} + +FixedPointConversion_Release32_ToUInt8 +.test("FromFloat16_AlwaysFails") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-128.5), + getFloat16(-1), + getFloat16(-0.5), + getFloat16(+0.5), + getFloat16(+127.5), + getFloat16(+255.5), + getFloat16(+256), + getFloat16(+2047), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectNil(UInt8(exactly: $0)) } } #endif // Float16 //===----------------------------------------------------------------------===// -// MARK: Float32: (-16777215)...(16777215) +// MARK: Float32: (-16777215)...(+16777215) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(-16777215)_AlwaysTraps") { - let input = getFloat32(-16777215) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(-16777215)_AlwaysFails") { - let input = getFloat32(-16777215) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(-32768.5)_AlwaysTraps") { - let input = getFloat32(-32768.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(-32768.5)_AlwaysFails") { - let input = getFloat32(-32768.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(-128.5)_AlwaysTraps") { - let input = getFloat32(-128.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(-128.5)_AlwaysFails") { - let input = getFloat32(-128.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(-1)_AlwaysTraps") { - let input = getFloat32(-1) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(-1)_AlwaysFails") { - let input = getFloat32(-1) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(-0.5)_NeverTraps") { - let input = getFloat32(-0.5) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(-0.5)_AlwaysFails") { - let input = getFloat32(-0.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(0)_NeverTraps") { - let input = getFloat32(0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(0)_NeverFails") { - let input = getFloat32(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(-0.0)_NeverTraps") { - let input = getFloat32(-0.0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(-0.0)_NeverFails") { - let input = getFloat32(-0.0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(0.0)_NeverTraps") { - let input = getFloat32(0.0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(0.0)_NeverFails") { - let input = getFloat32(0.0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(0.5)_NeverTraps") { - let input = getFloat32(0.5) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(0.5)_AlwaysFails") { - let input = getFloat32(0.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(127.5)_NeverTraps") { - let input = getFloat32(127.5) - let actual = UInt8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(127.5)_AlwaysFails") { - let input = getFloat32(127.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(255)_NeverTraps") { - let input = getFloat32(255) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(255)_NeverFails") { - let input = getFloat32(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(255.5)_NeverTraps") { - let input = getFloat32(255.5) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(255.5)_AlwaysFails") { - let input = getFloat32(255.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(256)_AlwaysTraps") { - let input = getFloat32(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(256)_AlwaysFails") { - let input = getFloat32(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(32767.5)_AlwaysTraps") { - let input = getFloat32(32767.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(32767.5)_AlwaysFails") { - let input = getFloat32(32767.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(65535.5)_AlwaysTraps") { - let input = getFloat32(65535.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(65535.5)_AlwaysFails") { - let input = getFloat32(65535.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(16777215)_AlwaysTraps") { - let input = getFloat32(16777215) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(16777215)_AlwaysFails") { - let input = getFloat32(16777215) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(-.infinity)_AlwaysTraps") { - let input = getFloat32(-.infinity) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(-.infinity)_AlwaysFails") { - let input = getFloat32(-.infinity) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(+.infinity)_AlwaysTraps") { - let input = getFloat32(+.infinity) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(+.infinity)_AlwaysFails") { - let input = getFloat32(+.infinity) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(-.nan)_AlwaysTraps") { - let input = getFloat32(-.nan) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(-.nan)_AlwaysFails") { - let input = getFloat32(-.nan) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(+.nan)_AlwaysTraps") { - let input = getFloat32(+.nan) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(+.nan)_AlwaysFails") { - let input = getFloat32(+.nan) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(-.signalingNaN)_AlwaysTraps") { - let input = getFloat32(-.signalingNaN) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(-.signalingNaN)_AlwaysFails") { - let input = getFloat32(-.signalingNaN) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(+.signalingNaN)_AlwaysTraps") { - let input = getFloat32(+.signalingNaN) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat32(+.signalingNaN)_AlwaysFails") { - let input = getFloat32(+.signalingNaN) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt8 +.test("FromFloat32_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getFloat32(-0.5)), + (getUInt8(+0), getFloat32(+0)), + (getUInt8(+0), getFloat32(-0)), + (getUInt8(+0), getFloat32(+0.5)), + (getUInt8(+127), getFloat32(+127.5)), + (getUInt8(+255), getFloat32(+255)), + (getUInt8(+255), getFloat32(+255.5)), +]) { + expectEqual($0.0, UInt8($0.1)) +} + +FixedPointConversion_Release32_ToUInt8 +.test("FromFloat32_NeverFails") +.forEach(in: [ + (getUInt8(+0), getFloat32(+0)), + (getUInt8(+0), getFloat32(-0)), + (getUInt8(+255), getFloat32(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToUInt8 +.test("FromFloat32_AlwaysTraps") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-1), + getFloat32(+256), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(+16777215), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt8($0)) +} + +FixedPointConversion_Release32_ToUInt8 +.test("FromFloat32_AlwaysFails") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-1), + getFloat32(-0.5), + getFloat32(+0.5), + getFloat32(+127.5), + getFloat32(+255.5), + getFloat32(+256), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(+16777215), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float64: (-9007199254740991)...(9007199254740991) +// MARK: Float64: (-9007199254740991)...(+9007199254740991) //===----------------------------------------------------------------------===// -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(-9007199254740991)_AlwaysTraps") { - let input = getFloat64(-9007199254740991) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(-9007199254740991)_AlwaysFails") { - let input = getFloat64(-9007199254740991) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(-32768.5)_AlwaysTraps") { - let input = getFloat64(-32768.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(-32768.5)_AlwaysFails") { - let input = getFloat64(-32768.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(-128.5)_AlwaysTraps") { - let input = getFloat64(-128.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(-128.5)_AlwaysFails") { - let input = getFloat64(-128.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(-1)_AlwaysTraps") { - let input = getFloat64(-1) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(-1)_AlwaysFails") { - let input = getFloat64(-1) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(-0.5)_NeverTraps") { - let input = getFloat64(-0.5) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(-0.5)_AlwaysFails") { - let input = getFloat64(-0.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(0)_NeverTraps") { - let input = getFloat64(0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(0)_NeverFails") { - let input = getFloat64(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(-0.0)_NeverTraps") { - let input = getFloat64(-0.0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(-0.0)_NeverFails") { - let input = getFloat64(-0.0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(0.0)_NeverTraps") { - let input = getFloat64(0.0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(0.0)_NeverFails") { - let input = getFloat64(0.0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(0.5)_NeverTraps") { - let input = getFloat64(0.5) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(0.5)_AlwaysFails") { - let input = getFloat64(0.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(127.5)_NeverTraps") { - let input = getFloat64(127.5) - let actual = UInt8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(127.5)_AlwaysFails") { - let input = getFloat64(127.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(255)_NeverTraps") { - let input = getFloat64(255) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(255)_NeverFails") { - let input = getFloat64(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(255.5)_NeverTraps") { - let input = getFloat64(255.5) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(255.5)_AlwaysFails") { - let input = getFloat64(255.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(256)_AlwaysTraps") { - let input = getFloat64(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(256)_AlwaysFails") { - let input = getFloat64(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(32767.5)_AlwaysTraps") { - let input = getFloat64(32767.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(32767.5)_AlwaysFails") { - let input = getFloat64(32767.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(65535.5)_AlwaysTraps") { - let input = getFloat64(65535.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(65535.5)_AlwaysFails") { - let input = getFloat64(65535.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(9007199254740991)_AlwaysTraps") { - let input = getFloat64(9007199254740991) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(9007199254740991)_AlwaysFails") { - let input = getFloat64(9007199254740991) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(-.infinity)_AlwaysTraps") { - let input = getFloat64(-.infinity) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(-.infinity)_AlwaysFails") { - let input = getFloat64(-.infinity) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(+.infinity)_AlwaysTraps") { - let input = getFloat64(+.infinity) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(+.infinity)_AlwaysFails") { - let input = getFloat64(+.infinity) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(-.nan)_AlwaysTraps") { - let input = getFloat64(-.nan) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(-.nan)_AlwaysFails") { - let input = getFloat64(-.nan) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(+.nan)_AlwaysTraps") { - let input = getFloat64(+.nan) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(+.nan)_AlwaysFails") { - let input = getFloat64(+.nan) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(-.signalingNaN)_AlwaysTraps") { - let input = getFloat64(-.signalingNaN) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(-.signalingNaN)_AlwaysFails") { - let input = getFloat64(-.signalingNaN) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(+.signalingNaN)_AlwaysTraps") { - let input = getFloat64(+.signalingNaN) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat64(+.signalingNaN)_AlwaysFails") { - let input = getFloat64(+.signalingNaN) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt8 +.test("FromFloat64_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getFloat64(-0.5)), + (getUInt8(+0), getFloat64(+0)), + (getUInt8(+0), getFloat64(-0)), + (getUInt8(+0), getFloat64(+0.5)), + (getUInt8(+127), getFloat64(+127.5)), + (getUInt8(+255), getFloat64(+255)), + (getUInt8(+255), getFloat64(+255.5)), +]) { + expectEqual($0.0, UInt8($0.1)) +} + +FixedPointConversion_Release32_ToUInt8 +.test("FromFloat64_NeverFails") +.forEach(in: [ + (getUInt8(+0), getFloat64(+0)), + (getUInt8(+0), getFloat64(-0)), + (getUInt8(+255), getFloat64(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToUInt8 +.test("FromFloat64_AlwaysTraps") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-1), + getFloat64(+256), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt8($0)) +} + +FixedPointConversion_Release32_ToUInt8 +.test("FromFloat64_AlwaysFails") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-1), + getFloat64(-0.5), + getFloat64(+0.5), + getFloat64(+127.5), + getFloat64(+255.5), + getFloat64(+256), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float80: (-18446744073709551615)...(18446744073709551615) +// MARK: Float80: (-18446744073709551615)...(+18446744073709551615) //===----------------------------------------------------------------------===// #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(-18446744073709551615)_AlwaysTraps") { - let input = getFloat80(-18446744073709551615) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(-18446744073709551615)_AlwaysFails") { - let input = getFloat80(-18446744073709551615) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(-32768.5)_AlwaysTraps") { - let input = getFloat80(-32768.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(-32768.5)_AlwaysFails") { - let input = getFloat80(-32768.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(-128.5)_AlwaysTraps") { - let input = getFloat80(-128.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(-128.5)_AlwaysFails") { - let input = getFloat80(-128.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(-1)_AlwaysTraps") { - let input = getFloat80(-1) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(-1)_AlwaysFails") { - let input = getFloat80(-1) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(-0.5)_NeverTraps") { - let input = getFloat80(-0.5) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(-0.5)_AlwaysFails") { - let input = getFloat80(-0.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(0)_NeverTraps") { - let input = getFloat80(0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(0)_NeverFails") { - let input = getFloat80(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(-0.0)_NeverTraps") { - let input = getFloat80(-0.0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(-0.0)_NeverFails") { - let input = getFloat80(-0.0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(0.0)_NeverTraps") { - let input = getFloat80(0.0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(0.0)_NeverFails") { - let input = getFloat80(0.0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(0.5)_NeverTraps") { - let input = getFloat80(0.5) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(0.5)_AlwaysFails") { - let input = getFloat80(0.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(127.5)_NeverTraps") { - let input = getFloat80(127.5) - let actual = UInt8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(127.5)_AlwaysFails") { - let input = getFloat80(127.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(255)_NeverTraps") { - let input = getFloat80(255) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(255)_NeverFails") { - let input = getFloat80(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(255.5)_NeverTraps") { - let input = getFloat80(255.5) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(255.5)_AlwaysFails") { - let input = getFloat80(255.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(256)_AlwaysTraps") { - let input = getFloat80(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(256)_AlwaysFails") { - let input = getFloat80(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(32767.5)_AlwaysTraps") { - let input = getFloat80(32767.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(32767.5)_AlwaysFails") { - let input = getFloat80(32767.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(65535.5)_AlwaysTraps") { - let input = getFloat80(65535.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(65535.5)_AlwaysFails") { - let input = getFloat80(65535.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(18446744073709551615)_AlwaysTraps") { - let input = getFloat80(18446744073709551615) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(18446744073709551615)_AlwaysFails") { - let input = getFloat80(18446744073709551615) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(-.infinity)_AlwaysTraps") { - let input = getFloat80(-.infinity) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(-.infinity)_AlwaysFails") { - let input = getFloat80(-.infinity) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(+.infinity)_AlwaysTraps") { - let input = getFloat80(+.infinity) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(+.infinity)_AlwaysFails") { - let input = getFloat80(+.infinity) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(-.nan)_AlwaysTraps") { - let input = getFloat80(-.nan) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(-.nan)_AlwaysFails") { - let input = getFloat80(-.nan) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(+.nan)_AlwaysTraps") { - let input = getFloat80(+.nan) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(+.nan)_AlwaysFails") { - let input = getFloat80(+.nan) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(-.signalingNaN)_AlwaysTraps") { - let input = getFloat80(-.signalingNaN) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(-.signalingNaN)_AlwaysFails") { - let input = getFloat80(-.signalingNaN) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(+.signalingNaN)_AlwaysTraps") { - let input = getFloat80(+.signalingNaN) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release32_ToUInt8.test("FromFloat80(+.signalingNaN)_AlwaysFails") { - let input = getFloat80(+.signalingNaN) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Release32_ToUInt8 +.test("FromFloat80_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getFloat80(-0.5)), + (getUInt8(+0), getFloat80(-0)), + (getUInt8(+0), getFloat80(+0)), + (getUInt8(+0), getFloat80(+0.5)), + (getUInt8(+127), getFloat80(+127.5)), + (getUInt8(+255), getFloat80(+255)), + (getUInt8(+255), getFloat80(+255.5)), +]) { + expectEqual($0.0, UInt8($0.1)) +} + +FixedPointConversion_Release32_ToUInt8 +.test("FromFloat80_NeverFails") +.forEach(in: [ + (getUInt8(+0), getFloat80(-0)), + (getUInt8(+0), getFloat80(+0)), + (getUInt8(+255), getFloat80(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) +} + +FixedPointConversion_Release32_ToUInt8 +.test("FromFloat80_AlwaysTraps") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-1), + getFloat80(+256), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt8($0)) +} + +FixedPointConversion_Release32_ToUInt8 +.test("FromFloat80_AlwaysFails") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-1), + getFloat80(-0.5), + getFloat80(+0.5), + getFloat80(+127.5), + getFloat80(+255.5), + getFloat80(+256), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectNil(UInt8(exactly: $0)) } #endif // Float80 diff --git a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release64_ToInt.swift b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release64_ToInt.swift index 77c68baee2546..948d9b0506fb9 100644 --- a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release64_ToInt.swift +++ b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release64_ToInt.swift @@ -14,1358 +14,562 @@ import StdlibUnittest -let FixedPointConversion_Release64_ToInt = TestSuite("FixedPointConversion_Release64_ToInt") +let FixedPointConversion_Release64_ToInt = TestSuite( + "FixedPointConversion_Release64_ToInt" +) //===----------------------------------------------------------------------===// -// MARK: UInt8: (0)...(255) +// MARK: UInt8: (+0)...(+255) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt.test("FromUInt8(0)_NeverTraps") { - let input = getUInt8(0) - let actual = Int(input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToInt +.test("FromUInt8_NeverTraps") +.forEach(in: [ + (getInt(+0), getUInt8(+0)), + (getInt(+255), getUInt8(+255)), +]) { + expectEqual($0.0, Int($0.1)) } -FixedPointConversion_Release64_ToInt.test("FromUInt8(0)_NeverFails") { - let input = getUInt8(0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromUInt8(255)_NeverTraps") { - let input = getUInt8(255) - let actual = Int(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromUInt8(255)_NeverFails") { - let input = getUInt8(255) - let actual = Int(exactly: input) - expectEqual(255, actual) +FixedPointConversion_Release64_ToInt +.test("FromUInt8_NeverFails") +.forEach(in: [ + (getInt(+0), getUInt8(+0)), + (getInt(+255), getUInt8(+255)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int8: (-128)...(127) +// MARK: Int8: (-128)...(+127) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt.test("FromInt8(-128)_NeverTraps") { - let input = getInt8(-128) - let actual = Int(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromInt8(-128)_NeverFails") { - let input = getInt8(-128) - let actual = Int(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromInt8(0)_NeverTraps") { - let input = getInt8(0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromInt8(0)_NeverFails") { - let input = getInt8(0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromInt8(127)_NeverTraps") { - let input = getInt8(127) - let actual = Int(input) - expectEqual(127, actual) +FixedPointConversion_Release64_ToInt +.test("FromInt8_NeverTraps") +.forEach(in: [ + (getInt(-128), getInt8(-128)), + (getInt(+0), getInt8(+0)), + (getInt(+127), getInt8(+127)), +]) { + expectEqual($0.0, Int($0.1)) } -FixedPointConversion_Release64_ToInt.test("FromInt8(127)_NeverFails") { - let input = getInt8(127) - let actual = Int(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Release64_ToInt +.test("FromInt8_NeverFails") +.forEach(in: [ + (getInt(-128), getInt8(-128)), + (getInt(+0), getInt8(+0)), + (getInt(+127), getInt8(+127)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt16: (0)...(65535) +// MARK: UInt16: (+0)...(+65535) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt.test("FromUInt16(0)_NeverTraps") { - let input = getUInt16(0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromUInt16(0)_NeverFails") { - let input = getUInt16(0) - let actual = Int(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToInt +.test("FromUInt16_NeverTraps") +.forEach(in: [ + (getInt(+0), getUInt16(+0)), + (getInt(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, Int($0.1)) } -FixedPointConversion_Release64_ToInt.test("FromUInt16(65535)_NeverTraps") { - let input = getUInt16(65535) - let actual = Int(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromUInt16(65535)_NeverFails") { - let input = getUInt16(65535) - let actual = Int(exactly: input) - expectEqual(65535, actual) +FixedPointConversion_Release64_ToInt +.test("FromUInt16_NeverFails") +.forEach(in: [ + (getInt(+0), getUInt16(+0)), + (getInt(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int16: (-32768)...(32767) +// MARK: Int16: (-32768)...(+32767) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt.test("FromInt16(-32768)_NeverTraps") { - let input = getInt16(-32768) - let actual = Int(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromInt16(-32768)_NeverFails") { - let input = getInt16(-32768) - let actual = Int(exactly: input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromInt16(0)_NeverTraps") { - let input = getInt16(0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromInt16(0)_NeverFails") { - let input = getInt16(0) - let actual = Int(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToInt +.test("FromInt16_NeverTraps") +.forEach(in: [ + (getInt(-32768), getInt16(-32768)), + (getInt(+0), getInt16(+0)), + (getInt(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, Int($0.1)) } -FixedPointConversion_Release64_ToInt.test("FromInt16(32767)_NeverTraps") { - let input = getInt16(32767) - let actual = Int(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromInt16(32767)_NeverFails") { - let input = getInt16(32767) - let actual = Int(exactly: input) - expectEqual(32767, actual) +FixedPointConversion_Release64_ToInt +.test("FromInt16_NeverFails") +.forEach(in: [ + (getInt(-32768), getInt16(-32768)), + (getInt(+0), getInt16(+0)), + (getInt(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt32: (0)...(4294967295) +// MARK: UInt32: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt.test("FromUInt32(0)_NeverTraps") { - let input = getUInt32(0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromUInt32(0)_NeverFails") { - let input = getUInt32(0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromUInt32(4294967295)_NeverTraps") { - let input = getUInt32(4294967295) - let actual = Int(input) - expectEqual(4294967295, actual) +FixedPointConversion_Release64_ToInt +.test("FromUInt32_NeverTraps") +.forEach(in: [ + (getInt(+0), getUInt32(+0)), + (getInt(+4294967295), getUInt32(+4294967295)), +]) { + expectEqual($0.0, Int($0.1)) } -FixedPointConversion_Release64_ToInt.test("FromUInt32(4294967295)_NeverFails") { - let input = getUInt32(4294967295) - let actual = Int(exactly: input) - expectEqual(4294967295, actual) +FixedPointConversion_Release64_ToInt +.test("FromUInt32_NeverFails") +.forEach(in: [ + (getInt(+0), getUInt32(+0)), + (getInt(+4294967295), getUInt32(+4294967295)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int32: (-2147483648)...(2147483647) +// MARK: Int32: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt.test("FromInt32(-2147483648)_NeverTraps") { - let input = getInt32(-2147483648) - let actual = Int(input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromInt32(-2147483648)_NeverFails") { - let input = getInt32(-2147483648) - let actual = Int(exactly: input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromInt32(0)_NeverTraps") { - let input = getInt32(0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromInt32(0)_NeverFails") { - let input = getInt32(0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromInt32(2147483647)_NeverTraps") { - let input = getInt32(2147483647) - let actual = Int(input) - expectEqual(2147483647, actual) +FixedPointConversion_Release64_ToInt +.test("FromInt32_NeverTraps") +.forEach(in: [ + (getInt(-2147483648), getInt32(-2147483648)), + (getInt(+0), getInt32(+0)), + (getInt(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, Int($0.1)) } -FixedPointConversion_Release64_ToInt.test("FromInt32(2147483647)_NeverFails") { - let input = getInt32(2147483647) - let actual = Int(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Release64_ToInt +.test("FromInt32_NeverFails") +.forEach(in: [ + (getInt(-2147483648), getInt32(-2147483648)), + (getInt(+0), getInt32(+0)), + (getInt(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt64: (0)...(18446744073709551615) +// MARK: UInt64: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt.test("FromUInt64(0)_NeverTraps") { - let input = getUInt64(0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromUInt64(0)_NeverFails") { - let input = getUInt64(0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromUInt64(9223372036854775807)_NeverTraps") { - let input = getUInt64(9223372036854775807) - let actual = Int(input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromUInt64(9223372036854775807)_NeverFails") { - let input = getUInt64(9223372036854775807) - let actual = Int(exactly: input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromUInt64(9223372036854775808)_AlwaysTraps") { - let input = getUInt64(9223372036854775808) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } +FixedPointConversion_Release64_ToInt +.test("FromUInt64_NeverTraps") +.forEach(in: [ + (getInt(+0), getUInt64(+0)), + (getInt(+9223372036854775807), getUInt64(+9223372036854775807)), +]) { + expectEqual($0.0, Int($0.1)) } -FixedPointConversion_Release64_ToInt.test("FromUInt64(9223372036854775808)_AlwaysFails") { - let input = getUInt64(9223372036854775808) - let actual = Int(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt +.test("FromUInt64_NeverFails") +.forEach(in: [ + (getInt(+0), getUInt64(+0)), + (getInt(+9223372036854775807), getUInt64(+9223372036854775807)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) } -FixedPointConversion_Release64_ToInt.test("FromUInt64(18446744073709551615)_AlwaysTraps") { - let input = getUInt64(18446744073709551615) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } +FixedPointConversion_Release64_ToInt +.test("FromUInt64_AlwaysTraps") +.forEach(in: [ + getUInt64(+9223372036854775808), + getUInt64(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(Int($0)) } -FixedPointConversion_Release64_ToInt.test("FromUInt64(18446744073709551615)_AlwaysFails") { - let input = getUInt64(18446744073709551615) - let actual = Int(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt +.test("FromUInt64_AlwaysFails") +.forEach(in: [ + getUInt64(+9223372036854775808), + getUInt64(+18446744073709551615), +]) { + expectNil(Int(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int64: (-9223372036854775808)...(9223372036854775807) +// MARK: Int64: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt.test("FromInt64(-9223372036854775808)_NeverTraps") { - let input = getInt64(-9223372036854775808) - let actual = Int(input) - expectEqual(-9223372036854775808, actual) +FixedPointConversion_Release64_ToInt +.test("FromInt64_NeverTraps") +.forEach(in: [ + (getInt(-9223372036854775808), getInt64(-9223372036854775808)), + (getInt(+0), getInt64(+0)), + (getInt(+9223372036854775807), getInt64(+9223372036854775807)), +]) { + expectEqual($0.0, Int($0.1)) } -FixedPointConversion_Release64_ToInt.test("FromInt64(-9223372036854775808)_NeverFails") { - let input = getInt64(-9223372036854775808) - let actual = Int(exactly: input) - expectEqual(-9223372036854775808, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromInt64(0)_NeverTraps") { - let input = getInt64(0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromInt64(0)_NeverFails") { - let input = getInt64(0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromInt64(9223372036854775807)_NeverTraps") { - let input = getInt64(9223372036854775807) - let actual = Int(input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromInt64(9223372036854775807)_NeverFails") { - let input = getInt64(9223372036854775807) - let actual = Int(exactly: input) - expectEqual(9223372036854775807, actual) +FixedPointConversion_Release64_ToInt +.test("FromInt64_NeverFails") +.forEach(in: [ + (getInt(-9223372036854775808), getInt64(-9223372036854775808)), + (getInt(+0), getInt64(+0)), + (getInt(+9223372036854775807), getInt64(+9223372036854775807)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt: (0)...(18446744073709551615) +// MARK: UInt: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt.test("FromUInt(0)_NeverTraps") { - let input = getUInt(0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromUInt(0)_NeverFails") { - let input = getUInt(0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromUInt(9223372036854775807)_NeverTraps") { - let input = getUInt(9223372036854775807) - let actual = Int(input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromUInt(9223372036854775807)_NeverFails") { - let input = getUInt(9223372036854775807) - let actual = Int(exactly: input) - expectEqual(9223372036854775807, actual) +FixedPointConversion_Release64_ToInt +.test("FromUInt_NeverTraps") +.forEach(in: [ + (getInt(+0), getUInt(+0)), + (getInt(+9223372036854775807), getUInt(+9223372036854775807)), +]) { + expectEqual($0.0, Int($0.1)) } -FixedPointConversion_Release64_ToInt.test("FromUInt(9223372036854775808)_AlwaysTraps") { - let input = getUInt(9223372036854775808) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } +FixedPointConversion_Release64_ToInt +.test("FromUInt_NeverFails") +.forEach(in: [ + (getInt(+0), getUInt(+0)), + (getInt(+9223372036854775807), getUInt(+9223372036854775807)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) } -FixedPointConversion_Release64_ToInt.test("FromUInt(9223372036854775808)_AlwaysFails") { - let input = getUInt(9223372036854775808) - let actual = Int(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt +.test("FromUInt_AlwaysTraps") +.forEach(in: [ + getUInt(+9223372036854775808), + getUInt(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(Int($0)) } -FixedPointConversion_Release64_ToInt.test("FromUInt(18446744073709551615)_AlwaysTraps") { - let input = getUInt(18446744073709551615) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt.test("FromUInt(18446744073709551615)_AlwaysFails") { - let input = getUInt(18446744073709551615) - let actual = Int(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt +.test("FromUInt_AlwaysFails") +.forEach(in: [ + getUInt(+9223372036854775808), + getUInt(+18446744073709551615), +]) { + expectNil(Int(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int: (-9223372036854775808)...(9223372036854775807) +// MARK: Int: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt.test("FromInt(-9223372036854775808)_NeverTraps") { - let input = getInt(-9223372036854775808) - let actual = Int(input) - expectEqual(-9223372036854775808, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromInt(-9223372036854775808)_NeverFails") { - let input = getInt(-9223372036854775808) - let actual = Int(exactly: input) - expectEqual(-9223372036854775808, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromInt(0)_NeverTraps") { - let input = getInt(0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromInt(0)_NeverFails") { - let input = getInt(0) - let actual = Int(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToInt +.test("FromInt_NeverTraps") +.forEach(in: [ + (getInt(-9223372036854775808), getInt(-9223372036854775808)), + (getInt(+0), getInt(+0)), + (getInt(+9223372036854775807), getInt(+9223372036854775807)), +]) { + expectEqual($0.0, Int($0.1)) } -FixedPointConversion_Release64_ToInt.test("FromInt(9223372036854775807)_NeverTraps") { - let input = getInt(9223372036854775807) - let actual = Int(input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromInt(9223372036854775807)_NeverFails") { - let input = getInt(9223372036854775807) - let actual = Int(exactly: input) - expectEqual(9223372036854775807, actual) +FixedPointConversion_Release64_ToInt +.test("FromInt_NeverFails") +.forEach(in: [ + (getInt(-9223372036854775808), getInt(-9223372036854775808)), + (getInt(+0), getInt(+0)), + (getInt(+9223372036854775807), getInt(+9223372036854775807)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Float16: (-2047)...(2047) +// MARK: Float16: (-2047)...(+2047) //===----------------------------------------------------------------------===// #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -FixedPointConversion_Release64_ToInt.test("FromFloat16(-2047)_NeverTraps") { - let input = getFloat16(-2047) - let actual = Int(input) - expectEqual(-2047, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat16(-2047)_NeverFails") { - let input = getFloat16(-2047) - let actual = Int(exactly: input) - expectEqual(-2047, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat16(-128.5)_NeverTraps") { - let input = getFloat16(-128.5) - let actual = Int(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat16(-128.5)_AlwaysFails") { - let input = getFloat16(-128.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat16(-0.5)_NeverTraps") { - let input = getFloat16(-0.5) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat16(-0.5)_AlwaysFails") { - let input = getFloat16(-0.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat16(-0.0)_NeverTraps") { - let input = getFloat16(-0.0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat16(-0.0)_NeverFails") { - let input = getFloat16(-0.0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat16(0.0)_NeverTraps") { - let input = getFloat16(0.0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat16(0.0)_NeverFails") { - let input = getFloat16(0.0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat16(0.5)_NeverTraps") { - let input = getFloat16(0.5) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat16(0.5)_AlwaysFails") { - let input = getFloat16(0.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat16(127.5)_NeverTraps") { - let input = getFloat16(127.5) - let actual = Int(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat16(127.5)_AlwaysFails") { - let input = getFloat16(127.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat16(255.5)_NeverTraps") { - let input = getFloat16(255.5) - let actual = Int(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat16(255.5)_AlwaysFails") { - let input = getFloat16(255.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat16(2047)_NeverTraps") { - let input = getFloat16(2047) - let actual = Int(input) - expectEqual(2047, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat16(2047)_NeverFails") { - let input = getFloat16(2047) - let actual = Int(exactly: input) - expectEqual(2047, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat16(-.infinity)_AlwaysTraps") { - let input = getFloat16(-.infinity) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt.test("FromFloat16(-.infinity)_AlwaysFails") { - let input = getFloat16(-.infinity) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat16(+.infinity)_AlwaysTraps") { - let input = getFloat16(+.infinity) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt.test("FromFloat16(+.infinity)_AlwaysFails") { - let input = getFloat16(+.infinity) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat16(-.nan)_AlwaysTraps") { - let input = getFloat16(-.nan) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt.test("FromFloat16(-.nan)_AlwaysFails") { - let input = getFloat16(-.nan) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat16(+.nan)_AlwaysTraps") { - let input = getFloat16(+.nan) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt.test("FromFloat16(+.nan)_AlwaysFails") { - let input = getFloat16(+.nan) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat16(-.signalingNaN)_AlwaysTraps") { - let input = getFloat16(-.signalingNaN) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt.test("FromFloat16(-.signalingNaN)_AlwaysFails") { - let input = getFloat16(-.signalingNaN) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat16(+.signalingNaN)_AlwaysTraps") { - let input = getFloat16(+.signalingNaN) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt.test("FromFloat16(+.signalingNaN)_AlwaysFails") { - let input = getFloat16(+.signalingNaN) - let actual = Int(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt +.test("FromFloat16_NeverTraps") +.forEach(in: [ + (getInt(-2047), getFloat16(-2047)), + (getInt(-128), getFloat16(-128.5)), + (getInt(+0), getFloat16(-0.5)), + (getInt(+0), getFloat16(+0)), + (getInt(+0), getFloat16(-0)), + (getInt(+0), getFloat16(+0.5)), + (getInt(+127), getFloat16(+127.5)), + (getInt(+255), getFloat16(+255.5)), + (getInt(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, Int($0.1)) +} + +FixedPointConversion_Release64_ToInt +.test("FromFloat16_NeverFails") +.forEach(in: [ + (getInt(-2047), getFloat16(-2047)), + (getInt(+0), getFloat16(+0)), + (getInt(+0), getFloat16(-0)), + (getInt(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToInt +.test("FromFloat16_AlwaysTraps") +.forEach(in: [ + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int($0)) +} + +FixedPointConversion_Release64_ToInt +.test("FromFloat16_AlwaysFails") +.forEach(in: [ + getFloat16(-128.5), + getFloat16(-0.5), + getFloat16(+0.5), + getFloat16(+127.5), + getFloat16(+255.5), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectNil(Int(exactly: $0)) } } #endif // Float16 //===----------------------------------------------------------------------===// -// MARK: Float32: (-16777215)...(16777215) +// MARK: Float32: (-16777215)...(+16777215) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt.test("FromFloat32(-16777215)_NeverTraps") { - let input = getFloat32(-16777215) - let actual = Int(input) - expectEqual(-16777215, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat32(-16777215)_NeverFails") { - let input = getFloat32(-16777215) - let actual = Int(exactly: input) - expectEqual(-16777215, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat32(-32768.5)_NeverTraps") { - let input = getFloat32(-32768.5) - let actual = Int(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat32(-32768.5)_AlwaysFails") { - let input = getFloat32(-32768.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat32(-128.5)_NeverTraps") { - let input = getFloat32(-128.5) - let actual = Int(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat32(-128.5)_AlwaysFails") { - let input = getFloat32(-128.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat32(-0.5)_NeverTraps") { - let input = getFloat32(-0.5) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat32(-0.5)_AlwaysFails") { - let input = getFloat32(-0.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat32(-0.0)_NeverTraps") { - let input = getFloat32(-0.0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat32(-0.0)_NeverFails") { - let input = getFloat32(-0.0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat32(0.0)_NeverTraps") { - let input = getFloat32(0.0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat32(0.0)_NeverFails") { - let input = getFloat32(0.0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat32(0.5)_NeverTraps") { - let input = getFloat32(0.5) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat32(0.5)_AlwaysFails") { - let input = getFloat32(0.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat32(127.5)_NeverTraps") { - let input = getFloat32(127.5) - let actual = Int(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat32(127.5)_AlwaysFails") { - let input = getFloat32(127.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat32(255.5)_NeverTraps") { - let input = getFloat32(255.5) - let actual = Int(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat32(255.5)_AlwaysFails") { - let input = getFloat32(255.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat32(32767.5)_NeverTraps") { - let input = getFloat32(32767.5) - let actual = Int(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat32(32767.5)_AlwaysFails") { - let input = getFloat32(32767.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat32(65535.5)_NeverTraps") { - let input = getFloat32(65535.5) - let actual = Int(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat32(65535.5)_AlwaysFails") { - let input = getFloat32(65535.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat32(16777215)_NeverTraps") { - let input = getFloat32(16777215) - let actual = Int(input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat32(16777215)_NeverFails") { - let input = getFloat32(16777215) - let actual = Int(exactly: input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat32(-.infinity)_AlwaysTraps") { - let input = getFloat32(-.infinity) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt.test("FromFloat32(-.infinity)_AlwaysFails") { - let input = getFloat32(-.infinity) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat32(+.infinity)_AlwaysTraps") { - let input = getFloat32(+.infinity) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt.test("FromFloat32(+.infinity)_AlwaysFails") { - let input = getFloat32(+.infinity) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat32(-.nan)_AlwaysTraps") { - let input = getFloat32(-.nan) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt.test("FromFloat32(-.nan)_AlwaysFails") { - let input = getFloat32(-.nan) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat32(+.nan)_AlwaysTraps") { - let input = getFloat32(+.nan) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt.test("FromFloat32(+.nan)_AlwaysFails") { - let input = getFloat32(+.nan) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat32(-.signalingNaN)_AlwaysTraps") { - let input = getFloat32(-.signalingNaN) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt.test("FromFloat32(-.signalingNaN)_AlwaysFails") { - let input = getFloat32(-.signalingNaN) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat32(+.signalingNaN)_AlwaysTraps") { - let input = getFloat32(+.signalingNaN) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt.test("FromFloat32(+.signalingNaN)_AlwaysFails") { - let input = getFloat32(+.signalingNaN) - let actual = Int(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt +.test("FromFloat32_NeverTraps") +.forEach(in: [ + (getInt(-16777215), getFloat32(-16777215)), + (getInt(-32768), getFloat32(-32768.5)), + (getInt(-128), getFloat32(-128.5)), + (getInt(+0), getFloat32(-0.5)), + (getInt(+0), getFloat32(+0)), + (getInt(+0), getFloat32(-0)), + (getInt(+0), getFloat32(+0.5)), + (getInt(+127), getFloat32(+127.5)), + (getInt(+255), getFloat32(+255.5)), + (getInt(+32767), getFloat32(+32767.5)), + (getInt(+65535), getFloat32(+65535.5)), + (getInt(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, Int($0.1)) +} + +FixedPointConversion_Release64_ToInt +.test("FromFloat32_NeverFails") +.forEach(in: [ + (getInt(-16777215), getFloat32(-16777215)), + (getInt(+0), getFloat32(+0)), + (getInt(+0), getFloat32(-0)), + (getInt(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToInt +.test("FromFloat32_AlwaysTraps") +.forEach(in: [ + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int($0)) +} + +FixedPointConversion_Release64_ToInt +.test("FromFloat32_AlwaysFails") +.forEach(in: [ + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-0.5), + getFloat32(+0.5), + getFloat32(+127.5), + getFloat32(+255.5), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectNil(Int(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float64: (-9007199254740991)...(9007199254740991) +// MARK: Float64: (-9007199254740991)...(+9007199254740991) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt.test("FromFloat64(-9007199254740991)_NeverTraps") { - let input = getFloat64(-9007199254740991) - let actual = Int(input) - expectEqual(-9007199254740991, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat64(-9007199254740991)_NeverFails") { - let input = getFloat64(-9007199254740991) - let actual = Int(exactly: input) - expectEqual(-9007199254740991, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat64(-32768.5)_NeverTraps") { - let input = getFloat64(-32768.5) - let actual = Int(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat64(-32768.5)_AlwaysFails") { - let input = getFloat64(-32768.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat64(-128.5)_NeverTraps") { - let input = getFloat64(-128.5) - let actual = Int(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat64(-128.5)_AlwaysFails") { - let input = getFloat64(-128.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat64(-0.5)_NeverTraps") { - let input = getFloat64(-0.5) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat64(-0.5)_AlwaysFails") { - let input = getFloat64(-0.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat64(-0.0)_NeverTraps") { - let input = getFloat64(-0.0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat64(-0.0)_NeverFails") { - let input = getFloat64(-0.0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat64(0.0)_NeverTraps") { - let input = getFloat64(0.0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat64(0.0)_NeverFails") { - let input = getFloat64(0.0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat64(0.5)_NeverTraps") { - let input = getFloat64(0.5) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat64(0.5)_AlwaysFails") { - let input = getFloat64(0.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat64(127.5)_NeverTraps") { - let input = getFloat64(127.5) - let actual = Int(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat64(127.5)_AlwaysFails") { - let input = getFloat64(127.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat64(255.5)_NeverTraps") { - let input = getFloat64(255.5) - let actual = Int(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat64(255.5)_AlwaysFails") { - let input = getFloat64(255.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat64(32767.5)_NeverTraps") { - let input = getFloat64(32767.5) - let actual = Int(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat64(32767.5)_AlwaysFails") { - let input = getFloat64(32767.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat64(65535.5)_NeverTraps") { - let input = getFloat64(65535.5) - let actual = Int(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat64(65535.5)_AlwaysFails") { - let input = getFloat64(65535.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat64(9007199254740991)_NeverTraps") { - let input = getFloat64(9007199254740991) - let actual = Int(input) - expectEqual(9007199254740991, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat64(9007199254740991)_NeverFails") { - let input = getFloat64(9007199254740991) - let actual = Int(exactly: input) - expectEqual(9007199254740991, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat64(-.infinity)_AlwaysTraps") { - let input = getFloat64(-.infinity) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt.test("FromFloat64(-.infinity)_AlwaysFails") { - let input = getFloat64(-.infinity) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat64(+.infinity)_AlwaysTraps") { - let input = getFloat64(+.infinity) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt.test("FromFloat64(+.infinity)_AlwaysFails") { - let input = getFloat64(+.infinity) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat64(-.nan)_AlwaysTraps") { - let input = getFloat64(-.nan) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt.test("FromFloat64(-.nan)_AlwaysFails") { - let input = getFloat64(-.nan) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat64(+.nan)_AlwaysTraps") { - let input = getFloat64(+.nan) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt.test("FromFloat64(+.nan)_AlwaysFails") { - let input = getFloat64(+.nan) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat64(-.signalingNaN)_AlwaysTraps") { - let input = getFloat64(-.signalingNaN) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt.test("FromFloat64(-.signalingNaN)_AlwaysFails") { - let input = getFloat64(-.signalingNaN) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat64(+.signalingNaN)_AlwaysTraps") { - let input = getFloat64(+.signalingNaN) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt.test("FromFloat64(+.signalingNaN)_AlwaysFails") { - let input = getFloat64(+.signalingNaN) - let actual = Int(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt +.test("FromFloat64_NeverTraps") +.forEach(in: [ + (getInt(-9007199254740991), getFloat64(-9007199254740991)), + (getInt(-32768), getFloat64(-32768.5)), + (getInt(-128), getFloat64(-128.5)), + (getInt(+0), getFloat64(-0.5)), + (getInt(+0), getFloat64(+0)), + (getInt(+0), getFloat64(-0)), + (getInt(+0), getFloat64(+0.5)), + (getInt(+127), getFloat64(+127.5)), + (getInt(+255), getFloat64(+255.5)), + (getInt(+32767), getFloat64(+32767.5)), + (getInt(+65535), getFloat64(+65535.5)), + (getInt(+9007199254740991), getFloat64(+9007199254740991)), +]) { + expectEqual($0.0, Int($0.1)) +} + +FixedPointConversion_Release64_ToInt +.test("FromFloat64_NeverFails") +.forEach(in: [ + (getInt(-9007199254740991), getFloat64(-9007199254740991)), + (getInt(+0), getFloat64(+0)), + (getInt(+0), getFloat64(-0)), + (getInt(+9007199254740991), getFloat64(+9007199254740991)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToInt +.test("FromFloat64_AlwaysTraps") +.forEach(in: [ + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int($0)) +} + +FixedPointConversion_Release64_ToInt +.test("FromFloat64_AlwaysFails") +.forEach(in: [ + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-0.5), + getFloat64(+0.5), + getFloat64(+127.5), + getFloat64(+255.5), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectNil(Int(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float80: (-18446744073709551615)...(18446744073709551615) +// MARK: Float80: (-18446744073709551615)...(+18446744073709551615) //===----------------------------------------------------------------------===// #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) -FixedPointConversion_Release64_ToInt.test("FromFloat80(-18446744073709551615)_AlwaysTraps") { - let input = getFloat80(-18446744073709551615) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(-18446744073709551615)_AlwaysFails") { - let input = getFloat80(-18446744073709551615) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(-9223372036854775809)_AlwaysTraps") { - let input = getFloat80(-9223372036854775809) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(-9223372036854775809)_AlwaysFails") { - let input = getFloat80(-9223372036854775809) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(-9223372036854775808)_NeverTraps") { - let input = getFloat80(-9223372036854775808) - let actual = Int(input) - expectEqual(-9223372036854775808, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(-9223372036854775808)_NeverFails") { - let input = getFloat80(-9223372036854775808) - let actual = Int(exactly: input) - expectEqual(-9223372036854775808, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(-32768.5)_NeverTraps") { - let input = getFloat80(-32768.5) - let actual = Int(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(-32768.5)_AlwaysFails") { - let input = getFloat80(-32768.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(-128.5)_NeverTraps") { - let input = getFloat80(-128.5) - let actual = Int(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(-128.5)_AlwaysFails") { - let input = getFloat80(-128.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(-0.5)_NeverTraps") { - let input = getFloat80(-0.5) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(-0.5)_AlwaysFails") { - let input = getFloat80(-0.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(-0.0)_NeverTraps") { - let input = getFloat80(-0.0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(-0.0)_NeverFails") { - let input = getFloat80(-0.0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(0.0)_NeverTraps") { - let input = getFloat80(0.0) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(0.0)_NeverFails") { - let input = getFloat80(0.0) - let actual = Int(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(0.5)_NeverTraps") { - let input = getFloat80(0.5) - let actual = Int(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(0.5)_AlwaysFails") { - let input = getFloat80(0.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(127.5)_NeverTraps") { - let input = getFloat80(127.5) - let actual = Int(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(127.5)_AlwaysFails") { - let input = getFloat80(127.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(255.5)_NeverTraps") { - let input = getFloat80(255.5) - let actual = Int(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(255.5)_AlwaysFails") { - let input = getFloat80(255.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(32767.5)_NeverTraps") { - let input = getFloat80(32767.5) - let actual = Int(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(32767.5)_AlwaysFails") { - let input = getFloat80(32767.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(65535.5)_NeverTraps") { - let input = getFloat80(65535.5) - let actual = Int(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(65535.5)_AlwaysFails") { - let input = getFloat80(65535.5) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(9223372036854775807)_NeverTraps") { - let input = getFloat80(9223372036854775807) - let actual = Int(input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(9223372036854775807)_NeverFails") { - let input = getFloat80(9223372036854775807) - let actual = Int(exactly: input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(9223372036854775808)_AlwaysTraps") { - let input = getFloat80(9223372036854775808) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(9223372036854775808)_AlwaysFails") { - let input = getFloat80(9223372036854775808) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(18446744073709551615)_AlwaysTraps") { - let input = getFloat80(18446744073709551615) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(18446744073709551615)_AlwaysFails") { - let input = getFloat80(18446744073709551615) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(-.infinity)_AlwaysTraps") { - let input = getFloat80(-.infinity) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(-.infinity)_AlwaysFails") { - let input = getFloat80(-.infinity) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(+.infinity)_AlwaysTraps") { - let input = getFloat80(+.infinity) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(+.infinity)_AlwaysFails") { - let input = getFloat80(+.infinity) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(-.nan)_AlwaysTraps") { - let input = getFloat80(-.nan) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(-.nan)_AlwaysFails") { - let input = getFloat80(-.nan) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(+.nan)_AlwaysTraps") { - let input = getFloat80(+.nan) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(+.nan)_AlwaysFails") { - let input = getFloat80(+.nan) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(-.signalingNaN)_AlwaysTraps") { - let input = getFloat80(-.signalingNaN) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(-.signalingNaN)_AlwaysFails") { - let input = getFloat80(-.signalingNaN) - let actual = Int(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(+.signalingNaN)_AlwaysTraps") { - let input = getFloat80(+.signalingNaN) - expectCrash { - let actual = Int(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt.test("FromFloat80(+.signalingNaN)_AlwaysFails") { - let input = getFloat80(+.signalingNaN) - let actual = Int(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt +.test("FromFloat80_NeverTraps") +.forEach(in: [ + (getInt(-9223372036854775808), getFloat80(-9223372036854775808)), + (getInt(-32768), getFloat80(-32768.5)), + (getInt(-128), getFloat80(-128.5)), + (getInt(+0), getFloat80(-0.5)), + (getInt(+0), getFloat80(-0)), + (getInt(+0), getFloat80(+0)), + (getInt(+0), getFloat80(+0.5)), + (getInt(+127), getFloat80(+127.5)), + (getInt(+255), getFloat80(+255.5)), + (getInt(+32767), getFloat80(+32767.5)), + (getInt(+65535), getFloat80(+65535.5)), + (getInt(+9223372036854775807), getFloat80(+9223372036854775807)), +]) { + expectEqual($0.0, Int($0.1)) +} + +FixedPointConversion_Release64_ToInt +.test("FromFloat80_NeverFails") +.forEach(in: [ + (getInt(-9223372036854775808), getFloat80(-9223372036854775808)), + (getInt(+0), getFloat80(-0)), + (getInt(+0), getFloat80(+0)), + (getInt(+9223372036854775807), getFloat80(+9223372036854775807)), +]) { + expectEqual($0.0, Int(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToInt +.test("FromFloat80_AlwaysTraps") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-9223372036854775809), + getFloat80(+9223372036854775808), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int($0)) +} + +FixedPointConversion_Release64_ToInt +.test("FromFloat80_AlwaysFails") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-9223372036854775809), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-0.5), + getFloat80(+0.5), + getFloat80(+127.5), + getFloat80(+255.5), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(+9223372036854775808), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectNil(Int(exactly: $0)) } #endif // Float80 diff --git a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release64_ToInt16.swift b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release64_ToInt16.swift index 913bb6f9cb1d7..e44bd22f9bdcf 100644 --- a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release64_ToInt16.swift +++ b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release64_ToInt16.swift @@ -14,1700 +14,685 @@ import StdlibUnittest -let FixedPointConversion_Release64_ToInt16 = TestSuite("FixedPointConversion_Release64_ToInt16") +let FixedPointConversion_Release64_ToInt16 = TestSuite( + "FixedPointConversion_Release64_ToInt16" +) //===----------------------------------------------------------------------===// -// MARK: UInt8: (0)...(255) +// MARK: UInt8: (+0)...(+255) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt16.test("FromUInt8(0)_NeverTraps") { - let input = getUInt8(0) - let actual = Int16(input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToInt16 +.test("FromUInt8_NeverTraps") +.forEach(in: [ + (getInt16(+0), getUInt8(+0)), + (getInt16(+255), getUInt8(+255)), +]) { + expectEqual($0.0, Int16($0.1)) } -FixedPointConversion_Release64_ToInt16.test("FromUInt8(0)_NeverFails") { - let input = getUInt8(0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromUInt8(255)_NeverTraps") { - let input = getUInt8(255) - let actual = Int16(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromUInt8(255)_NeverFails") { - let input = getUInt8(255) - let actual = Int16(exactly: input) - expectEqual(255, actual) +FixedPointConversion_Release64_ToInt16 +.test("FromUInt8_NeverFails") +.forEach(in: [ + (getInt16(+0), getUInt8(+0)), + (getInt16(+255), getUInt8(+255)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int8: (-128)...(127) +// MARK: Int8: (-128)...(+127) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt16.test("FromInt8(-128)_NeverTraps") { - let input = getInt8(-128) - let actual = Int16(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromInt8(-128)_NeverFails") { - let input = getInt8(-128) - let actual = Int16(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromInt8(0)_NeverTraps") { - let input = getInt8(0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromInt8(0)_NeverFails") { - let input = getInt8(0) - let actual = Int16(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToInt16 +.test("FromInt8_NeverTraps") +.forEach(in: [ + (getInt16(-128), getInt8(-128)), + (getInt16(+0), getInt8(+0)), + (getInt16(+127), getInt8(+127)), +]) { + expectEqual($0.0, Int16($0.1)) } -FixedPointConversion_Release64_ToInt16.test("FromInt8(127)_NeverTraps") { - let input = getInt8(127) - let actual = Int16(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromInt8(127)_NeverFails") { - let input = getInt8(127) - let actual = Int16(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Release64_ToInt16 +.test("FromInt8_NeverFails") +.forEach(in: [ + (getInt16(-128), getInt8(-128)), + (getInt16(+0), getInt8(+0)), + (getInt16(+127), getInt8(+127)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt16: (0)...(65535) +// MARK: UInt16: (+0)...(+65535) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt16.test("FromUInt16(0)_NeverTraps") { - let input = getUInt16(0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromUInt16(0)_NeverFails") { - let input = getUInt16(0) - let actual = Int16(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToInt16 +.test("FromUInt16_NeverTraps") +.forEach(in: [ + (getInt16(+0), getUInt16(+0)), + (getInt16(+32767), getUInt16(+32767)), +]) { + expectEqual($0.0, Int16($0.1)) } -FixedPointConversion_Release64_ToInt16.test("FromUInt16(32767)_NeverTraps") { - let input = getUInt16(32767) - let actual = Int16(input) - expectEqual(32767, actual) +FixedPointConversion_Release64_ToInt16 +.test("FromUInt16_NeverFails") +.forEach(in: [ + (getInt16(+0), getUInt16(+0)), + (getInt16(+32767), getUInt16(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) } -FixedPointConversion_Release64_ToInt16.test("FromUInt16(32767)_NeverFails") { - let input = getUInt16(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) +FixedPointConversion_Release64_ToInt16 +.test("FromUInt16_AlwaysTraps") +.forEach(in: [ + getUInt16(+32768), + getUInt16(+65535), +]) { + expectCrashLater() + _blackHole(Int16($0)) } -FixedPointConversion_Release64_ToInt16.test("FromUInt16(32768)_AlwaysTraps") { - let input = getUInt16(32768) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromUInt16(32768)_AlwaysFails") { - let input = getUInt16(32768) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromUInt16(65535)_AlwaysTraps") { - let input = getUInt16(65535) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromUInt16(65535)_AlwaysFails") { - let input = getUInt16(65535) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt16 +.test("FromUInt16_AlwaysFails") +.forEach(in: [ + getUInt16(+32768), + getUInt16(+65535), +]) { + expectNil(Int16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int16: (-32768)...(32767) +// MARK: Int16: (-32768)...(+32767) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt16.test("FromInt16(-32768)_NeverTraps") { - let input = getInt16(-32768) - let actual = Int16(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromInt16(-32768)_NeverFails") { - let input = getInt16(-32768) - let actual = Int16(exactly: input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromInt16(0)_NeverTraps") { - let input = getInt16(0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromInt16(0)_NeverFails") { - let input = getInt16(0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromInt16(32767)_NeverTraps") { - let input = getInt16(32767) - let actual = Int16(input) - expectEqual(32767, actual) +FixedPointConversion_Release64_ToInt16 +.test("FromInt16_NeverTraps") +.forEach(in: [ + (getInt16(-32768), getInt16(-32768)), + (getInt16(+0), getInt16(+0)), + (getInt16(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, Int16($0.1)) } -FixedPointConversion_Release64_ToInt16.test("FromInt16(32767)_NeverFails") { - let input = getInt16(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) +FixedPointConversion_Release64_ToInt16 +.test("FromInt16_NeverFails") +.forEach(in: [ + (getInt16(-32768), getInt16(-32768)), + (getInt16(+0), getInt16(+0)), + (getInt16(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt32: (0)...(4294967295) +// MARK: UInt32: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt16.test("FromUInt32(0)_NeverTraps") { - let input = getUInt32(0) - let actual = Int16(input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToInt16 +.test("FromUInt32_NeverTraps") +.forEach(in: [ + (getInt16(+0), getUInt32(+0)), + (getInt16(+32767), getUInt32(+32767)), +]) { + expectEqual($0.0, Int16($0.1)) } -FixedPointConversion_Release64_ToInt16.test("FromUInt32(0)_NeverFails") { - let input = getUInt32(0) - let actual = Int16(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToInt16 +.test("FromUInt32_NeverFails") +.forEach(in: [ + (getInt16(+0), getUInt32(+0)), + (getInt16(+32767), getUInt32(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) } -FixedPointConversion_Release64_ToInt16.test("FromUInt32(32767)_NeverTraps") { - let input = getUInt32(32767) - let actual = Int16(input) - expectEqual(32767, actual) +FixedPointConversion_Release64_ToInt16 +.test("FromUInt32_AlwaysTraps") +.forEach(in: [ + getUInt32(+32768), + getUInt32(+4294967295), +]) { + expectCrashLater() + _blackHole(Int16($0)) } -FixedPointConversion_Release64_ToInt16.test("FromUInt32(32767)_NeverFails") { - let input = getUInt32(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromUInt32(32768)_AlwaysTraps") { - let input = getUInt32(32768) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromUInt32(32768)_AlwaysFails") { - let input = getUInt32(32768) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromUInt32(4294967295)_AlwaysTraps") { - let input = getUInt32(4294967295) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromUInt32(4294967295)_AlwaysFails") { - let input = getUInt32(4294967295) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt16 +.test("FromUInt32_AlwaysFails") +.forEach(in: [ + getUInt32(+32768), + getUInt32(+4294967295), +]) { + expectNil(Int16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int32: (-2147483648)...(2147483647) +// MARK: Int32: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt16.test("FromInt32(-2147483648)_AlwaysTraps") { - let input = getInt32(-2147483648) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromInt32(-2147483648)_AlwaysFails") { - let input = getInt32(-2147483648) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromInt32(-32769)_AlwaysTraps") { - let input = getInt32(-32769) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromInt32(-32769)_AlwaysFails") { - let input = getInt32(-32769) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromInt32(-32768)_NeverTraps") { - let input = getInt32(-32768) - let actual = Int16(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromInt32(-32768)_NeverFails") { - let input = getInt32(-32768) - let actual = Int16(exactly: input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromInt32(0)_NeverTraps") { - let input = getInt32(0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromInt32(0)_NeverFails") { - let input = getInt32(0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromInt32(32767)_NeverTraps") { - let input = getInt32(32767) - let actual = Int16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromInt32(32767)_NeverFails") { - let input = getInt32(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromInt32(32768)_AlwaysTraps") { - let input = getInt32(32768) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromInt32(32768)_AlwaysFails") { - let input = getInt32(32768) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromInt32(2147483647)_AlwaysTraps") { - let input = getInt32(2147483647) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromInt32(2147483647)_AlwaysFails") { - let input = getInt32(2147483647) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt16 +.test("FromInt32_NeverTraps") +.forEach(in: [ + (getInt16(-32768), getInt32(-32768)), + (getInt16(+0), getInt32(+0)), + (getInt16(+32767), getInt32(+32767)), +]) { + expectEqual($0.0, Int16($0.1)) +} + +FixedPointConversion_Release64_ToInt16 +.test("FromInt32_NeverFails") +.forEach(in: [ + (getInt16(-32768), getInt32(-32768)), + (getInt16(+0), getInt32(+0)), + (getInt16(+32767), getInt32(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToInt16 +.test("FromInt32_AlwaysTraps") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-32769), + getInt32(+32768), + getInt32(+2147483647), +]) { + expectCrashLater() + _blackHole(Int16($0)) +} + +FixedPointConversion_Release64_ToInt16 +.test("FromInt32_AlwaysFails") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-32769), + getInt32(+32768), + getInt32(+2147483647), +]) { + expectNil(Int16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt64: (0)...(18446744073709551615) +// MARK: UInt64: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt16.test("FromUInt64(0)_NeverTraps") { - let input = getUInt64(0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromUInt64(0)_NeverFails") { - let input = getUInt64(0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromUInt64(32767)_NeverTraps") { - let input = getUInt64(32767) - let actual = Int16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromUInt64(32767)_NeverFails") { - let input = getUInt64(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromUInt64(32768)_AlwaysTraps") { - let input = getUInt64(32768) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } +FixedPointConversion_Release64_ToInt16 +.test("FromUInt64_NeverTraps") +.forEach(in: [ + (getInt16(+0), getUInt64(+0)), + (getInt16(+32767), getUInt64(+32767)), +]) { + expectEqual($0.0, Int16($0.1)) } -FixedPointConversion_Release64_ToInt16.test("FromUInt64(32768)_AlwaysFails") { - let input = getUInt64(32768) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt16 +.test("FromUInt64_NeverFails") +.forEach(in: [ + (getInt16(+0), getUInt64(+0)), + (getInt16(+32767), getUInt64(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) } -FixedPointConversion_Release64_ToInt16.test("FromUInt64(18446744073709551615)_AlwaysTraps") { - let input = getUInt64(18446744073709551615) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } +FixedPointConversion_Release64_ToInt16 +.test("FromUInt64_AlwaysTraps") +.forEach(in: [ + getUInt64(+32768), + getUInt64(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(Int16($0)) } -FixedPointConversion_Release64_ToInt16.test("FromUInt64(18446744073709551615)_AlwaysFails") { - let input = getUInt64(18446744073709551615) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt16 +.test("FromUInt64_AlwaysFails") +.forEach(in: [ + getUInt64(+32768), + getUInt64(+18446744073709551615), +]) { + expectNil(Int16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int64: (-9223372036854775808)...(9223372036854775807) +// MARK: Int64: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt16.test("FromInt64(-9223372036854775808)_AlwaysTraps") { - let input = getInt64(-9223372036854775808) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromInt64(-9223372036854775808)_AlwaysFails") { - let input = getInt64(-9223372036854775808) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromInt64(-32769)_AlwaysTraps") { - let input = getInt64(-32769) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromInt64(-32769)_AlwaysFails") { - let input = getInt64(-32769) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromInt64(-32768)_NeverTraps") { - let input = getInt64(-32768) - let actual = Int16(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromInt64(-32768)_NeverFails") { - let input = getInt64(-32768) - let actual = Int16(exactly: input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromInt64(0)_NeverTraps") { - let input = getInt64(0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromInt64(0)_NeverFails") { - let input = getInt64(0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromInt64(32767)_NeverTraps") { - let input = getInt64(32767) - let actual = Int16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromInt64(32767)_NeverFails") { - let input = getInt64(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromInt64(32768)_AlwaysTraps") { - let input = getInt64(32768) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromInt64(32768)_AlwaysFails") { - let input = getInt64(32768) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromInt64(9223372036854775807)_AlwaysTraps") { - let input = getInt64(9223372036854775807) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromInt64(9223372036854775807)_AlwaysFails") { - let input = getInt64(9223372036854775807) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt16 +.test("FromInt64_NeverTraps") +.forEach(in: [ + (getInt16(-32768), getInt64(-32768)), + (getInt16(+0), getInt64(+0)), + (getInt16(+32767), getInt64(+32767)), +]) { + expectEqual($0.0, Int16($0.1)) +} + +FixedPointConversion_Release64_ToInt16 +.test("FromInt64_NeverFails") +.forEach(in: [ + (getInt16(-32768), getInt64(-32768)), + (getInt16(+0), getInt64(+0)), + (getInt16(+32767), getInt64(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToInt16 +.test("FromInt64_AlwaysTraps") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-32769), + getInt64(+32768), + getInt64(+9223372036854775807), +]) { + expectCrashLater() + _blackHole(Int16($0)) +} + +FixedPointConversion_Release64_ToInt16 +.test("FromInt64_AlwaysFails") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-32769), + getInt64(+32768), + getInt64(+9223372036854775807), +]) { + expectNil(Int16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt: (0)...(18446744073709551615) +// MARK: UInt: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt16.test("FromUInt(0)_NeverTraps") { - let input = getUInt(0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromUInt(0)_NeverFails") { - let input = getUInt(0) - let actual = Int16(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToInt16 +.test("FromUInt_NeverTraps") +.forEach(in: [ + (getInt16(+0), getUInt(+0)), + (getInt16(+32767), getUInt(+32767)), +]) { + expectEqual($0.0, Int16($0.1)) } -FixedPointConversion_Release64_ToInt16.test("FromUInt(32767)_NeverTraps") { - let input = getUInt(32767) - let actual = Int16(input) - expectEqual(32767, actual) +FixedPointConversion_Release64_ToInt16 +.test("FromUInt_NeverFails") +.forEach(in: [ + (getInt16(+0), getUInt(+0)), + (getInt16(+32767), getUInt(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) } -FixedPointConversion_Release64_ToInt16.test("FromUInt(32767)_NeverFails") { - let input = getUInt(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) +FixedPointConversion_Release64_ToInt16 +.test("FromUInt_AlwaysTraps") +.forEach(in: [ + getUInt(+32768), + getUInt(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(Int16($0)) } -FixedPointConversion_Release64_ToInt16.test("FromUInt(32768)_AlwaysTraps") { - let input = getUInt(32768) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromUInt(32768)_AlwaysFails") { - let input = getUInt(32768) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromUInt(18446744073709551615)_AlwaysTraps") { - let input = getUInt(18446744073709551615) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromUInt(18446744073709551615)_AlwaysFails") { - let input = getUInt(18446744073709551615) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt16 +.test("FromUInt_AlwaysFails") +.forEach(in: [ + getUInt(+32768), + getUInt(+18446744073709551615), +]) { + expectNil(Int16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int: (-9223372036854775808)...(9223372036854775807) +// MARK: Int: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt16.test("FromInt(-9223372036854775808)_AlwaysTraps") { - let input = getInt(-9223372036854775808) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromInt(-9223372036854775808)_AlwaysFails") { - let input = getInt(-9223372036854775808) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromInt(-32769)_AlwaysTraps") { - let input = getInt(-32769) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromInt(-32769)_AlwaysFails") { - let input = getInt(-32769) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromInt(-32768)_NeverTraps") { - let input = getInt(-32768) - let actual = Int16(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromInt(-32768)_NeverFails") { - let input = getInt(-32768) - let actual = Int16(exactly: input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromInt(0)_NeverTraps") { - let input = getInt(0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromInt(0)_NeverFails") { - let input = getInt(0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromInt(32767)_NeverTraps") { - let input = getInt(32767) - let actual = Int16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromInt(32767)_NeverFails") { - let input = getInt(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromInt(32768)_AlwaysTraps") { - let input = getInt(32768) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromInt(32768)_AlwaysFails") { - let input = getInt(32768) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromInt(9223372036854775807)_AlwaysTraps") { - let input = getInt(9223372036854775807) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromInt(9223372036854775807)_AlwaysFails") { - let input = getInt(9223372036854775807) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt16 +.test("FromInt_NeverTraps") +.forEach(in: [ + (getInt16(-32768), getInt(-32768)), + (getInt16(+0), getInt(+0)), + (getInt16(+32767), getInt(+32767)), +]) { + expectEqual($0.0, Int16($0.1)) +} + +FixedPointConversion_Release64_ToInt16 +.test("FromInt_NeverFails") +.forEach(in: [ + (getInt16(-32768), getInt(-32768)), + (getInt16(+0), getInt(+0)), + (getInt16(+32767), getInt(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToInt16 +.test("FromInt_AlwaysTraps") +.forEach(in: [ + getInt(-9223372036854775808), + getInt(-32769), + getInt(+32768), + getInt(+9223372036854775807), +]) { + expectCrashLater() + _blackHole(Int16($0)) +} + +FixedPointConversion_Release64_ToInt16 +.test("FromInt_AlwaysFails") +.forEach(in: [ + getInt(-9223372036854775808), + getInt(-32769), + getInt(+32768), + getInt(+9223372036854775807), +]) { + expectNil(Int16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float16: (-2047)...(2047) +// MARK: Float16: (-2047)...(+2047) //===----------------------------------------------------------------------===// #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -FixedPointConversion_Release64_ToInt16.test("FromFloat16(-2047)_NeverTraps") { - let input = getFloat16(-2047) - let actual = Int16(input) - expectEqual(-2047, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat16(-2047)_NeverFails") { - let input = getFloat16(-2047) - let actual = Int16(exactly: input) - expectEqual(-2047, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat16(-128.5)_NeverTraps") { - let input = getFloat16(-128.5) - let actual = Int16(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat16(-128.5)_AlwaysFails") { - let input = getFloat16(-128.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat16(-0.5)_NeverTraps") { - let input = getFloat16(-0.5) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat16(-0.5)_AlwaysFails") { - let input = getFloat16(-0.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat16(-0.0)_NeverTraps") { - let input = getFloat16(-0.0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat16(-0.0)_NeverFails") { - let input = getFloat16(-0.0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat16(0.0)_NeverTraps") { - let input = getFloat16(0.0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat16(0.0)_NeverFails") { - let input = getFloat16(0.0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat16(0.5)_NeverTraps") { - let input = getFloat16(0.5) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat16(0.5)_AlwaysFails") { - let input = getFloat16(0.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat16(127.5)_NeverTraps") { - let input = getFloat16(127.5) - let actual = Int16(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat16(127.5)_AlwaysFails") { - let input = getFloat16(127.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat16(255.5)_NeverTraps") { - let input = getFloat16(255.5) - let actual = Int16(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat16(255.5)_AlwaysFails") { - let input = getFloat16(255.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat16(2047)_NeverTraps") { - let input = getFloat16(2047) - let actual = Int16(input) - expectEqual(2047, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat16(2047)_NeverFails") { - let input = getFloat16(2047) - let actual = Int16(exactly: input) - expectEqual(2047, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat16(-.infinity)_AlwaysTraps") { - let input = getFloat16(-.infinity) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat16(-.infinity)_AlwaysFails") { - let input = getFloat16(-.infinity) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat16(+.infinity)_AlwaysTraps") { - let input = getFloat16(+.infinity) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat16(+.infinity)_AlwaysFails") { - let input = getFloat16(+.infinity) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat16(-.nan)_AlwaysTraps") { - let input = getFloat16(-.nan) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat16(-.nan)_AlwaysFails") { - let input = getFloat16(-.nan) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat16(+.nan)_AlwaysTraps") { - let input = getFloat16(+.nan) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat16(+.nan)_AlwaysFails") { - let input = getFloat16(+.nan) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat16(-.signalingNaN)_AlwaysTraps") { - let input = getFloat16(-.signalingNaN) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat16(-.signalingNaN)_AlwaysFails") { - let input = getFloat16(-.signalingNaN) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat16(+.signalingNaN)_AlwaysTraps") { - let input = getFloat16(+.signalingNaN) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat16(+.signalingNaN)_AlwaysFails") { - let input = getFloat16(+.signalingNaN) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt16 +.test("FromFloat16_NeverTraps") +.forEach(in: [ + (getInt16(-2047), getFloat16(-2047)), + (getInt16(-128), getFloat16(-128.5)), + (getInt16(+0), getFloat16(-0.5)), + (getInt16(+0), getFloat16(+0)), + (getInt16(+0), getFloat16(-0)), + (getInt16(+0), getFloat16(+0.5)), + (getInt16(+127), getFloat16(+127.5)), + (getInt16(+255), getFloat16(+255.5)), + (getInt16(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, Int16($0.1)) +} + +FixedPointConversion_Release64_ToInt16 +.test("FromFloat16_NeverFails") +.forEach(in: [ + (getInt16(-2047), getFloat16(-2047)), + (getInt16(+0), getFloat16(+0)), + (getInt16(+0), getFloat16(-0)), + (getInt16(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToInt16 +.test("FromFloat16_AlwaysTraps") +.forEach(in: [ + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int16($0)) +} + +FixedPointConversion_Release64_ToInt16 +.test("FromFloat16_AlwaysFails") +.forEach(in: [ + getFloat16(-128.5), + getFloat16(-0.5), + getFloat16(+0.5), + getFloat16(+127.5), + getFloat16(+255.5), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectNil(Int16(exactly: $0)) } } #endif // Float16 //===----------------------------------------------------------------------===// -// MARK: Float32: (-16777215)...(16777215) +// MARK: Float32: (-16777215)...(+16777215) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt16.test("FromFloat32(-16777215)_AlwaysTraps") { - let input = getFloat32(-16777215) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(-16777215)_AlwaysFails") { - let input = getFloat32(-16777215) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(-32769)_AlwaysTraps") { - let input = getFloat32(-32769) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(-32769)_AlwaysFails") { - let input = getFloat32(-32769) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(-32768.5)_NeverTraps") { - let input = getFloat32(-32768.5) - let actual = Int16(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(-32768.5)_AlwaysFails") { - let input = getFloat32(-32768.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(-32768)_NeverTraps") { - let input = getFloat32(-32768) - let actual = Int16(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(-32768)_NeverFails") { - let input = getFloat32(-32768) - let actual = Int16(exactly: input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(-128.5)_NeverTraps") { - let input = getFloat32(-128.5) - let actual = Int16(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(-128.5)_AlwaysFails") { - let input = getFloat32(-128.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(-0.5)_NeverTraps") { - let input = getFloat32(-0.5) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(-0.5)_AlwaysFails") { - let input = getFloat32(-0.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(-0.0)_NeverTraps") { - let input = getFloat32(-0.0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(-0.0)_NeverFails") { - let input = getFloat32(-0.0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(0.0)_NeverTraps") { - let input = getFloat32(0.0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(0.0)_NeverFails") { - let input = getFloat32(0.0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(0.5)_NeverTraps") { - let input = getFloat32(0.5) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(0.5)_AlwaysFails") { - let input = getFloat32(0.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(127.5)_NeverTraps") { - let input = getFloat32(127.5) - let actual = Int16(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(127.5)_AlwaysFails") { - let input = getFloat32(127.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(255.5)_NeverTraps") { - let input = getFloat32(255.5) - let actual = Int16(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(255.5)_AlwaysFails") { - let input = getFloat32(255.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(32767)_NeverTraps") { - let input = getFloat32(32767) - let actual = Int16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(32767)_NeverFails") { - let input = getFloat32(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(32767.5)_NeverTraps") { - let input = getFloat32(32767.5) - let actual = Int16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(32767.5)_AlwaysFails") { - let input = getFloat32(32767.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(32768)_AlwaysTraps") { - let input = getFloat32(32768) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(32768)_AlwaysFails") { - let input = getFloat32(32768) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(65535.5)_AlwaysTraps") { - let input = getFloat32(65535.5) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(65535.5)_AlwaysFails") { - let input = getFloat32(65535.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(16777215)_AlwaysTraps") { - let input = getFloat32(16777215) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(16777215)_AlwaysFails") { - let input = getFloat32(16777215) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(-.infinity)_AlwaysTraps") { - let input = getFloat32(-.infinity) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(-.infinity)_AlwaysFails") { - let input = getFloat32(-.infinity) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(+.infinity)_AlwaysTraps") { - let input = getFloat32(+.infinity) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(+.infinity)_AlwaysFails") { - let input = getFloat32(+.infinity) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(-.nan)_AlwaysTraps") { - let input = getFloat32(-.nan) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(-.nan)_AlwaysFails") { - let input = getFloat32(-.nan) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(+.nan)_AlwaysTraps") { - let input = getFloat32(+.nan) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(+.nan)_AlwaysFails") { - let input = getFloat32(+.nan) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(-.signalingNaN)_AlwaysTraps") { - let input = getFloat32(-.signalingNaN) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(-.signalingNaN)_AlwaysFails") { - let input = getFloat32(-.signalingNaN) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(+.signalingNaN)_AlwaysTraps") { - let input = getFloat32(+.signalingNaN) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat32(+.signalingNaN)_AlwaysFails") { - let input = getFloat32(+.signalingNaN) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt16 +.test("FromFloat32_NeverTraps") +.forEach(in: [ + (getInt16(-32768), getFloat32(-32768.5)), + (getInt16(-32768), getFloat32(-32768)), + (getInt16(-128), getFloat32(-128.5)), + (getInt16(+0), getFloat32(-0.5)), + (getInt16(+0), getFloat32(+0)), + (getInt16(+0), getFloat32(-0)), + (getInt16(+0), getFloat32(+0.5)), + (getInt16(+127), getFloat32(+127.5)), + (getInt16(+255), getFloat32(+255.5)), + (getInt16(+32767), getFloat32(+32767)), + (getInt16(+32767), getFloat32(+32767.5)), +]) { + expectEqual($0.0, Int16($0.1)) +} + +FixedPointConversion_Release64_ToInt16 +.test("FromFloat32_NeverFails") +.forEach(in: [ + (getInt16(-32768), getFloat32(-32768)), + (getInt16(+0), getFloat32(+0)), + (getInt16(+0), getFloat32(-0)), + (getInt16(+32767), getFloat32(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToInt16 +.test("FromFloat32_AlwaysTraps") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32769), + getFloat32(+32768), + getFloat32(+65535.5), + getFloat32(+16777215), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int16($0)) +} + +FixedPointConversion_Release64_ToInt16 +.test("FromFloat32_AlwaysFails") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32769), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-0.5), + getFloat32(+0.5), + getFloat32(+127.5), + getFloat32(+255.5), + getFloat32(+32767.5), + getFloat32(+32768), + getFloat32(+65535.5), + getFloat32(+16777215), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectNil(Int16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float64: (-9007199254740991)...(9007199254740991) +// MARK: Float64: (-9007199254740991)...(+9007199254740991) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt16.test("FromFloat64(-9007199254740991)_AlwaysTraps") { - let input = getFloat64(-9007199254740991) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(-9007199254740991)_AlwaysFails") { - let input = getFloat64(-9007199254740991) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(-32769)_AlwaysTraps") { - let input = getFloat64(-32769) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(-32769)_AlwaysFails") { - let input = getFloat64(-32769) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(-32768.5)_NeverTraps") { - let input = getFloat64(-32768.5) - let actual = Int16(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(-32768.5)_AlwaysFails") { - let input = getFloat64(-32768.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(-32768)_NeverTraps") { - let input = getFloat64(-32768) - let actual = Int16(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(-32768)_NeverFails") { - let input = getFloat64(-32768) - let actual = Int16(exactly: input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(-128.5)_NeverTraps") { - let input = getFloat64(-128.5) - let actual = Int16(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(-128.5)_AlwaysFails") { - let input = getFloat64(-128.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(-0.5)_NeverTraps") { - let input = getFloat64(-0.5) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(-0.5)_AlwaysFails") { - let input = getFloat64(-0.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(-0.0)_NeverTraps") { - let input = getFloat64(-0.0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(-0.0)_NeverFails") { - let input = getFloat64(-0.0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(0.0)_NeverTraps") { - let input = getFloat64(0.0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(0.0)_NeverFails") { - let input = getFloat64(0.0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(0.5)_NeverTraps") { - let input = getFloat64(0.5) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(0.5)_AlwaysFails") { - let input = getFloat64(0.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(127.5)_NeverTraps") { - let input = getFloat64(127.5) - let actual = Int16(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(127.5)_AlwaysFails") { - let input = getFloat64(127.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(255.5)_NeverTraps") { - let input = getFloat64(255.5) - let actual = Int16(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(255.5)_AlwaysFails") { - let input = getFloat64(255.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(32767)_NeverTraps") { - let input = getFloat64(32767) - let actual = Int16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(32767)_NeverFails") { - let input = getFloat64(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(32767.5)_NeverTraps") { - let input = getFloat64(32767.5) - let actual = Int16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(32767.5)_AlwaysFails") { - let input = getFloat64(32767.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(32768)_AlwaysTraps") { - let input = getFloat64(32768) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(32768)_AlwaysFails") { - let input = getFloat64(32768) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(65535.5)_AlwaysTraps") { - let input = getFloat64(65535.5) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(65535.5)_AlwaysFails") { - let input = getFloat64(65535.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(9007199254740991)_AlwaysTraps") { - let input = getFloat64(9007199254740991) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(9007199254740991)_AlwaysFails") { - let input = getFloat64(9007199254740991) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(-.infinity)_AlwaysTraps") { - let input = getFloat64(-.infinity) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(-.infinity)_AlwaysFails") { - let input = getFloat64(-.infinity) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(+.infinity)_AlwaysTraps") { - let input = getFloat64(+.infinity) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(+.infinity)_AlwaysFails") { - let input = getFloat64(+.infinity) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(-.nan)_AlwaysTraps") { - let input = getFloat64(-.nan) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(-.nan)_AlwaysFails") { - let input = getFloat64(-.nan) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(+.nan)_AlwaysTraps") { - let input = getFloat64(+.nan) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(+.nan)_AlwaysFails") { - let input = getFloat64(+.nan) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(-.signalingNaN)_AlwaysTraps") { - let input = getFloat64(-.signalingNaN) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(-.signalingNaN)_AlwaysFails") { - let input = getFloat64(-.signalingNaN) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(+.signalingNaN)_AlwaysTraps") { - let input = getFloat64(+.signalingNaN) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat64(+.signalingNaN)_AlwaysFails") { - let input = getFloat64(+.signalingNaN) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt16 +.test("FromFloat64_NeverTraps") +.forEach(in: [ + (getInt16(-32768), getFloat64(-32768.5)), + (getInt16(-32768), getFloat64(-32768)), + (getInt16(-128), getFloat64(-128.5)), + (getInt16(+0), getFloat64(-0.5)), + (getInt16(+0), getFloat64(+0)), + (getInt16(+0), getFloat64(-0)), + (getInt16(+0), getFloat64(+0.5)), + (getInt16(+127), getFloat64(+127.5)), + (getInt16(+255), getFloat64(+255.5)), + (getInt16(+32767), getFloat64(+32767)), + (getInt16(+32767), getFloat64(+32767.5)), +]) { + expectEqual($0.0, Int16($0.1)) +} + +FixedPointConversion_Release64_ToInt16 +.test("FromFloat64_NeverFails") +.forEach(in: [ + (getInt16(-32768), getFloat64(-32768)), + (getInt16(+0), getFloat64(+0)), + (getInt16(+0), getFloat64(-0)), + (getInt16(+32767), getFloat64(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToInt16 +.test("FromFloat64_AlwaysTraps") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32769), + getFloat64(+32768), + getFloat64(+65535.5), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int16($0)) +} + +FixedPointConversion_Release64_ToInt16 +.test("FromFloat64_AlwaysFails") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32769), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-0.5), + getFloat64(+0.5), + getFloat64(+127.5), + getFloat64(+255.5), + getFloat64(+32767.5), + getFloat64(+32768), + getFloat64(+65535.5), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectNil(Int16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float80: (-18446744073709551615)...(18446744073709551615) +// MARK: Float80: (-18446744073709551615)...(+18446744073709551615) //===----------------------------------------------------------------------===// #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) -FixedPointConversion_Release64_ToInt16.test("FromFloat80(-18446744073709551615)_AlwaysTraps") { - let input = getFloat80(-18446744073709551615) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(-18446744073709551615)_AlwaysFails") { - let input = getFloat80(-18446744073709551615) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(-32769)_AlwaysTraps") { - let input = getFloat80(-32769) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(-32769)_AlwaysFails") { - let input = getFloat80(-32769) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(-32768.5)_NeverTraps") { - let input = getFloat80(-32768.5) - let actual = Int16(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(-32768.5)_AlwaysFails") { - let input = getFloat80(-32768.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(-32768)_NeverTraps") { - let input = getFloat80(-32768) - let actual = Int16(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(-32768)_NeverFails") { - let input = getFloat80(-32768) - let actual = Int16(exactly: input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(-128.5)_NeverTraps") { - let input = getFloat80(-128.5) - let actual = Int16(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(-128.5)_AlwaysFails") { - let input = getFloat80(-128.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(-0.5)_NeverTraps") { - let input = getFloat80(-0.5) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(-0.5)_AlwaysFails") { - let input = getFloat80(-0.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(-0.0)_NeverTraps") { - let input = getFloat80(-0.0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(-0.0)_NeverFails") { - let input = getFloat80(-0.0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(0.0)_NeverTraps") { - let input = getFloat80(0.0) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(0.0)_NeverFails") { - let input = getFloat80(0.0) - let actual = Int16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(0.5)_NeverTraps") { - let input = getFloat80(0.5) - let actual = Int16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(0.5)_AlwaysFails") { - let input = getFloat80(0.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(127.5)_NeverTraps") { - let input = getFloat80(127.5) - let actual = Int16(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(127.5)_AlwaysFails") { - let input = getFloat80(127.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(255.5)_NeverTraps") { - let input = getFloat80(255.5) - let actual = Int16(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(255.5)_AlwaysFails") { - let input = getFloat80(255.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(32767)_NeverTraps") { - let input = getFloat80(32767) - let actual = Int16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(32767)_NeverFails") { - let input = getFloat80(32767) - let actual = Int16(exactly: input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(32767.5)_NeverTraps") { - let input = getFloat80(32767.5) - let actual = Int16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(32767.5)_AlwaysFails") { - let input = getFloat80(32767.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(32768)_AlwaysTraps") { - let input = getFloat80(32768) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(32768)_AlwaysFails") { - let input = getFloat80(32768) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(65535.5)_AlwaysTraps") { - let input = getFloat80(65535.5) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(65535.5)_AlwaysFails") { - let input = getFloat80(65535.5) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(18446744073709551615)_AlwaysTraps") { - let input = getFloat80(18446744073709551615) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(18446744073709551615)_AlwaysFails") { - let input = getFloat80(18446744073709551615) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(-.infinity)_AlwaysTraps") { - let input = getFloat80(-.infinity) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(-.infinity)_AlwaysFails") { - let input = getFloat80(-.infinity) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(+.infinity)_AlwaysTraps") { - let input = getFloat80(+.infinity) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(+.infinity)_AlwaysFails") { - let input = getFloat80(+.infinity) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(-.nan)_AlwaysTraps") { - let input = getFloat80(-.nan) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(-.nan)_AlwaysFails") { - let input = getFloat80(-.nan) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(+.nan)_AlwaysTraps") { - let input = getFloat80(+.nan) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(+.nan)_AlwaysFails") { - let input = getFloat80(+.nan) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(-.signalingNaN)_AlwaysTraps") { - let input = getFloat80(-.signalingNaN) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(-.signalingNaN)_AlwaysFails") { - let input = getFloat80(-.signalingNaN) - let actual = Int16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(+.signalingNaN)_AlwaysTraps") { - let input = getFloat80(+.signalingNaN) - expectCrash { - let actual = Int16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt16.test("FromFloat80(+.signalingNaN)_AlwaysFails") { - let input = getFloat80(+.signalingNaN) - let actual = Int16(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt16 +.test("FromFloat80_NeverTraps") +.forEach(in: [ + (getInt16(-32768), getFloat80(-32768.5)), + (getInt16(-32768), getFloat80(-32768)), + (getInt16(-128), getFloat80(-128.5)), + (getInt16(+0), getFloat80(-0.5)), + (getInt16(+0), getFloat80(+0)), + (getInt16(+0), getFloat80(-0)), + (getInt16(+0), getFloat80(+0.5)), + (getInt16(+127), getFloat80(+127.5)), + (getInt16(+255), getFloat80(+255.5)), + (getInt16(+32767), getFloat80(+32767)), + (getInt16(+32767), getFloat80(+32767.5)), +]) { + expectEqual($0.0, Int16($0.1)) +} + +FixedPointConversion_Release64_ToInt16 +.test("FromFloat80_NeverFails") +.forEach(in: [ + (getInt16(-32768), getFloat80(-32768)), + (getInt16(+0), getFloat80(+0)), + (getInt16(+0), getFloat80(-0)), + (getInt16(+32767), getFloat80(+32767)), +]) { + expectEqual($0.0, Int16(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToInt16 +.test("FromFloat80_AlwaysTraps") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32769), + getFloat80(+32768), + getFloat80(+65535.5), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int16($0)) +} + +FixedPointConversion_Release64_ToInt16 +.test("FromFloat80_AlwaysFails") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32769), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-0.5), + getFloat80(+0.5), + getFloat80(+127.5), + getFloat80(+255.5), + getFloat80(+32767.5), + getFloat80(+32768), + getFloat80(+65535.5), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectNil(Int16(exactly: $0)) } #endif // Float80 diff --git a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release64_ToInt32.swift b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release64_ToInt32.swift index b4b29fe5e7e52..1bceee1db5f83 100644 --- a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release64_ToInt32.swift +++ b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release64_ToInt32.swift @@ -14,1554 +14,635 @@ import StdlibUnittest -let FixedPointConversion_Release64_ToInt32 = TestSuite("FixedPointConversion_Release64_ToInt32") +let FixedPointConversion_Release64_ToInt32 = TestSuite( + "FixedPointConversion_Release64_ToInt32" +) //===----------------------------------------------------------------------===// -// MARK: UInt8: (0)...(255) +// MARK: UInt8: (+0)...(+255) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt32.test("FromUInt8(0)_NeverTraps") { - let input = getUInt8(0) - let actual = Int32(input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToInt32 +.test("FromUInt8_NeverTraps") +.forEach(in: [ + (getInt32(+0), getUInt8(+0)), + (getInt32(+255), getUInt8(+255)), +]) { + expectEqual($0.0, Int32($0.1)) } -FixedPointConversion_Release64_ToInt32.test("FromUInt8(0)_NeverFails") { - let input = getUInt8(0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromUInt8(255)_NeverTraps") { - let input = getUInt8(255) - let actual = Int32(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromUInt8(255)_NeverFails") { - let input = getUInt8(255) - let actual = Int32(exactly: input) - expectEqual(255, actual) +FixedPointConversion_Release64_ToInt32 +.test("FromUInt8_NeverFails") +.forEach(in: [ + (getInt32(+0), getUInt8(+0)), + (getInt32(+255), getUInt8(+255)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int8: (-128)...(127) +// MARK: Int8: (-128)...(+127) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt32.test("FromInt8(-128)_NeverTraps") { - let input = getInt8(-128) - let actual = Int32(input) - expectEqual(-128, actual) +FixedPointConversion_Release64_ToInt32 +.test("FromInt8_NeverTraps") +.forEach(in: [ + (getInt32(-128), getInt8(-128)), + (getInt32(+0), getInt8(+0)), + (getInt32(+127), getInt8(+127)), +]) { + expectEqual($0.0, Int32($0.1)) } -FixedPointConversion_Release64_ToInt32.test("FromInt8(-128)_NeverFails") { - let input = getInt8(-128) - let actual = Int32(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromInt8(0)_NeverTraps") { - let input = getInt8(0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromInt8(0)_NeverFails") { - let input = getInt8(0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromInt8(127)_NeverTraps") { - let input = getInt8(127) - let actual = Int32(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromInt8(127)_NeverFails") { - let input = getInt8(127) - let actual = Int32(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Release64_ToInt32 +.test("FromInt8_NeverFails") +.forEach(in: [ + (getInt32(-128), getInt8(-128)), + (getInt32(+0), getInt8(+0)), + (getInt32(+127), getInt8(+127)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt16: (0)...(65535) +// MARK: UInt16: (+0)...(+65535) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt32.test("FromUInt16(0)_NeverTraps") { - let input = getUInt16(0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromUInt16(0)_NeverFails") { - let input = getUInt16(0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromUInt16(65535)_NeverTraps") { - let input = getUInt16(65535) - let actual = Int32(input) - expectEqual(65535, actual) +FixedPointConversion_Release64_ToInt32 +.test("FromUInt16_NeverTraps") +.forEach(in: [ + (getInt32(+0), getUInt16(+0)), + (getInt32(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, Int32($0.1)) } -FixedPointConversion_Release64_ToInt32.test("FromUInt16(65535)_NeverFails") { - let input = getUInt16(65535) - let actual = Int32(exactly: input) - expectEqual(65535, actual) +FixedPointConversion_Release64_ToInt32 +.test("FromUInt16_NeverFails") +.forEach(in: [ + (getInt32(+0), getUInt16(+0)), + (getInt32(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int16: (-32768)...(32767) +// MARK: Int16: (-32768)...(+32767) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt32.test("FromInt16(-32768)_NeverTraps") { - let input = getInt16(-32768) - let actual = Int32(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromInt16(-32768)_NeverFails") { - let input = getInt16(-32768) - let actual = Int32(exactly: input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromInt16(0)_NeverTraps") { - let input = getInt16(0) - let actual = Int32(input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToInt32 +.test("FromInt16_NeverTraps") +.forEach(in: [ + (getInt32(-32768), getInt16(-32768)), + (getInt32(+0), getInt16(+0)), + (getInt32(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, Int32($0.1)) } -FixedPointConversion_Release64_ToInt32.test("FromInt16(0)_NeverFails") { - let input = getInt16(0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromInt16(32767)_NeverTraps") { - let input = getInt16(32767) - let actual = Int32(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromInt16(32767)_NeverFails") { - let input = getInt16(32767) - let actual = Int32(exactly: input) - expectEqual(32767, actual) +FixedPointConversion_Release64_ToInt32 +.test("FromInt16_NeverFails") +.forEach(in: [ + (getInt32(-32768), getInt16(-32768)), + (getInt32(+0), getInt16(+0)), + (getInt32(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt32: (0)...(4294967295) +// MARK: UInt32: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt32.test("FromUInt32(0)_NeverTraps") { - let input = getUInt32(0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromUInt32(0)_NeverFails") { - let input = getUInt32(0) - let actual = Int32(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToInt32 +.test("FromUInt32_NeverTraps") +.forEach(in: [ + (getInt32(+0), getUInt32(+0)), + (getInt32(+2147483647), getUInt32(+2147483647)), +]) { + expectEqual($0.0, Int32($0.1)) } -FixedPointConversion_Release64_ToInt32.test("FromUInt32(2147483647)_NeverTraps") { - let input = getUInt32(2147483647) - let actual = Int32(input) - expectEqual(2147483647, actual) +FixedPointConversion_Release64_ToInt32 +.test("FromUInt32_NeverFails") +.forEach(in: [ + (getInt32(+0), getUInt32(+0)), + (getInt32(+2147483647), getUInt32(+2147483647)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) } -FixedPointConversion_Release64_ToInt32.test("FromUInt32(2147483647)_NeverFails") { - let input = getUInt32(2147483647) - let actual = Int32(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Release64_ToInt32 +.test("FromUInt32_AlwaysTraps") +.forEach(in: [ + getUInt32(+2147483648), + getUInt32(+4294967295), +]) { + expectCrashLater() + _blackHole(Int32($0)) } -FixedPointConversion_Release64_ToInt32.test("FromUInt32(2147483648)_AlwaysTraps") { - let input = getUInt32(2147483648) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromUInt32(2147483648)_AlwaysFails") { - let input = getUInt32(2147483648) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromUInt32(4294967295)_AlwaysTraps") { - let input = getUInt32(4294967295) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromUInt32(4294967295)_AlwaysFails") { - let input = getUInt32(4294967295) - let actual = Int32(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt32 +.test("FromUInt32_AlwaysFails") +.forEach(in: [ + getUInt32(+2147483648), + getUInt32(+4294967295), +]) { + expectNil(Int32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int32: (-2147483648)...(2147483647) +// MARK: Int32: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt32.test("FromInt32(-2147483648)_NeverTraps") { - let input = getInt32(-2147483648) - let actual = Int32(input) - expectEqual(-2147483648, actual) +FixedPointConversion_Release64_ToInt32 +.test("FromInt32_NeverTraps") +.forEach(in: [ + (getInt32(-2147483648), getInt32(-2147483648)), + (getInt32(+0), getInt32(+0)), + (getInt32(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, Int32($0.1)) } -FixedPointConversion_Release64_ToInt32.test("FromInt32(-2147483648)_NeverFails") { - let input = getInt32(-2147483648) - let actual = Int32(exactly: input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromInt32(0)_NeverTraps") { - let input = getInt32(0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromInt32(0)_NeverFails") { - let input = getInt32(0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromInt32(2147483647)_NeverTraps") { - let input = getInt32(2147483647) - let actual = Int32(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromInt32(2147483647)_NeverFails") { - let input = getInt32(2147483647) - let actual = Int32(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Release64_ToInt32 +.test("FromInt32_NeverFails") +.forEach(in: [ + (getInt32(-2147483648), getInt32(-2147483648)), + (getInt32(+0), getInt32(+0)), + (getInt32(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt64: (0)...(18446744073709551615) +// MARK: UInt64: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt32.test("FromUInt64(0)_NeverTraps") { - let input = getUInt64(0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromUInt64(0)_NeverFails") { - let input = getUInt64(0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromUInt64(2147483647)_NeverTraps") { - let input = getUInt64(2147483647) - let actual = Int32(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromUInt64(2147483647)_NeverFails") { - let input = getUInt64(2147483647) - let actual = Int32(exactly: input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromUInt64(2147483648)_AlwaysTraps") { - let input = getUInt64(2147483648) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } +FixedPointConversion_Release64_ToInt32 +.test("FromUInt64_NeverTraps") +.forEach(in: [ + (getInt32(+0), getUInt64(+0)), + (getInt32(+2147483647), getUInt64(+2147483647)), +]) { + expectEqual($0.0, Int32($0.1)) } -FixedPointConversion_Release64_ToInt32.test("FromUInt64(2147483648)_AlwaysFails") { - let input = getUInt64(2147483648) - let actual = Int32(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt32 +.test("FromUInt64_NeverFails") +.forEach(in: [ + (getInt32(+0), getUInt64(+0)), + (getInt32(+2147483647), getUInt64(+2147483647)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) } -FixedPointConversion_Release64_ToInt32.test("FromUInt64(18446744073709551615)_AlwaysTraps") { - let input = getUInt64(18446744073709551615) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } +FixedPointConversion_Release64_ToInt32 +.test("FromUInt64_AlwaysTraps") +.forEach(in: [ + getUInt64(+2147483648), + getUInt64(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(Int32($0)) } -FixedPointConversion_Release64_ToInt32.test("FromUInt64(18446744073709551615)_AlwaysFails") { - let input = getUInt64(18446744073709551615) - let actual = Int32(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt32 +.test("FromUInt64_AlwaysFails") +.forEach(in: [ + getUInt64(+2147483648), + getUInt64(+18446744073709551615), +]) { + expectNil(Int32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int64: (-9223372036854775808)...(9223372036854775807) +// MARK: Int64: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt32.test("FromInt64(-9223372036854775808)_AlwaysTraps") { - let input = getInt64(-9223372036854775808) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromInt64(-9223372036854775808)_AlwaysFails") { - let input = getInt64(-9223372036854775808) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromInt64(-2147483649)_AlwaysTraps") { - let input = getInt64(-2147483649) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromInt64(-2147483649)_AlwaysFails") { - let input = getInt64(-2147483649) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromInt64(-2147483648)_NeverTraps") { - let input = getInt64(-2147483648) - let actual = Int32(input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromInt64(-2147483648)_NeverFails") { - let input = getInt64(-2147483648) - let actual = Int32(exactly: input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromInt64(0)_NeverTraps") { - let input = getInt64(0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromInt64(0)_NeverFails") { - let input = getInt64(0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromInt64(2147483647)_NeverTraps") { - let input = getInt64(2147483647) - let actual = Int32(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromInt64(2147483647)_NeverFails") { - let input = getInt64(2147483647) - let actual = Int32(exactly: input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromInt64(2147483648)_AlwaysTraps") { - let input = getInt64(2147483648) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromInt64(2147483648)_AlwaysFails") { - let input = getInt64(2147483648) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromInt64(9223372036854775807)_AlwaysTraps") { - let input = getInt64(9223372036854775807) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromInt64(9223372036854775807)_AlwaysFails") { - let input = getInt64(9223372036854775807) - let actual = Int32(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt32 +.test("FromInt64_NeverTraps") +.forEach(in: [ + (getInt32(-2147483648), getInt64(-2147483648)), + (getInt32(+0), getInt64(+0)), + (getInt32(+2147483647), getInt64(+2147483647)), +]) { + expectEqual($0.0, Int32($0.1)) +} + +FixedPointConversion_Release64_ToInt32 +.test("FromInt64_NeverFails") +.forEach(in: [ + (getInt32(-2147483648), getInt64(-2147483648)), + (getInt32(+0), getInt64(+0)), + (getInt32(+2147483647), getInt64(+2147483647)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToInt32 +.test("FromInt64_AlwaysTraps") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-2147483649), + getInt64(+2147483648), + getInt64(+9223372036854775807), +]) { + expectCrashLater() + _blackHole(Int32($0)) +} + +FixedPointConversion_Release64_ToInt32 +.test("FromInt64_AlwaysFails") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-2147483649), + getInt64(+2147483648), + getInt64(+9223372036854775807), +]) { + expectNil(Int32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt: (0)...(18446744073709551615) +// MARK: UInt: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt32.test("FromUInt(0)_NeverTraps") { - let input = getUInt(0) - let actual = Int32(input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToInt32 +.test("FromUInt_NeverTraps") +.forEach(in: [ + (getInt32(+0), getUInt(+0)), + (getInt32(+2147483647), getUInt(+2147483647)), +]) { + expectEqual($0.0, Int32($0.1)) } -FixedPointConversion_Release64_ToInt32.test("FromUInt(0)_NeverFails") { - let input = getUInt(0) - let actual = Int32(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToInt32 +.test("FromUInt_NeverFails") +.forEach(in: [ + (getInt32(+0), getUInt(+0)), + (getInt32(+2147483647), getUInt(+2147483647)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) } -FixedPointConversion_Release64_ToInt32.test("FromUInt(2147483647)_NeverTraps") { - let input = getUInt(2147483647) - let actual = Int32(input) - expectEqual(2147483647, actual) +FixedPointConversion_Release64_ToInt32 +.test("FromUInt_AlwaysTraps") +.forEach(in: [ + getUInt(+2147483648), + getUInt(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(Int32($0)) } -FixedPointConversion_Release64_ToInt32.test("FromUInt(2147483647)_NeverFails") { - let input = getUInt(2147483647) - let actual = Int32(exactly: input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromUInt(2147483648)_AlwaysTraps") { - let input = getUInt(2147483648) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromUInt(2147483648)_AlwaysFails") { - let input = getUInt(2147483648) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromUInt(18446744073709551615)_AlwaysTraps") { - let input = getUInt(18446744073709551615) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromUInt(18446744073709551615)_AlwaysFails") { - let input = getUInt(18446744073709551615) - let actual = Int32(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt32 +.test("FromUInt_AlwaysFails") +.forEach(in: [ + getUInt(+2147483648), + getUInt(+18446744073709551615), +]) { + expectNil(Int32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int: (-9223372036854775808)...(9223372036854775807) +// MARK: Int: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt32.test("FromInt(-9223372036854775808)_AlwaysTraps") { - let input = getInt(-9223372036854775808) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromInt(-9223372036854775808)_AlwaysFails") { - let input = getInt(-9223372036854775808) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromInt(-2147483649)_AlwaysTraps") { - let input = getInt(-2147483649) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromInt(-2147483649)_AlwaysFails") { - let input = getInt(-2147483649) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromInt(-2147483648)_NeverTraps") { - let input = getInt(-2147483648) - let actual = Int32(input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromInt(-2147483648)_NeverFails") { - let input = getInt(-2147483648) - let actual = Int32(exactly: input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromInt(0)_NeverTraps") { - let input = getInt(0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromInt(0)_NeverFails") { - let input = getInt(0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromInt(2147483647)_NeverTraps") { - let input = getInt(2147483647) - let actual = Int32(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromInt(2147483647)_NeverFails") { - let input = getInt(2147483647) - let actual = Int32(exactly: input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromInt(2147483648)_AlwaysTraps") { - let input = getInt(2147483648) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromInt(2147483648)_AlwaysFails") { - let input = getInt(2147483648) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromInt(9223372036854775807)_AlwaysTraps") { - let input = getInt(9223372036854775807) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromInt(9223372036854775807)_AlwaysFails") { - let input = getInt(9223372036854775807) - let actual = Int32(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt32 +.test("FromInt_NeverTraps") +.forEach(in: [ + (getInt32(-2147483648), getInt(-2147483648)), + (getInt32(+0), getInt(+0)), + (getInt32(+2147483647), getInt(+2147483647)), +]) { + expectEqual($0.0, Int32($0.1)) +} + +FixedPointConversion_Release64_ToInt32 +.test("FromInt_NeverFails") +.forEach(in: [ + (getInt32(-2147483648), getInt(-2147483648)), + (getInt32(+0), getInt(+0)), + (getInt32(+2147483647), getInt(+2147483647)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToInt32 +.test("FromInt_AlwaysTraps") +.forEach(in: [ + getInt(-9223372036854775808), + getInt(-2147483649), + getInt(+2147483648), + getInt(+9223372036854775807), +]) { + expectCrashLater() + _blackHole(Int32($0)) +} + +FixedPointConversion_Release64_ToInt32 +.test("FromInt_AlwaysFails") +.forEach(in: [ + getInt(-9223372036854775808), + getInt(-2147483649), + getInt(+2147483648), + getInt(+9223372036854775807), +]) { + expectNil(Int32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float16: (-2047)...(2047) +// MARK: Float16: (-2047)...(+2047) //===----------------------------------------------------------------------===// #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -FixedPointConversion_Release64_ToInt32.test("FromFloat16(-2047)_NeverTraps") { - let input = getFloat16(-2047) - let actual = Int32(input) - expectEqual(-2047, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat16(-2047)_NeverFails") { - let input = getFloat16(-2047) - let actual = Int32(exactly: input) - expectEqual(-2047, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat16(-128.5)_NeverTraps") { - let input = getFloat16(-128.5) - let actual = Int32(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat16(-128.5)_AlwaysFails") { - let input = getFloat16(-128.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat16(-0.5)_NeverTraps") { - let input = getFloat16(-0.5) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat16(-0.5)_AlwaysFails") { - let input = getFloat16(-0.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat16(-0.0)_NeverTraps") { - let input = getFloat16(-0.0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat16(-0.0)_NeverFails") { - let input = getFloat16(-0.0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat16(0.0)_NeverTraps") { - let input = getFloat16(0.0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat16(0.0)_NeverFails") { - let input = getFloat16(0.0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat16(0.5)_NeverTraps") { - let input = getFloat16(0.5) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat16(0.5)_AlwaysFails") { - let input = getFloat16(0.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat16(127.5)_NeverTraps") { - let input = getFloat16(127.5) - let actual = Int32(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat16(127.5)_AlwaysFails") { - let input = getFloat16(127.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat16(255.5)_NeverTraps") { - let input = getFloat16(255.5) - let actual = Int32(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat16(255.5)_AlwaysFails") { - let input = getFloat16(255.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat16(2047)_NeverTraps") { - let input = getFloat16(2047) - let actual = Int32(input) - expectEqual(2047, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat16(2047)_NeverFails") { - let input = getFloat16(2047) - let actual = Int32(exactly: input) - expectEqual(2047, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat16(-.infinity)_AlwaysTraps") { - let input = getFloat16(-.infinity) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat16(-.infinity)_AlwaysFails") { - let input = getFloat16(-.infinity) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat16(+.infinity)_AlwaysTraps") { - let input = getFloat16(+.infinity) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat16(+.infinity)_AlwaysFails") { - let input = getFloat16(+.infinity) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat16(-.nan)_AlwaysTraps") { - let input = getFloat16(-.nan) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat16(-.nan)_AlwaysFails") { - let input = getFloat16(-.nan) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat16(+.nan)_AlwaysTraps") { - let input = getFloat16(+.nan) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat16(+.nan)_AlwaysFails") { - let input = getFloat16(+.nan) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat16(-.signalingNaN)_AlwaysTraps") { - let input = getFloat16(-.signalingNaN) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat16(-.signalingNaN)_AlwaysFails") { - let input = getFloat16(-.signalingNaN) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat16(+.signalingNaN)_AlwaysTraps") { - let input = getFloat16(+.signalingNaN) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat16(+.signalingNaN)_AlwaysFails") { - let input = getFloat16(+.signalingNaN) - let actual = Int32(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt32 +.test("FromFloat16_NeverTraps") +.forEach(in: [ + (getInt32(-2047), getFloat16(-2047)), + (getInt32(-128), getFloat16(-128.5)), + (getInt32(+0), getFloat16(-0.5)), + (getInt32(+0), getFloat16(+0)), + (getInt32(+0), getFloat16(-0)), + (getInt32(+0), getFloat16(+0.5)), + (getInt32(+127), getFloat16(+127.5)), + (getInt32(+255), getFloat16(+255.5)), + (getInt32(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, Int32($0.1)) +} + +FixedPointConversion_Release64_ToInt32 +.test("FromFloat16_NeverFails") +.forEach(in: [ + (getInt32(-2047), getFloat16(-2047)), + (getInt32(+0), getFloat16(+0)), + (getInt32(+0), getFloat16(-0)), + (getInt32(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToInt32 +.test("FromFloat16_AlwaysTraps") +.forEach(in: [ + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int32($0)) +} + +FixedPointConversion_Release64_ToInt32 +.test("FromFloat16_AlwaysFails") +.forEach(in: [ + getFloat16(-128.5), + getFloat16(-0.5), + getFloat16(+0.5), + getFloat16(+127.5), + getFloat16(+255.5), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectNil(Int32(exactly: $0)) } } #endif // Float16 //===----------------------------------------------------------------------===// -// MARK: Float32: (-16777215)...(16777215) +// MARK: Float32: (-16777215)...(+16777215) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt32.test("FromFloat32(-16777215)_NeverTraps") { - let input = getFloat32(-16777215) - let actual = Int32(input) - expectEqual(-16777215, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat32(-16777215)_NeverFails") { - let input = getFloat32(-16777215) - let actual = Int32(exactly: input) - expectEqual(-16777215, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat32(-32768.5)_NeverTraps") { - let input = getFloat32(-32768.5) - let actual = Int32(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat32(-32768.5)_AlwaysFails") { - let input = getFloat32(-32768.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat32(-128.5)_NeverTraps") { - let input = getFloat32(-128.5) - let actual = Int32(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat32(-128.5)_AlwaysFails") { - let input = getFloat32(-128.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat32(-0.5)_NeverTraps") { - let input = getFloat32(-0.5) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat32(-0.5)_AlwaysFails") { - let input = getFloat32(-0.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat32(-0.0)_NeverTraps") { - let input = getFloat32(-0.0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat32(-0.0)_NeverFails") { - let input = getFloat32(-0.0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat32(0.0)_NeverTraps") { - let input = getFloat32(0.0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat32(0.0)_NeverFails") { - let input = getFloat32(0.0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat32(0.5)_NeverTraps") { - let input = getFloat32(0.5) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat32(0.5)_AlwaysFails") { - let input = getFloat32(0.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat32(127.5)_NeverTraps") { - let input = getFloat32(127.5) - let actual = Int32(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat32(127.5)_AlwaysFails") { - let input = getFloat32(127.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat32(255.5)_NeverTraps") { - let input = getFloat32(255.5) - let actual = Int32(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat32(255.5)_AlwaysFails") { - let input = getFloat32(255.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat32(32767.5)_NeverTraps") { - let input = getFloat32(32767.5) - let actual = Int32(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat32(32767.5)_AlwaysFails") { - let input = getFloat32(32767.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat32(65535.5)_NeverTraps") { - let input = getFloat32(65535.5) - let actual = Int32(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat32(65535.5)_AlwaysFails") { - let input = getFloat32(65535.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat32(16777215)_NeverTraps") { - let input = getFloat32(16777215) - let actual = Int32(input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat32(16777215)_NeverFails") { - let input = getFloat32(16777215) - let actual = Int32(exactly: input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat32(-.infinity)_AlwaysTraps") { - let input = getFloat32(-.infinity) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat32(-.infinity)_AlwaysFails") { - let input = getFloat32(-.infinity) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat32(+.infinity)_AlwaysTraps") { - let input = getFloat32(+.infinity) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat32(+.infinity)_AlwaysFails") { - let input = getFloat32(+.infinity) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat32(-.nan)_AlwaysTraps") { - let input = getFloat32(-.nan) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat32(-.nan)_AlwaysFails") { - let input = getFloat32(-.nan) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat32(+.nan)_AlwaysTraps") { - let input = getFloat32(+.nan) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat32(+.nan)_AlwaysFails") { - let input = getFloat32(+.nan) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat32(-.signalingNaN)_AlwaysTraps") { - let input = getFloat32(-.signalingNaN) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat32(-.signalingNaN)_AlwaysFails") { - let input = getFloat32(-.signalingNaN) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat32(+.signalingNaN)_AlwaysTraps") { - let input = getFloat32(+.signalingNaN) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat32(+.signalingNaN)_AlwaysFails") { - let input = getFloat32(+.signalingNaN) - let actual = Int32(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt32 +.test("FromFloat32_NeverTraps") +.forEach(in: [ + (getInt32(-16777215), getFloat32(-16777215)), + (getInt32(-32768), getFloat32(-32768.5)), + (getInt32(-128), getFloat32(-128.5)), + (getInt32(+0), getFloat32(-0.5)), + (getInt32(+0), getFloat32(+0)), + (getInt32(+0), getFloat32(-0)), + (getInt32(+0), getFloat32(+0.5)), + (getInt32(+127), getFloat32(+127.5)), + (getInt32(+255), getFloat32(+255.5)), + (getInt32(+32767), getFloat32(+32767.5)), + (getInt32(+65535), getFloat32(+65535.5)), + (getInt32(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, Int32($0.1)) +} + +FixedPointConversion_Release64_ToInt32 +.test("FromFloat32_NeverFails") +.forEach(in: [ + (getInt32(-16777215), getFloat32(-16777215)), + (getInt32(+0), getFloat32(+0)), + (getInt32(+0), getFloat32(-0)), + (getInt32(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToInt32 +.test("FromFloat32_AlwaysTraps") +.forEach(in: [ + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int32($0)) +} + +FixedPointConversion_Release64_ToInt32 +.test("FromFloat32_AlwaysFails") +.forEach(in: [ + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-0.5), + getFloat32(+0.5), + getFloat32(+127.5), + getFloat32(+255.5), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectNil(Int32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float64: (-9007199254740991)...(9007199254740991) +// MARK: Float64: (-9007199254740991)...(+9007199254740991) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt32.test("FromFloat64(-9007199254740991)_AlwaysTraps") { - let input = getFloat64(-9007199254740991) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(-9007199254740991)_AlwaysFails") { - let input = getFloat64(-9007199254740991) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(-2147483649)_AlwaysTraps") { - let input = getFloat64(-2147483649) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(-2147483649)_AlwaysFails") { - let input = getFloat64(-2147483649) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(-2147483648)_NeverTraps") { - let input = getFloat64(-2147483648) - let actual = Int32(input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(-2147483648)_NeverFails") { - let input = getFloat64(-2147483648) - let actual = Int32(exactly: input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(-32768.5)_NeverTraps") { - let input = getFloat64(-32768.5) - let actual = Int32(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(-32768.5)_AlwaysFails") { - let input = getFloat64(-32768.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(-128.5)_NeverTraps") { - let input = getFloat64(-128.5) - let actual = Int32(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(-128.5)_AlwaysFails") { - let input = getFloat64(-128.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(-0.5)_NeverTraps") { - let input = getFloat64(-0.5) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(-0.5)_AlwaysFails") { - let input = getFloat64(-0.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(-0.0)_NeverTraps") { - let input = getFloat64(-0.0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(-0.0)_NeverFails") { - let input = getFloat64(-0.0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(0.0)_NeverTraps") { - let input = getFloat64(0.0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(0.0)_NeverFails") { - let input = getFloat64(0.0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(0.5)_NeverTraps") { - let input = getFloat64(0.5) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(0.5)_AlwaysFails") { - let input = getFloat64(0.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(127.5)_NeverTraps") { - let input = getFloat64(127.5) - let actual = Int32(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(127.5)_AlwaysFails") { - let input = getFloat64(127.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(255.5)_NeverTraps") { - let input = getFloat64(255.5) - let actual = Int32(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(255.5)_AlwaysFails") { - let input = getFloat64(255.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(32767.5)_NeverTraps") { - let input = getFloat64(32767.5) - let actual = Int32(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(32767.5)_AlwaysFails") { - let input = getFloat64(32767.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(65535.5)_NeverTraps") { - let input = getFloat64(65535.5) - let actual = Int32(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(65535.5)_AlwaysFails") { - let input = getFloat64(65535.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(2147483647)_NeverTraps") { - let input = getFloat64(2147483647) - let actual = Int32(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(2147483647)_NeverFails") { - let input = getFloat64(2147483647) - let actual = Int32(exactly: input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(2147483648)_AlwaysTraps") { - let input = getFloat64(2147483648) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(2147483648)_AlwaysFails") { - let input = getFloat64(2147483648) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(9007199254740991)_AlwaysTraps") { - let input = getFloat64(9007199254740991) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(9007199254740991)_AlwaysFails") { - let input = getFloat64(9007199254740991) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(-.infinity)_AlwaysTraps") { - let input = getFloat64(-.infinity) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(-.infinity)_AlwaysFails") { - let input = getFloat64(-.infinity) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(+.infinity)_AlwaysTraps") { - let input = getFloat64(+.infinity) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(+.infinity)_AlwaysFails") { - let input = getFloat64(+.infinity) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(-.nan)_AlwaysTraps") { - let input = getFloat64(-.nan) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(-.nan)_AlwaysFails") { - let input = getFloat64(-.nan) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(+.nan)_AlwaysTraps") { - let input = getFloat64(+.nan) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(+.nan)_AlwaysFails") { - let input = getFloat64(+.nan) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(-.signalingNaN)_AlwaysTraps") { - let input = getFloat64(-.signalingNaN) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(-.signalingNaN)_AlwaysFails") { - let input = getFloat64(-.signalingNaN) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(+.signalingNaN)_AlwaysTraps") { - let input = getFloat64(+.signalingNaN) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat64(+.signalingNaN)_AlwaysFails") { - let input = getFloat64(+.signalingNaN) - let actual = Int32(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt32 +.test("FromFloat64_NeverTraps") +.forEach(in: [ + (getInt32(-2147483648), getFloat64(-2147483648)), + (getInt32(-32768), getFloat64(-32768.5)), + (getInt32(-128), getFloat64(-128.5)), + (getInt32(+0), getFloat64(-0.5)), + (getInt32(+0), getFloat64(-0)), + (getInt32(+0), getFloat64(+0)), + (getInt32(+0), getFloat64(+0.5)), + (getInt32(+127), getFloat64(+127.5)), + (getInt32(+255), getFloat64(+255.5)), + (getInt32(+32767), getFloat64(+32767.5)), + (getInt32(+65535), getFloat64(+65535.5)), + (getInt32(+2147483647), getFloat64(+2147483647)), +]) { + expectEqual($0.0, Int32($0.1)) +} + +FixedPointConversion_Release64_ToInt32 +.test("FromFloat64_NeverFails") +.forEach(in: [ + (getInt32(-2147483648), getFloat64(-2147483648)), + (getInt32(+0), getFloat64(-0)), + (getInt32(+0), getFloat64(+0)), + (getInt32(+2147483647), getFloat64(+2147483647)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToInt32 +.test("FromFloat64_AlwaysTraps") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-2147483649), + getFloat64(+2147483648), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int32($0)) +} + +FixedPointConversion_Release64_ToInt32 +.test("FromFloat64_AlwaysFails") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-2147483649), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-0.5), + getFloat64(+0.5), + getFloat64(+127.5), + getFloat64(+255.5), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(+2147483648), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectNil(Int32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float80: (-18446744073709551615)...(18446744073709551615) +// MARK: Float80: (-18446744073709551615)...(+18446744073709551615) //===----------------------------------------------------------------------===// #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) -FixedPointConversion_Release64_ToInt32.test("FromFloat80(-18446744073709551615)_AlwaysTraps") { - let input = getFloat80(-18446744073709551615) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(-18446744073709551615)_AlwaysFails") { - let input = getFloat80(-18446744073709551615) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(-2147483649)_AlwaysTraps") { - let input = getFloat80(-2147483649) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(-2147483649)_AlwaysFails") { - let input = getFloat80(-2147483649) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(-2147483648)_NeverTraps") { - let input = getFloat80(-2147483648) - let actual = Int32(input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(-2147483648)_NeverFails") { - let input = getFloat80(-2147483648) - let actual = Int32(exactly: input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(-32768.5)_NeverTraps") { - let input = getFloat80(-32768.5) - let actual = Int32(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(-32768.5)_AlwaysFails") { - let input = getFloat80(-32768.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(-128.5)_NeverTraps") { - let input = getFloat80(-128.5) - let actual = Int32(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(-128.5)_AlwaysFails") { - let input = getFloat80(-128.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(-0.5)_NeverTraps") { - let input = getFloat80(-0.5) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(-0.5)_AlwaysFails") { - let input = getFloat80(-0.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(-0.0)_NeverTraps") { - let input = getFloat80(-0.0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(-0.0)_NeverFails") { - let input = getFloat80(-0.0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(0.0)_NeverTraps") { - let input = getFloat80(0.0) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(0.0)_NeverFails") { - let input = getFloat80(0.0) - let actual = Int32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(0.5)_NeverTraps") { - let input = getFloat80(0.5) - let actual = Int32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(0.5)_AlwaysFails") { - let input = getFloat80(0.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(127.5)_NeverTraps") { - let input = getFloat80(127.5) - let actual = Int32(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(127.5)_AlwaysFails") { - let input = getFloat80(127.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(255.5)_NeverTraps") { - let input = getFloat80(255.5) - let actual = Int32(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(255.5)_AlwaysFails") { - let input = getFloat80(255.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(32767.5)_NeverTraps") { - let input = getFloat80(32767.5) - let actual = Int32(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(32767.5)_AlwaysFails") { - let input = getFloat80(32767.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(65535.5)_NeverTraps") { - let input = getFloat80(65535.5) - let actual = Int32(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(65535.5)_AlwaysFails") { - let input = getFloat80(65535.5) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(2147483647)_NeverTraps") { - let input = getFloat80(2147483647) - let actual = Int32(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(2147483647)_NeverFails") { - let input = getFloat80(2147483647) - let actual = Int32(exactly: input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(2147483648)_AlwaysTraps") { - let input = getFloat80(2147483648) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(2147483648)_AlwaysFails") { - let input = getFloat80(2147483648) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(18446744073709551615)_AlwaysTraps") { - let input = getFloat80(18446744073709551615) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(18446744073709551615)_AlwaysFails") { - let input = getFloat80(18446744073709551615) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(-.infinity)_AlwaysTraps") { - let input = getFloat80(-.infinity) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(-.infinity)_AlwaysFails") { - let input = getFloat80(-.infinity) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(+.infinity)_AlwaysTraps") { - let input = getFloat80(+.infinity) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(+.infinity)_AlwaysFails") { - let input = getFloat80(+.infinity) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(-.nan)_AlwaysTraps") { - let input = getFloat80(-.nan) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(-.nan)_AlwaysFails") { - let input = getFloat80(-.nan) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(+.nan)_AlwaysTraps") { - let input = getFloat80(+.nan) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(+.nan)_AlwaysFails") { - let input = getFloat80(+.nan) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(-.signalingNaN)_AlwaysTraps") { - let input = getFloat80(-.signalingNaN) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(-.signalingNaN)_AlwaysFails") { - let input = getFloat80(-.signalingNaN) - let actual = Int32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(+.signalingNaN)_AlwaysTraps") { - let input = getFloat80(+.signalingNaN) - expectCrash { - let actual = Int32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt32.test("FromFloat80(+.signalingNaN)_AlwaysFails") { - let input = getFloat80(+.signalingNaN) - let actual = Int32(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt32 +.test("FromFloat80_NeverTraps") +.forEach(in: [ + (getInt32(-2147483648), getFloat80(-2147483648)), + (getInt32(-32768), getFloat80(-32768.5)), + (getInt32(-128), getFloat80(-128.5)), + (getInt32(+0), getFloat80(-0.5)), + (getInt32(+0), getFloat80(-0)), + (getInt32(+0), getFloat80(+0)), + (getInt32(+0), getFloat80(+0.5)), + (getInt32(+127), getFloat80(+127.5)), + (getInt32(+255), getFloat80(+255.5)), + (getInt32(+32767), getFloat80(+32767.5)), + (getInt32(+65535), getFloat80(+65535.5)), + (getInt32(+2147483647), getFloat80(+2147483647)), +]) { + expectEqual($0.0, Int32($0.1)) +} + +FixedPointConversion_Release64_ToInt32 +.test("FromFloat80_NeverFails") +.forEach(in: [ + (getInt32(-2147483648), getFloat80(-2147483648)), + (getInt32(+0), getFloat80(-0)), + (getInt32(+0), getFloat80(+0)), + (getInt32(+2147483647), getFloat80(+2147483647)), +]) { + expectEqual($0.0, Int32(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToInt32 +.test("FromFloat80_AlwaysTraps") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-2147483649), + getFloat80(+2147483648), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int32($0)) +} + +FixedPointConversion_Release64_ToInt32 +.test("FromFloat80_AlwaysFails") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-2147483649), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-0.5), + getFloat80(+0.5), + getFloat80(+127.5), + getFloat80(+255.5), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(+2147483648), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectNil(Int32(exactly: $0)) } #endif // Float80 diff --git a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release64_ToInt64.swift b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release64_ToInt64.swift index 1a074a71ce337..af09fe7a5f968 100644 --- a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release64_ToInt64.swift +++ b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release64_ToInt64.swift @@ -14,1358 +14,562 @@ import StdlibUnittest -let FixedPointConversion_Release64_ToInt64 = TestSuite("FixedPointConversion_Release64_ToInt64") +let FixedPointConversion_Release64_ToInt64 = TestSuite( + "FixedPointConversion_Release64_ToInt64" +) //===----------------------------------------------------------------------===// -// MARK: UInt8: (0)...(255) +// MARK: UInt8: (+0)...(+255) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt64.test("FromUInt8(0)_NeverTraps") { - let input = getUInt8(0) - let actual = Int64(input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToInt64 +.test("FromUInt8_NeverTraps") +.forEach(in: [ + (getInt64(+0), getUInt8(+0)), + (getInt64(+255), getUInt8(+255)), +]) { + expectEqual($0.0, Int64($0.1)) } -FixedPointConversion_Release64_ToInt64.test("FromUInt8(0)_NeverFails") { - let input = getUInt8(0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromUInt8(255)_NeverTraps") { - let input = getUInt8(255) - let actual = Int64(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromUInt8(255)_NeverFails") { - let input = getUInt8(255) - let actual = Int64(exactly: input) - expectEqual(255, actual) +FixedPointConversion_Release64_ToInt64 +.test("FromUInt8_NeverFails") +.forEach(in: [ + (getInt64(+0), getUInt8(+0)), + (getInt64(+255), getUInt8(+255)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int8: (-128)...(127) +// MARK: Int8: (-128)...(+127) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt64.test("FromInt8(-128)_NeverTraps") { - let input = getInt8(-128) - let actual = Int64(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromInt8(-128)_NeverFails") { - let input = getInt8(-128) - let actual = Int64(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromInt8(0)_NeverTraps") { - let input = getInt8(0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromInt8(0)_NeverFails") { - let input = getInt8(0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromInt8(127)_NeverTraps") { - let input = getInt8(127) - let actual = Int64(input) - expectEqual(127, actual) +FixedPointConversion_Release64_ToInt64 +.test("FromInt8_NeverTraps") +.forEach(in: [ + (getInt64(-128), getInt8(-128)), + (getInt64(+0), getInt8(+0)), + (getInt64(+127), getInt8(+127)), +]) { + expectEqual($0.0, Int64($0.1)) } -FixedPointConversion_Release64_ToInt64.test("FromInt8(127)_NeverFails") { - let input = getInt8(127) - let actual = Int64(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Release64_ToInt64 +.test("FromInt8_NeverFails") +.forEach(in: [ + (getInt64(-128), getInt8(-128)), + (getInt64(+0), getInt8(+0)), + (getInt64(+127), getInt8(+127)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt16: (0)...(65535) +// MARK: UInt16: (+0)...(+65535) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt64.test("FromUInt16(0)_NeverTraps") { - let input = getUInt16(0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromUInt16(0)_NeverFails") { - let input = getUInt16(0) - let actual = Int64(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToInt64 +.test("FromUInt16_NeverTraps") +.forEach(in: [ + (getInt64(+0), getUInt16(+0)), + (getInt64(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, Int64($0.1)) } -FixedPointConversion_Release64_ToInt64.test("FromUInt16(65535)_NeverTraps") { - let input = getUInt16(65535) - let actual = Int64(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromUInt16(65535)_NeverFails") { - let input = getUInt16(65535) - let actual = Int64(exactly: input) - expectEqual(65535, actual) +FixedPointConversion_Release64_ToInt64 +.test("FromUInt16_NeverFails") +.forEach(in: [ + (getInt64(+0), getUInt16(+0)), + (getInt64(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int16: (-32768)...(32767) +// MARK: Int16: (-32768)...(+32767) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt64.test("FromInt16(-32768)_NeverTraps") { - let input = getInt16(-32768) - let actual = Int64(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromInt16(-32768)_NeverFails") { - let input = getInt16(-32768) - let actual = Int64(exactly: input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromInt16(0)_NeverTraps") { - let input = getInt16(0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromInt16(0)_NeverFails") { - let input = getInt16(0) - let actual = Int64(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToInt64 +.test("FromInt16_NeverTraps") +.forEach(in: [ + (getInt64(-32768), getInt16(-32768)), + (getInt64(+0), getInt16(+0)), + (getInt64(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, Int64($0.1)) } -FixedPointConversion_Release64_ToInt64.test("FromInt16(32767)_NeverTraps") { - let input = getInt16(32767) - let actual = Int64(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromInt16(32767)_NeverFails") { - let input = getInt16(32767) - let actual = Int64(exactly: input) - expectEqual(32767, actual) +FixedPointConversion_Release64_ToInt64 +.test("FromInt16_NeverFails") +.forEach(in: [ + (getInt64(-32768), getInt16(-32768)), + (getInt64(+0), getInt16(+0)), + (getInt64(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt32: (0)...(4294967295) +// MARK: UInt32: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt64.test("FromUInt32(0)_NeverTraps") { - let input = getUInt32(0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromUInt32(0)_NeverFails") { - let input = getUInt32(0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromUInt32(4294967295)_NeverTraps") { - let input = getUInt32(4294967295) - let actual = Int64(input) - expectEqual(4294967295, actual) +FixedPointConversion_Release64_ToInt64 +.test("FromUInt32_NeverTraps") +.forEach(in: [ + (getInt64(+0), getUInt32(+0)), + (getInt64(+4294967295), getUInt32(+4294967295)), +]) { + expectEqual($0.0, Int64($0.1)) } -FixedPointConversion_Release64_ToInt64.test("FromUInt32(4294967295)_NeverFails") { - let input = getUInt32(4294967295) - let actual = Int64(exactly: input) - expectEqual(4294967295, actual) +FixedPointConversion_Release64_ToInt64 +.test("FromUInt32_NeverFails") +.forEach(in: [ + (getInt64(+0), getUInt32(+0)), + (getInt64(+4294967295), getUInt32(+4294967295)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int32: (-2147483648)...(2147483647) +// MARK: Int32: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt64.test("FromInt32(-2147483648)_NeverTraps") { - let input = getInt32(-2147483648) - let actual = Int64(input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromInt32(-2147483648)_NeverFails") { - let input = getInt32(-2147483648) - let actual = Int64(exactly: input) - expectEqual(-2147483648, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromInt32(0)_NeverTraps") { - let input = getInt32(0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromInt32(0)_NeverFails") { - let input = getInt32(0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromInt32(2147483647)_NeverTraps") { - let input = getInt32(2147483647) - let actual = Int64(input) - expectEqual(2147483647, actual) +FixedPointConversion_Release64_ToInt64 +.test("FromInt32_NeverTraps") +.forEach(in: [ + (getInt64(-2147483648), getInt32(-2147483648)), + (getInt64(+0), getInt32(+0)), + (getInt64(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, Int64($0.1)) } -FixedPointConversion_Release64_ToInt64.test("FromInt32(2147483647)_NeverFails") { - let input = getInt32(2147483647) - let actual = Int64(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Release64_ToInt64 +.test("FromInt32_NeverFails") +.forEach(in: [ + (getInt64(-2147483648), getInt32(-2147483648)), + (getInt64(+0), getInt32(+0)), + (getInt64(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt64: (0)...(18446744073709551615) +// MARK: UInt64: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt64.test("FromUInt64(0)_NeverTraps") { - let input = getUInt64(0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromUInt64(0)_NeverFails") { - let input = getUInt64(0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromUInt64(9223372036854775807)_NeverTraps") { - let input = getUInt64(9223372036854775807) - let actual = Int64(input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromUInt64(9223372036854775807)_NeverFails") { - let input = getUInt64(9223372036854775807) - let actual = Int64(exactly: input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromUInt64(9223372036854775808)_AlwaysTraps") { - let input = getUInt64(9223372036854775808) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } +FixedPointConversion_Release64_ToInt64 +.test("FromUInt64_NeverTraps") +.forEach(in: [ + (getInt64(+0), getUInt64(+0)), + (getInt64(+9223372036854775807), getUInt64(+9223372036854775807)), +]) { + expectEqual($0.0, Int64($0.1)) } -FixedPointConversion_Release64_ToInt64.test("FromUInt64(9223372036854775808)_AlwaysFails") { - let input = getUInt64(9223372036854775808) - let actual = Int64(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt64 +.test("FromUInt64_NeverFails") +.forEach(in: [ + (getInt64(+0), getUInt64(+0)), + (getInt64(+9223372036854775807), getUInt64(+9223372036854775807)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) } -FixedPointConversion_Release64_ToInt64.test("FromUInt64(18446744073709551615)_AlwaysTraps") { - let input = getUInt64(18446744073709551615) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } +FixedPointConversion_Release64_ToInt64 +.test("FromUInt64_AlwaysTraps") +.forEach(in: [ + getUInt64(+9223372036854775808), + getUInt64(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(Int64($0)) } -FixedPointConversion_Release64_ToInt64.test("FromUInt64(18446744073709551615)_AlwaysFails") { - let input = getUInt64(18446744073709551615) - let actual = Int64(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt64 +.test("FromUInt64_AlwaysFails") +.forEach(in: [ + getUInt64(+9223372036854775808), + getUInt64(+18446744073709551615), +]) { + expectNil(Int64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int64: (-9223372036854775808)...(9223372036854775807) +// MARK: Int64: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt64.test("FromInt64(-9223372036854775808)_NeverTraps") { - let input = getInt64(-9223372036854775808) - let actual = Int64(input) - expectEqual(-9223372036854775808, actual) +FixedPointConversion_Release64_ToInt64 +.test("FromInt64_NeverTraps") +.forEach(in: [ + (getInt64(-9223372036854775808), getInt64(-9223372036854775808)), + (getInt64(+0), getInt64(+0)), + (getInt64(+9223372036854775807), getInt64(+9223372036854775807)), +]) { + expectEqual($0.0, Int64($0.1)) } -FixedPointConversion_Release64_ToInt64.test("FromInt64(-9223372036854775808)_NeverFails") { - let input = getInt64(-9223372036854775808) - let actual = Int64(exactly: input) - expectEqual(-9223372036854775808, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromInt64(0)_NeverTraps") { - let input = getInt64(0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromInt64(0)_NeverFails") { - let input = getInt64(0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromInt64(9223372036854775807)_NeverTraps") { - let input = getInt64(9223372036854775807) - let actual = Int64(input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromInt64(9223372036854775807)_NeverFails") { - let input = getInt64(9223372036854775807) - let actual = Int64(exactly: input) - expectEqual(9223372036854775807, actual) +FixedPointConversion_Release64_ToInt64 +.test("FromInt64_NeverFails") +.forEach(in: [ + (getInt64(-9223372036854775808), getInt64(-9223372036854775808)), + (getInt64(+0), getInt64(+0)), + (getInt64(+9223372036854775807), getInt64(+9223372036854775807)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt: (0)...(18446744073709551615) +// MARK: UInt: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt64.test("FromUInt(0)_NeverTraps") { - let input = getUInt(0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromUInt(0)_NeverFails") { - let input = getUInt(0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromUInt(9223372036854775807)_NeverTraps") { - let input = getUInt(9223372036854775807) - let actual = Int64(input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromUInt(9223372036854775807)_NeverFails") { - let input = getUInt(9223372036854775807) - let actual = Int64(exactly: input) - expectEqual(9223372036854775807, actual) +FixedPointConversion_Release64_ToInt64 +.test("FromUInt_NeverTraps") +.forEach(in: [ + (getInt64(+0), getUInt(+0)), + (getInt64(+9223372036854775807), getUInt(+9223372036854775807)), +]) { + expectEqual($0.0, Int64($0.1)) } -FixedPointConversion_Release64_ToInt64.test("FromUInt(9223372036854775808)_AlwaysTraps") { - let input = getUInt(9223372036854775808) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } +FixedPointConversion_Release64_ToInt64 +.test("FromUInt_NeverFails") +.forEach(in: [ + (getInt64(+0), getUInt(+0)), + (getInt64(+9223372036854775807), getUInt(+9223372036854775807)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) } -FixedPointConversion_Release64_ToInt64.test("FromUInt(9223372036854775808)_AlwaysFails") { - let input = getUInt(9223372036854775808) - let actual = Int64(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt64 +.test("FromUInt_AlwaysTraps") +.forEach(in: [ + getUInt(+9223372036854775808), + getUInt(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(Int64($0)) } -FixedPointConversion_Release64_ToInt64.test("FromUInt(18446744073709551615)_AlwaysTraps") { - let input = getUInt(18446744073709551615) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt64.test("FromUInt(18446744073709551615)_AlwaysFails") { - let input = getUInt(18446744073709551615) - let actual = Int64(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt64 +.test("FromUInt_AlwaysFails") +.forEach(in: [ + getUInt(+9223372036854775808), + getUInt(+18446744073709551615), +]) { + expectNil(Int64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int: (-9223372036854775808)...(9223372036854775807) +// MARK: Int: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt64.test("FromInt(-9223372036854775808)_NeverTraps") { - let input = getInt(-9223372036854775808) - let actual = Int64(input) - expectEqual(-9223372036854775808, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromInt(-9223372036854775808)_NeverFails") { - let input = getInt(-9223372036854775808) - let actual = Int64(exactly: input) - expectEqual(-9223372036854775808, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromInt(0)_NeverTraps") { - let input = getInt(0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromInt(0)_NeverFails") { - let input = getInt(0) - let actual = Int64(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToInt64 +.test("FromInt_NeverTraps") +.forEach(in: [ + (getInt64(-9223372036854775808), getInt(-9223372036854775808)), + (getInt64(+0), getInt(+0)), + (getInt64(+9223372036854775807), getInt(+9223372036854775807)), +]) { + expectEqual($0.0, Int64($0.1)) } -FixedPointConversion_Release64_ToInt64.test("FromInt(9223372036854775807)_NeverTraps") { - let input = getInt(9223372036854775807) - let actual = Int64(input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromInt(9223372036854775807)_NeverFails") { - let input = getInt(9223372036854775807) - let actual = Int64(exactly: input) - expectEqual(9223372036854775807, actual) +FixedPointConversion_Release64_ToInt64 +.test("FromInt_NeverFails") +.forEach(in: [ + (getInt64(-9223372036854775808), getInt(-9223372036854775808)), + (getInt64(+0), getInt(+0)), + (getInt64(+9223372036854775807), getInt(+9223372036854775807)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Float16: (-2047)...(2047) +// MARK: Float16: (-2047)...(+2047) //===----------------------------------------------------------------------===// #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -FixedPointConversion_Release64_ToInt64.test("FromFloat16(-2047)_NeverTraps") { - let input = getFloat16(-2047) - let actual = Int64(input) - expectEqual(-2047, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat16(-2047)_NeverFails") { - let input = getFloat16(-2047) - let actual = Int64(exactly: input) - expectEqual(-2047, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat16(-128.5)_NeverTraps") { - let input = getFloat16(-128.5) - let actual = Int64(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat16(-128.5)_AlwaysFails") { - let input = getFloat16(-128.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat16(-0.5)_NeverTraps") { - let input = getFloat16(-0.5) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat16(-0.5)_AlwaysFails") { - let input = getFloat16(-0.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat16(-0.0)_NeverTraps") { - let input = getFloat16(-0.0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat16(-0.0)_NeverFails") { - let input = getFloat16(-0.0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat16(0.0)_NeverTraps") { - let input = getFloat16(0.0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat16(0.0)_NeverFails") { - let input = getFloat16(0.0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat16(0.5)_NeverTraps") { - let input = getFloat16(0.5) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat16(0.5)_AlwaysFails") { - let input = getFloat16(0.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat16(127.5)_NeverTraps") { - let input = getFloat16(127.5) - let actual = Int64(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat16(127.5)_AlwaysFails") { - let input = getFloat16(127.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat16(255.5)_NeverTraps") { - let input = getFloat16(255.5) - let actual = Int64(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat16(255.5)_AlwaysFails") { - let input = getFloat16(255.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat16(2047)_NeverTraps") { - let input = getFloat16(2047) - let actual = Int64(input) - expectEqual(2047, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat16(2047)_NeverFails") { - let input = getFloat16(2047) - let actual = Int64(exactly: input) - expectEqual(2047, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat16(-.infinity)_AlwaysTraps") { - let input = getFloat16(-.infinity) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat16(-.infinity)_AlwaysFails") { - let input = getFloat16(-.infinity) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat16(+.infinity)_AlwaysTraps") { - let input = getFloat16(+.infinity) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat16(+.infinity)_AlwaysFails") { - let input = getFloat16(+.infinity) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat16(-.nan)_AlwaysTraps") { - let input = getFloat16(-.nan) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat16(-.nan)_AlwaysFails") { - let input = getFloat16(-.nan) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat16(+.nan)_AlwaysTraps") { - let input = getFloat16(+.nan) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat16(+.nan)_AlwaysFails") { - let input = getFloat16(+.nan) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat16(-.signalingNaN)_AlwaysTraps") { - let input = getFloat16(-.signalingNaN) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat16(-.signalingNaN)_AlwaysFails") { - let input = getFloat16(-.signalingNaN) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat16(+.signalingNaN)_AlwaysTraps") { - let input = getFloat16(+.signalingNaN) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat16(+.signalingNaN)_AlwaysFails") { - let input = getFloat16(+.signalingNaN) - let actual = Int64(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt64 +.test("FromFloat16_NeverTraps") +.forEach(in: [ + (getInt64(-2047), getFloat16(-2047)), + (getInt64(-128), getFloat16(-128.5)), + (getInt64(+0), getFloat16(-0.5)), + (getInt64(+0), getFloat16(+0)), + (getInt64(+0), getFloat16(-0)), + (getInt64(+0), getFloat16(+0.5)), + (getInt64(+127), getFloat16(+127.5)), + (getInt64(+255), getFloat16(+255.5)), + (getInt64(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, Int64($0.1)) +} + +FixedPointConversion_Release64_ToInt64 +.test("FromFloat16_NeverFails") +.forEach(in: [ + (getInt64(-2047), getFloat16(-2047)), + (getInt64(+0), getFloat16(+0)), + (getInt64(+0), getFloat16(-0)), + (getInt64(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToInt64 +.test("FromFloat16_AlwaysTraps") +.forEach(in: [ + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int64($0)) +} + +FixedPointConversion_Release64_ToInt64 +.test("FromFloat16_AlwaysFails") +.forEach(in: [ + getFloat16(-128.5), + getFloat16(-0.5), + getFloat16(+0.5), + getFloat16(+127.5), + getFloat16(+255.5), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectNil(Int64(exactly: $0)) } } #endif // Float16 //===----------------------------------------------------------------------===// -// MARK: Float32: (-16777215)...(16777215) +// MARK: Float32: (-16777215)...(+16777215) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt64.test("FromFloat32(-16777215)_NeverTraps") { - let input = getFloat32(-16777215) - let actual = Int64(input) - expectEqual(-16777215, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat32(-16777215)_NeverFails") { - let input = getFloat32(-16777215) - let actual = Int64(exactly: input) - expectEqual(-16777215, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat32(-32768.5)_NeverTraps") { - let input = getFloat32(-32768.5) - let actual = Int64(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat32(-32768.5)_AlwaysFails") { - let input = getFloat32(-32768.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat32(-128.5)_NeverTraps") { - let input = getFloat32(-128.5) - let actual = Int64(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat32(-128.5)_AlwaysFails") { - let input = getFloat32(-128.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat32(-0.5)_NeverTraps") { - let input = getFloat32(-0.5) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat32(-0.5)_AlwaysFails") { - let input = getFloat32(-0.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat32(-0.0)_NeverTraps") { - let input = getFloat32(-0.0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat32(-0.0)_NeverFails") { - let input = getFloat32(-0.0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat32(0.0)_NeverTraps") { - let input = getFloat32(0.0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat32(0.0)_NeverFails") { - let input = getFloat32(0.0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat32(0.5)_NeverTraps") { - let input = getFloat32(0.5) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat32(0.5)_AlwaysFails") { - let input = getFloat32(0.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat32(127.5)_NeverTraps") { - let input = getFloat32(127.5) - let actual = Int64(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat32(127.5)_AlwaysFails") { - let input = getFloat32(127.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat32(255.5)_NeverTraps") { - let input = getFloat32(255.5) - let actual = Int64(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat32(255.5)_AlwaysFails") { - let input = getFloat32(255.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat32(32767.5)_NeverTraps") { - let input = getFloat32(32767.5) - let actual = Int64(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat32(32767.5)_AlwaysFails") { - let input = getFloat32(32767.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat32(65535.5)_NeverTraps") { - let input = getFloat32(65535.5) - let actual = Int64(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat32(65535.5)_AlwaysFails") { - let input = getFloat32(65535.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat32(16777215)_NeverTraps") { - let input = getFloat32(16777215) - let actual = Int64(input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat32(16777215)_NeverFails") { - let input = getFloat32(16777215) - let actual = Int64(exactly: input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat32(-.infinity)_AlwaysTraps") { - let input = getFloat32(-.infinity) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat32(-.infinity)_AlwaysFails") { - let input = getFloat32(-.infinity) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat32(+.infinity)_AlwaysTraps") { - let input = getFloat32(+.infinity) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat32(+.infinity)_AlwaysFails") { - let input = getFloat32(+.infinity) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat32(-.nan)_AlwaysTraps") { - let input = getFloat32(-.nan) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat32(-.nan)_AlwaysFails") { - let input = getFloat32(-.nan) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat32(+.nan)_AlwaysTraps") { - let input = getFloat32(+.nan) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat32(+.nan)_AlwaysFails") { - let input = getFloat32(+.nan) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat32(-.signalingNaN)_AlwaysTraps") { - let input = getFloat32(-.signalingNaN) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat32(-.signalingNaN)_AlwaysFails") { - let input = getFloat32(-.signalingNaN) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat32(+.signalingNaN)_AlwaysTraps") { - let input = getFloat32(+.signalingNaN) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat32(+.signalingNaN)_AlwaysFails") { - let input = getFloat32(+.signalingNaN) - let actual = Int64(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt64 +.test("FromFloat32_NeverTraps") +.forEach(in: [ + (getInt64(-16777215), getFloat32(-16777215)), + (getInt64(-32768), getFloat32(-32768.5)), + (getInt64(-128), getFloat32(-128.5)), + (getInt64(+0), getFloat32(-0.5)), + (getInt64(+0), getFloat32(+0)), + (getInt64(+0), getFloat32(-0)), + (getInt64(+0), getFloat32(+0.5)), + (getInt64(+127), getFloat32(+127.5)), + (getInt64(+255), getFloat32(+255.5)), + (getInt64(+32767), getFloat32(+32767.5)), + (getInt64(+65535), getFloat32(+65535.5)), + (getInt64(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, Int64($0.1)) +} + +FixedPointConversion_Release64_ToInt64 +.test("FromFloat32_NeverFails") +.forEach(in: [ + (getInt64(-16777215), getFloat32(-16777215)), + (getInt64(+0), getFloat32(+0)), + (getInt64(+0), getFloat32(-0)), + (getInt64(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToInt64 +.test("FromFloat32_AlwaysTraps") +.forEach(in: [ + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int64($0)) +} + +FixedPointConversion_Release64_ToInt64 +.test("FromFloat32_AlwaysFails") +.forEach(in: [ + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-0.5), + getFloat32(+0.5), + getFloat32(+127.5), + getFloat32(+255.5), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectNil(Int64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float64: (-9007199254740991)...(9007199254740991) +// MARK: Float64: (-9007199254740991)...(+9007199254740991) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt64.test("FromFloat64(-9007199254740991)_NeverTraps") { - let input = getFloat64(-9007199254740991) - let actual = Int64(input) - expectEqual(-9007199254740991, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat64(-9007199254740991)_NeverFails") { - let input = getFloat64(-9007199254740991) - let actual = Int64(exactly: input) - expectEqual(-9007199254740991, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat64(-32768.5)_NeverTraps") { - let input = getFloat64(-32768.5) - let actual = Int64(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat64(-32768.5)_AlwaysFails") { - let input = getFloat64(-32768.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat64(-128.5)_NeverTraps") { - let input = getFloat64(-128.5) - let actual = Int64(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat64(-128.5)_AlwaysFails") { - let input = getFloat64(-128.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat64(-0.5)_NeverTraps") { - let input = getFloat64(-0.5) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat64(-0.5)_AlwaysFails") { - let input = getFloat64(-0.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat64(-0.0)_NeverTraps") { - let input = getFloat64(-0.0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat64(-0.0)_NeverFails") { - let input = getFloat64(-0.0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat64(0.0)_NeverTraps") { - let input = getFloat64(0.0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat64(0.0)_NeverFails") { - let input = getFloat64(0.0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat64(0.5)_NeverTraps") { - let input = getFloat64(0.5) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat64(0.5)_AlwaysFails") { - let input = getFloat64(0.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat64(127.5)_NeverTraps") { - let input = getFloat64(127.5) - let actual = Int64(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat64(127.5)_AlwaysFails") { - let input = getFloat64(127.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat64(255.5)_NeverTraps") { - let input = getFloat64(255.5) - let actual = Int64(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat64(255.5)_AlwaysFails") { - let input = getFloat64(255.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat64(32767.5)_NeverTraps") { - let input = getFloat64(32767.5) - let actual = Int64(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat64(32767.5)_AlwaysFails") { - let input = getFloat64(32767.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat64(65535.5)_NeverTraps") { - let input = getFloat64(65535.5) - let actual = Int64(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat64(65535.5)_AlwaysFails") { - let input = getFloat64(65535.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat64(9007199254740991)_NeverTraps") { - let input = getFloat64(9007199254740991) - let actual = Int64(input) - expectEqual(9007199254740991, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat64(9007199254740991)_NeverFails") { - let input = getFloat64(9007199254740991) - let actual = Int64(exactly: input) - expectEqual(9007199254740991, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat64(-.infinity)_AlwaysTraps") { - let input = getFloat64(-.infinity) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat64(-.infinity)_AlwaysFails") { - let input = getFloat64(-.infinity) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat64(+.infinity)_AlwaysTraps") { - let input = getFloat64(+.infinity) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat64(+.infinity)_AlwaysFails") { - let input = getFloat64(+.infinity) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat64(-.nan)_AlwaysTraps") { - let input = getFloat64(-.nan) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat64(-.nan)_AlwaysFails") { - let input = getFloat64(-.nan) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat64(+.nan)_AlwaysTraps") { - let input = getFloat64(+.nan) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat64(+.nan)_AlwaysFails") { - let input = getFloat64(+.nan) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat64(-.signalingNaN)_AlwaysTraps") { - let input = getFloat64(-.signalingNaN) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat64(-.signalingNaN)_AlwaysFails") { - let input = getFloat64(-.signalingNaN) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat64(+.signalingNaN)_AlwaysTraps") { - let input = getFloat64(+.signalingNaN) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat64(+.signalingNaN)_AlwaysFails") { - let input = getFloat64(+.signalingNaN) - let actual = Int64(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt64 +.test("FromFloat64_NeverTraps") +.forEach(in: [ + (getInt64(-9007199254740991), getFloat64(-9007199254740991)), + (getInt64(-32768), getFloat64(-32768.5)), + (getInt64(-128), getFloat64(-128.5)), + (getInt64(+0), getFloat64(-0.5)), + (getInt64(+0), getFloat64(+0)), + (getInt64(+0), getFloat64(-0)), + (getInt64(+0), getFloat64(+0.5)), + (getInt64(+127), getFloat64(+127.5)), + (getInt64(+255), getFloat64(+255.5)), + (getInt64(+32767), getFloat64(+32767.5)), + (getInt64(+65535), getFloat64(+65535.5)), + (getInt64(+9007199254740991), getFloat64(+9007199254740991)), +]) { + expectEqual($0.0, Int64($0.1)) +} + +FixedPointConversion_Release64_ToInt64 +.test("FromFloat64_NeverFails") +.forEach(in: [ + (getInt64(-9007199254740991), getFloat64(-9007199254740991)), + (getInt64(+0), getFloat64(+0)), + (getInt64(+0), getFloat64(-0)), + (getInt64(+9007199254740991), getFloat64(+9007199254740991)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToInt64 +.test("FromFloat64_AlwaysTraps") +.forEach(in: [ + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int64($0)) +} + +FixedPointConversion_Release64_ToInt64 +.test("FromFloat64_AlwaysFails") +.forEach(in: [ + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-0.5), + getFloat64(+0.5), + getFloat64(+127.5), + getFloat64(+255.5), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectNil(Int64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float80: (-18446744073709551615)...(18446744073709551615) +// MARK: Float80: (-18446744073709551615)...(+18446744073709551615) //===----------------------------------------------------------------------===// #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) -FixedPointConversion_Release64_ToInt64.test("FromFloat80(-18446744073709551615)_AlwaysTraps") { - let input = getFloat80(-18446744073709551615) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(-18446744073709551615)_AlwaysFails") { - let input = getFloat80(-18446744073709551615) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(-9223372036854775809)_AlwaysTraps") { - let input = getFloat80(-9223372036854775809) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(-9223372036854775809)_AlwaysFails") { - let input = getFloat80(-9223372036854775809) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(-9223372036854775808)_NeverTraps") { - let input = getFloat80(-9223372036854775808) - let actual = Int64(input) - expectEqual(-9223372036854775808, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(-9223372036854775808)_NeverFails") { - let input = getFloat80(-9223372036854775808) - let actual = Int64(exactly: input) - expectEqual(-9223372036854775808, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(-32768.5)_NeverTraps") { - let input = getFloat80(-32768.5) - let actual = Int64(input) - expectEqual(-32768, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(-32768.5)_AlwaysFails") { - let input = getFloat80(-32768.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(-128.5)_NeverTraps") { - let input = getFloat80(-128.5) - let actual = Int64(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(-128.5)_AlwaysFails") { - let input = getFloat80(-128.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(-0.5)_NeverTraps") { - let input = getFloat80(-0.5) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(-0.5)_AlwaysFails") { - let input = getFloat80(-0.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(-0.0)_NeverTraps") { - let input = getFloat80(-0.0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(-0.0)_NeverFails") { - let input = getFloat80(-0.0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(0.0)_NeverTraps") { - let input = getFloat80(0.0) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(0.0)_NeverFails") { - let input = getFloat80(0.0) - let actual = Int64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(0.5)_NeverTraps") { - let input = getFloat80(0.5) - let actual = Int64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(0.5)_AlwaysFails") { - let input = getFloat80(0.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(127.5)_NeverTraps") { - let input = getFloat80(127.5) - let actual = Int64(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(127.5)_AlwaysFails") { - let input = getFloat80(127.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(255.5)_NeverTraps") { - let input = getFloat80(255.5) - let actual = Int64(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(255.5)_AlwaysFails") { - let input = getFloat80(255.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(32767.5)_NeverTraps") { - let input = getFloat80(32767.5) - let actual = Int64(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(32767.5)_AlwaysFails") { - let input = getFloat80(32767.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(65535.5)_NeverTraps") { - let input = getFloat80(65535.5) - let actual = Int64(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(65535.5)_AlwaysFails") { - let input = getFloat80(65535.5) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(9223372036854775807)_NeverTraps") { - let input = getFloat80(9223372036854775807) - let actual = Int64(input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(9223372036854775807)_NeverFails") { - let input = getFloat80(9223372036854775807) - let actual = Int64(exactly: input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(9223372036854775808)_AlwaysTraps") { - let input = getFloat80(9223372036854775808) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(9223372036854775808)_AlwaysFails") { - let input = getFloat80(9223372036854775808) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(18446744073709551615)_AlwaysTraps") { - let input = getFloat80(18446744073709551615) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(18446744073709551615)_AlwaysFails") { - let input = getFloat80(18446744073709551615) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(-.infinity)_AlwaysTraps") { - let input = getFloat80(-.infinity) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(-.infinity)_AlwaysFails") { - let input = getFloat80(-.infinity) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(+.infinity)_AlwaysTraps") { - let input = getFloat80(+.infinity) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(+.infinity)_AlwaysFails") { - let input = getFloat80(+.infinity) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(-.nan)_AlwaysTraps") { - let input = getFloat80(-.nan) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(-.nan)_AlwaysFails") { - let input = getFloat80(-.nan) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(+.nan)_AlwaysTraps") { - let input = getFloat80(+.nan) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(+.nan)_AlwaysFails") { - let input = getFloat80(+.nan) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(-.signalingNaN)_AlwaysTraps") { - let input = getFloat80(-.signalingNaN) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(-.signalingNaN)_AlwaysFails") { - let input = getFloat80(-.signalingNaN) - let actual = Int64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(+.signalingNaN)_AlwaysTraps") { - let input = getFloat80(+.signalingNaN) - expectCrash { - let actual = Int64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt64.test("FromFloat80(+.signalingNaN)_AlwaysFails") { - let input = getFloat80(+.signalingNaN) - let actual = Int64(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt64 +.test("FromFloat80_NeverTraps") +.forEach(in: [ + (getInt64(-9223372036854775808), getFloat80(-9223372036854775808)), + (getInt64(-32768), getFloat80(-32768.5)), + (getInt64(-128), getFloat80(-128.5)), + (getInt64(+0), getFloat80(-0.5)), + (getInt64(+0), getFloat80(-0)), + (getInt64(+0), getFloat80(+0)), + (getInt64(+0), getFloat80(+0.5)), + (getInt64(+127), getFloat80(+127.5)), + (getInt64(+255), getFloat80(+255.5)), + (getInt64(+32767), getFloat80(+32767.5)), + (getInt64(+65535), getFloat80(+65535.5)), + (getInt64(+9223372036854775807), getFloat80(+9223372036854775807)), +]) { + expectEqual($0.0, Int64($0.1)) +} + +FixedPointConversion_Release64_ToInt64 +.test("FromFloat80_NeverFails") +.forEach(in: [ + (getInt64(-9223372036854775808), getFloat80(-9223372036854775808)), + (getInt64(+0), getFloat80(-0)), + (getInt64(+0), getFloat80(+0)), + (getInt64(+9223372036854775807), getFloat80(+9223372036854775807)), +]) { + expectEqual($0.0, Int64(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToInt64 +.test("FromFloat80_AlwaysTraps") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-9223372036854775809), + getFloat80(+9223372036854775808), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int64($0)) +} + +FixedPointConversion_Release64_ToInt64 +.test("FromFloat80_AlwaysFails") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-9223372036854775809), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-0.5), + getFloat80(+0.5), + getFloat80(+127.5), + getFloat80(+255.5), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(+9223372036854775808), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectNil(Int64(exactly: $0)) } #endif // Float80 diff --git a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release64_ToInt8.swift b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release64_ToInt8.swift index 0de77217fae46..60525d7fa036a 100644 --- a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release64_ToInt8.swift +++ b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release64_ToInt8.swift @@ -14,1860 +14,735 @@ import StdlibUnittest -let FixedPointConversion_Release64_ToInt8 = TestSuite("FixedPointConversion_Release64_ToInt8") +let FixedPointConversion_Release64_ToInt8 = TestSuite( + "FixedPointConversion_Release64_ToInt8" +) //===----------------------------------------------------------------------===// -// MARK: UInt8: (0)...(255) +// MARK: UInt8: (+0)...(+255) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt8.test("FromUInt8(0)_NeverTraps") { - let input = getUInt8(0) - let actual = Int8(input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToInt8 +.test("FromUInt8_NeverTraps") +.forEach(in: [ + (getInt8(+0), getUInt8(+0)), + (getInt8(+127), getUInt8(+127)), +]) { + expectEqual($0.0, Int8($0.1)) } -FixedPointConversion_Release64_ToInt8.test("FromUInt8(0)_NeverFails") { - let input = getUInt8(0) - let actual = Int8(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToInt8 +.test("FromUInt8_NeverFails") +.forEach(in: [ + (getInt8(+0), getUInt8(+0)), + (getInt8(+127), getUInt8(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) } -FixedPointConversion_Release64_ToInt8.test("FromUInt8(127)_NeverTraps") { - let input = getUInt8(127) - let actual = Int8(input) - expectEqual(127, actual) +FixedPointConversion_Release64_ToInt8 +.test("FromUInt8_AlwaysTraps") +.forEach(in: [ + getUInt8(+128), + getUInt8(+255), +]) { + expectCrashLater() + _blackHole(Int8($0)) } -FixedPointConversion_Release64_ToInt8.test("FromUInt8(127)_NeverFails") { - let input = getUInt8(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromUInt8(128)_AlwaysTraps") { - let input = getUInt8(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromUInt8(128)_AlwaysFails") { - let input = getUInt8(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromUInt8(255)_AlwaysTraps") { - let input = getUInt8(255) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromUInt8(255)_AlwaysFails") { - let input = getUInt8(255) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt8 +.test("FromUInt8_AlwaysFails") +.forEach(in: [ + getUInt8(+128), + getUInt8(+255), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int8: (-128)...(127) +// MARK: Int8: (-128)...(+127) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt8.test("FromInt8(-128)_NeverTraps") { - let input = getInt8(-128) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromInt8(-128)_NeverFails") { - let input = getInt8(-128) - let actual = Int8(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromInt8(0)_NeverTraps") { - let input = getInt8(0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromInt8(0)_NeverFails") { - let input = getInt8(0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromInt8(127)_NeverTraps") { - let input = getInt8(127) - let actual = Int8(input) - expectEqual(127, actual) +FixedPointConversion_Release64_ToInt8 +.test("FromInt8_NeverTraps") +.forEach(in: [ + (getInt8(-128), getInt8(-128)), + (getInt8(+0), getInt8(+0)), + (getInt8(+127), getInt8(+127)), +]) { + expectEqual($0.0, Int8($0.1)) } -FixedPointConversion_Release64_ToInt8.test("FromInt8(127)_NeverFails") { - let input = getInt8(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Release64_ToInt8 +.test("FromInt8_NeverFails") +.forEach(in: [ + (getInt8(-128), getInt8(-128)), + (getInt8(+0), getInt8(+0)), + (getInt8(+127), getInt8(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: UInt16: (0)...(65535) +// MARK: UInt16: (+0)...(+65535) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt8.test("FromUInt16(0)_NeverTraps") { - let input = getUInt16(0) - let actual = Int8(input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToInt8 +.test("FromUInt16_NeverTraps") +.forEach(in: [ + (getInt8(+0), getUInt16(+0)), + (getInt8(+127), getUInt16(+127)), +]) { + expectEqual($0.0, Int8($0.1)) } -FixedPointConversion_Release64_ToInt8.test("FromUInt16(0)_NeverFails") { - let input = getUInt16(0) - let actual = Int8(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToInt8 +.test("FromUInt16_NeverFails") +.forEach(in: [ + (getInt8(+0), getUInt16(+0)), + (getInt8(+127), getUInt16(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) } -FixedPointConversion_Release64_ToInt8.test("FromUInt16(127)_NeverTraps") { - let input = getUInt16(127) - let actual = Int8(input) - expectEqual(127, actual) +FixedPointConversion_Release64_ToInt8 +.test("FromUInt16_AlwaysTraps") +.forEach(in: [ + getUInt16(+128), + getUInt16(+65535), +]) { + expectCrashLater() + _blackHole(Int8($0)) } -FixedPointConversion_Release64_ToInt8.test("FromUInt16(127)_NeverFails") { - let input = getUInt16(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromUInt16(128)_AlwaysTraps") { - let input = getUInt16(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromUInt16(128)_AlwaysFails") { - let input = getUInt16(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromUInt16(65535)_AlwaysTraps") { - let input = getUInt16(65535) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromUInt16(65535)_AlwaysFails") { - let input = getUInt16(65535) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt8 +.test("FromUInt16_AlwaysFails") +.forEach(in: [ + getUInt16(+128), + getUInt16(+65535), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int16: (-32768)...(32767) +// MARK: Int16: (-32768)...(+32767) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt8.test("FromInt16(-32768)_AlwaysTraps") { - let input = getInt16(-32768) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromInt16(-32768)_AlwaysFails") { - let input = getInt16(-32768) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromInt16(-129)_AlwaysTraps") { - let input = getInt16(-129) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromInt16(-129)_AlwaysFails") { - let input = getInt16(-129) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromInt16(-128)_NeverTraps") { - let input = getInt16(-128) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromInt16(-128)_NeverFails") { - let input = getInt16(-128) - let actual = Int8(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromInt16(0)_NeverTraps") { - let input = getInt16(0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromInt16(0)_NeverFails") { - let input = getInt16(0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromInt16(127)_NeverTraps") { - let input = getInt16(127) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromInt16(127)_NeverFails") { - let input = getInt16(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromInt16(128)_AlwaysTraps") { - let input = getInt16(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromInt16(128)_AlwaysFails") { - let input = getInt16(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromInt16(32767)_AlwaysTraps") { - let input = getInt16(32767) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromInt16(32767)_AlwaysFails") { - let input = getInt16(32767) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt8 +.test("FromInt16_NeverTraps") +.forEach(in: [ + (getInt8(-128), getInt16(-128)), + (getInt8(+0), getInt16(+0)), + (getInt8(+127), getInt16(+127)), +]) { + expectEqual($0.0, Int8($0.1)) +} + +FixedPointConversion_Release64_ToInt8 +.test("FromInt16_NeverFails") +.forEach(in: [ + (getInt8(-128), getInt16(-128)), + (getInt8(+0), getInt16(+0)), + (getInt8(+127), getInt16(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToInt8 +.test("FromInt16_AlwaysTraps") +.forEach(in: [ + getInt16(-32768), + getInt16(-129), + getInt16(+128), + getInt16(+32767), +]) { + expectCrashLater() + _blackHole(Int8($0)) +} + +FixedPointConversion_Release64_ToInt8 +.test("FromInt16_AlwaysFails") +.forEach(in: [ + getInt16(-32768), + getInt16(-129), + getInt16(+128), + getInt16(+32767), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt32: (0)...(4294967295) +// MARK: UInt32: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt8.test("FromUInt32(0)_NeverTraps") { - let input = getUInt32(0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromUInt32(0)_NeverFails") { - let input = getUInt32(0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromUInt32(127)_NeverTraps") { - let input = getUInt32(127) - let actual = Int8(input) - expectEqual(127, actual) +FixedPointConversion_Release64_ToInt8 +.test("FromUInt32_NeverTraps") +.forEach(in: [ + (getInt8(+0), getUInt32(+0)), + (getInt8(+127), getUInt32(+127)), +]) { + expectEqual($0.0, Int8($0.1)) } -FixedPointConversion_Release64_ToInt8.test("FromUInt32(127)_NeverFails") { - let input = getUInt32(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Release64_ToInt8 +.test("FromUInt32_NeverFails") +.forEach(in: [ + (getInt8(+0), getUInt32(+0)), + (getInt8(+127), getUInt32(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) } -FixedPointConversion_Release64_ToInt8.test("FromUInt32(128)_AlwaysTraps") { - let input = getUInt32(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } +FixedPointConversion_Release64_ToInt8 +.test("FromUInt32_AlwaysTraps") +.forEach(in: [ + getUInt32(+128), + getUInt32(+4294967295), +]) { + expectCrashLater() + _blackHole(Int8($0)) } -FixedPointConversion_Release64_ToInt8.test("FromUInt32(128)_AlwaysFails") { - let input = getUInt32(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromUInt32(4294967295)_AlwaysTraps") { - let input = getUInt32(4294967295) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromUInt32(4294967295)_AlwaysFails") { - let input = getUInt32(4294967295) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt8 +.test("FromUInt32_AlwaysFails") +.forEach(in: [ + getUInt32(+128), + getUInt32(+4294967295), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int32: (-2147483648)...(2147483647) +// MARK: Int32: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt8.test("FromInt32(-2147483648)_AlwaysTraps") { - let input = getInt32(-2147483648) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromInt32(-2147483648)_AlwaysFails") { - let input = getInt32(-2147483648) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromInt32(-129)_AlwaysTraps") { - let input = getInt32(-129) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromInt32(-129)_AlwaysFails") { - let input = getInt32(-129) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromInt32(-128)_NeverTraps") { - let input = getInt32(-128) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromInt32(-128)_NeverFails") { - let input = getInt32(-128) - let actual = Int8(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromInt32(0)_NeverTraps") { - let input = getInt32(0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromInt32(0)_NeverFails") { - let input = getInt32(0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromInt32(127)_NeverTraps") { - let input = getInt32(127) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromInt32(127)_NeverFails") { - let input = getInt32(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromInt32(128)_AlwaysTraps") { - let input = getInt32(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromInt32(128)_AlwaysFails") { - let input = getInt32(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromInt32(2147483647)_AlwaysTraps") { - let input = getInt32(2147483647) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromInt32(2147483647)_AlwaysFails") { - let input = getInt32(2147483647) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt8 +.test("FromInt32_NeverTraps") +.forEach(in: [ + (getInt8(-128), getInt32(-128)), + (getInt8(+0), getInt32(+0)), + (getInt8(+127), getInt32(+127)), +]) { + expectEqual($0.0, Int8($0.1)) +} + +FixedPointConversion_Release64_ToInt8 +.test("FromInt32_NeverFails") +.forEach(in: [ + (getInt8(-128), getInt32(-128)), + (getInt8(+0), getInt32(+0)), + (getInt8(+127), getInt32(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToInt8 +.test("FromInt32_AlwaysTraps") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-129), + getInt32(+128), + getInt32(+2147483647), +]) { + expectCrashLater() + _blackHole(Int8($0)) +} + +FixedPointConversion_Release64_ToInt8 +.test("FromInt32_AlwaysFails") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-129), + getInt32(+128), + getInt32(+2147483647), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt64: (0)...(18446744073709551615) +// MARK: UInt64: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt8.test("FromUInt64(0)_NeverTraps") { - let input = getUInt64(0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromUInt64(0)_NeverFails") { - let input = getUInt64(0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromUInt64(127)_NeverTraps") { - let input = getUInt64(127) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromUInt64(127)_NeverFails") { - let input = getUInt64(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromUInt64(128)_AlwaysTraps") { - let input = getUInt64(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } +FixedPointConversion_Release64_ToInt8 +.test("FromUInt64_NeverTraps") +.forEach(in: [ + (getInt8(+0), getUInt64(+0)), + (getInt8(+127), getUInt64(+127)), +]) { + expectEqual($0.0, Int8($0.1)) } -FixedPointConversion_Release64_ToInt8.test("FromUInt64(128)_AlwaysFails") { - let input = getUInt64(128) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt8 +.test("FromUInt64_NeverFails") +.forEach(in: [ + (getInt8(+0), getUInt64(+0)), + (getInt8(+127), getUInt64(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) } -FixedPointConversion_Release64_ToInt8.test("FromUInt64(18446744073709551615)_AlwaysTraps") { - let input = getUInt64(18446744073709551615) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } +FixedPointConversion_Release64_ToInt8 +.test("FromUInt64_AlwaysTraps") +.forEach(in: [ + getUInt64(+128), + getUInt64(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(Int8($0)) } -FixedPointConversion_Release64_ToInt8.test("FromUInt64(18446744073709551615)_AlwaysFails") { - let input = getUInt64(18446744073709551615) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt8 +.test("FromUInt64_AlwaysFails") +.forEach(in: [ + getUInt64(+128), + getUInt64(+18446744073709551615), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int64: (-9223372036854775808)...(9223372036854775807) +// MARK: Int64: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt8.test("FromInt64(-9223372036854775808)_AlwaysTraps") { - let input = getInt64(-9223372036854775808) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromInt64(-9223372036854775808)_AlwaysFails") { - let input = getInt64(-9223372036854775808) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromInt64(-129)_AlwaysTraps") { - let input = getInt64(-129) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromInt64(-129)_AlwaysFails") { - let input = getInt64(-129) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromInt64(-128)_NeverTraps") { - let input = getInt64(-128) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromInt64(-128)_NeverFails") { - let input = getInt64(-128) - let actual = Int8(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromInt64(0)_NeverTraps") { - let input = getInt64(0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromInt64(0)_NeverFails") { - let input = getInt64(0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromInt64(127)_NeverTraps") { - let input = getInt64(127) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromInt64(127)_NeverFails") { - let input = getInt64(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromInt64(128)_AlwaysTraps") { - let input = getInt64(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromInt64(128)_AlwaysFails") { - let input = getInt64(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromInt64(9223372036854775807)_AlwaysTraps") { - let input = getInt64(9223372036854775807) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromInt64(9223372036854775807)_AlwaysFails") { - let input = getInt64(9223372036854775807) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt8 +.test("FromInt64_NeverTraps") +.forEach(in: [ + (getInt8(-128), getInt64(-128)), + (getInt8(+0), getInt64(+0)), + (getInt8(+127), getInt64(+127)), +]) { + expectEqual($0.0, Int8($0.1)) +} + +FixedPointConversion_Release64_ToInt8 +.test("FromInt64_NeverFails") +.forEach(in: [ + (getInt8(-128), getInt64(-128)), + (getInt8(+0), getInt64(+0)), + (getInt8(+127), getInt64(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToInt8 +.test("FromInt64_AlwaysTraps") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-129), + getInt64(+128), + getInt64(+9223372036854775807), +]) { + expectCrashLater() + _blackHole(Int8($0)) +} + +FixedPointConversion_Release64_ToInt8 +.test("FromInt64_AlwaysFails") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-129), + getInt64(+128), + getInt64(+9223372036854775807), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt: (0)...(18446744073709551615) +// MARK: UInt: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt8.test("FromUInt(0)_NeverTraps") { - let input = getUInt(0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromUInt(0)_NeverFails") { - let input = getUInt(0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromUInt(127)_NeverTraps") { - let input = getUInt(127) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromUInt(127)_NeverFails") { - let input = getUInt(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromUInt(128)_AlwaysTraps") { - let input = getUInt(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } +FixedPointConversion_Release64_ToInt8 +.test("FromUInt_NeverTraps") +.forEach(in: [ + (getInt8(+0), getUInt(+0)), + (getInt8(+127), getUInt(+127)), +]) { + expectEqual($0.0, Int8($0.1)) } -FixedPointConversion_Release64_ToInt8.test("FromUInt(128)_AlwaysFails") { - let input = getUInt(128) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt8 +.test("FromUInt_NeverFails") +.forEach(in: [ + (getInt8(+0), getUInt(+0)), + (getInt8(+127), getUInt(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) } -FixedPointConversion_Release64_ToInt8.test("FromUInt(18446744073709551615)_AlwaysTraps") { - let input = getUInt(18446744073709551615) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } +FixedPointConversion_Release64_ToInt8 +.test("FromUInt_AlwaysTraps") +.forEach(in: [ + getUInt(+128), + getUInt(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(Int8($0)) } -FixedPointConversion_Release64_ToInt8.test("FromUInt(18446744073709551615)_AlwaysFails") { - let input = getUInt(18446744073709551615) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt8 +.test("FromUInt_AlwaysFails") +.forEach(in: [ + getUInt(+128), + getUInt(+18446744073709551615), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int: (-9223372036854775808)...(9223372036854775807) +// MARK: Int: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt8.test("FromInt(-9223372036854775808)_AlwaysTraps") { - let input = getInt(-9223372036854775808) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromInt(-9223372036854775808)_AlwaysFails") { - let input = getInt(-9223372036854775808) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromInt(-129)_AlwaysTraps") { - let input = getInt(-129) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromInt(-129)_AlwaysFails") { - let input = getInt(-129) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromInt(-128)_NeverTraps") { - let input = getInt(-128) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromInt(-128)_NeverFails") { - let input = getInt(-128) - let actual = Int8(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromInt(0)_NeverTraps") { - let input = getInt(0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromInt(0)_NeverFails") { - let input = getInt(0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromInt(127)_NeverTraps") { - let input = getInt(127) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromInt(127)_NeverFails") { - let input = getInt(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromInt(128)_AlwaysTraps") { - let input = getInt(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromInt(128)_AlwaysFails") { - let input = getInt(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromInt(9223372036854775807)_AlwaysTraps") { - let input = getInt(9223372036854775807) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromInt(9223372036854775807)_AlwaysFails") { - let input = getInt(9223372036854775807) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt8 +.test("FromInt_NeverTraps") +.forEach(in: [ + (getInt8(-128), getInt(-128)), + (getInt8(+0), getInt(+0)), + (getInt8(+127), getInt(+127)), +]) { + expectEqual($0.0, Int8($0.1)) +} + +FixedPointConversion_Release64_ToInt8 +.test("FromInt_NeverFails") +.forEach(in: [ + (getInt8(-128), getInt(-128)), + (getInt8(+0), getInt(+0)), + (getInt8(+127), getInt(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToInt8 +.test("FromInt_AlwaysTraps") +.forEach(in: [ + getInt(-9223372036854775808), + getInt(-129), + getInt(+128), + getInt(+9223372036854775807), +]) { + expectCrashLater() + _blackHole(Int8($0)) +} + +FixedPointConversion_Release64_ToInt8 +.test("FromInt_AlwaysFails") +.forEach(in: [ + getInt(-9223372036854775808), + getInt(-129), + getInt(+128), + getInt(+9223372036854775807), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float16: (-2047)...(2047) +// MARK: Float16: (-2047)...(+2047) //===----------------------------------------------------------------------===// #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -FixedPointConversion_Release64_ToInt8.test("FromFloat16(-2047)_AlwaysTraps") { - let input = getFloat16(-2047) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat16(-2047)_AlwaysFails") { - let input = getFloat16(-2047) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat16(-129)_AlwaysTraps") { - let input = getFloat16(-129) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat16(-129)_AlwaysFails") { - let input = getFloat16(-129) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat16(-128.5)_NeverTraps") { - let input = getFloat16(-128.5) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat16(-128.5)_AlwaysFails") { - let input = getFloat16(-128.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat16(-128)_NeverTraps") { - let input = getFloat16(-128) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat16(-128)_NeverFails") { - let input = getFloat16(-128) - let actual = Int8(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat16(-0.5)_NeverTraps") { - let input = getFloat16(-0.5) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat16(-0.5)_AlwaysFails") { - let input = getFloat16(-0.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat16(-0.0)_NeverTraps") { - let input = getFloat16(-0.0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat16(-0.0)_NeverFails") { - let input = getFloat16(-0.0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat16(0.0)_NeverTraps") { - let input = getFloat16(0.0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat16(0.0)_NeverFails") { - let input = getFloat16(0.0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat16(0.5)_NeverTraps") { - let input = getFloat16(0.5) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat16(0.5)_AlwaysFails") { - let input = getFloat16(0.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat16(127)_NeverTraps") { - let input = getFloat16(127) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat16(127)_NeverFails") { - let input = getFloat16(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat16(127.5)_NeverTraps") { - let input = getFloat16(127.5) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat16(127.5)_AlwaysFails") { - let input = getFloat16(127.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat16(128)_AlwaysTraps") { - let input = getFloat16(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat16(128)_AlwaysFails") { - let input = getFloat16(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat16(255.5)_AlwaysTraps") { - let input = getFloat16(255.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat16(255.5)_AlwaysFails") { - let input = getFloat16(255.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat16(2047)_AlwaysTraps") { - let input = getFloat16(2047) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat16(2047)_AlwaysFails") { - let input = getFloat16(2047) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat16(-.infinity)_AlwaysTraps") { - let input = getFloat16(-.infinity) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat16(-.infinity)_AlwaysFails") { - let input = getFloat16(-.infinity) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat16(+.infinity)_AlwaysTraps") { - let input = getFloat16(+.infinity) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat16(+.infinity)_AlwaysFails") { - let input = getFloat16(+.infinity) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat16(-.nan)_AlwaysTraps") { - let input = getFloat16(-.nan) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat16(-.nan)_AlwaysFails") { - let input = getFloat16(-.nan) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat16(+.nan)_AlwaysTraps") { - let input = getFloat16(+.nan) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat16(+.nan)_AlwaysFails") { - let input = getFloat16(+.nan) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat16(-.signalingNaN)_AlwaysTraps") { - let input = getFloat16(-.signalingNaN) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat16(-.signalingNaN)_AlwaysFails") { - let input = getFloat16(-.signalingNaN) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat16(+.signalingNaN)_AlwaysTraps") { - let input = getFloat16(+.signalingNaN) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat16(+.signalingNaN)_AlwaysFails") { - let input = getFloat16(+.signalingNaN) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt8 +.test("FromFloat16_NeverTraps") +.forEach(in: [ + (getInt8(-128), getFloat16(-128.5)), + (getInt8(-128), getFloat16(-128)), + (getInt8(+0), getFloat16(-0.5)), + (getInt8(+0), getFloat16(-0)), + (getInt8(+0), getFloat16(+0)), + (getInt8(+0), getFloat16(+0.5)), + (getInt8(+127), getFloat16(+127)), + (getInt8(+127), getFloat16(+127.5)), +]) { + expectEqual($0.0, Int8($0.1)) +} + +FixedPointConversion_Release64_ToInt8 +.test("FromFloat16_NeverFails") +.forEach(in: [ + (getInt8(-128), getFloat16(-128)), + (getInt8(+0), getFloat16(-0)), + (getInt8(+0), getFloat16(+0)), + (getInt8(+127), getFloat16(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToInt8 +.test("FromFloat16_AlwaysTraps") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-129), + getFloat16(+128), + getFloat16(+255.5), + getFloat16(+2047), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int8($0)) +} + +FixedPointConversion_Release64_ToInt8 +.test("FromFloat16_AlwaysFails") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-129), + getFloat16(-128.5), + getFloat16(-0.5), + getFloat16(+0.5), + getFloat16(+127.5), + getFloat16(+128), + getFloat16(+255.5), + getFloat16(+2047), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectNil(Int8(exactly: $0)) } } #endif // Float16 //===----------------------------------------------------------------------===// -// MARK: Float32: (-16777215)...(16777215) +// MARK: Float32: (-16777215)...(+16777215) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt8.test("FromFloat32(-16777215)_AlwaysTraps") { - let input = getFloat32(-16777215) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(-16777215)_AlwaysFails") { - let input = getFloat32(-16777215) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(-32768.5)_AlwaysTraps") { - let input = getFloat32(-32768.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(-32768.5)_AlwaysFails") { - let input = getFloat32(-32768.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(-129)_AlwaysTraps") { - let input = getFloat32(-129) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(-129)_AlwaysFails") { - let input = getFloat32(-129) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(-128.5)_NeverTraps") { - let input = getFloat32(-128.5) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(-128.5)_AlwaysFails") { - let input = getFloat32(-128.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(-128)_NeverTraps") { - let input = getFloat32(-128) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(-128)_NeverFails") { - let input = getFloat32(-128) - let actual = Int8(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(-0.5)_NeverTraps") { - let input = getFloat32(-0.5) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(-0.5)_AlwaysFails") { - let input = getFloat32(-0.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(-0.0)_NeverTraps") { - let input = getFloat32(-0.0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(-0.0)_NeverFails") { - let input = getFloat32(-0.0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(0.0)_NeverTraps") { - let input = getFloat32(0.0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(0.0)_NeverFails") { - let input = getFloat32(0.0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(0.5)_NeverTraps") { - let input = getFloat32(0.5) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(0.5)_AlwaysFails") { - let input = getFloat32(0.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(127)_NeverTraps") { - let input = getFloat32(127) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(127)_NeverFails") { - let input = getFloat32(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(127.5)_NeverTraps") { - let input = getFloat32(127.5) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(127.5)_AlwaysFails") { - let input = getFloat32(127.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(128)_AlwaysTraps") { - let input = getFloat32(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(128)_AlwaysFails") { - let input = getFloat32(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(255.5)_AlwaysTraps") { - let input = getFloat32(255.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(255.5)_AlwaysFails") { - let input = getFloat32(255.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(32767.5)_AlwaysTraps") { - let input = getFloat32(32767.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(32767.5)_AlwaysFails") { - let input = getFloat32(32767.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(65535.5)_AlwaysTraps") { - let input = getFloat32(65535.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(65535.5)_AlwaysFails") { - let input = getFloat32(65535.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(16777215)_AlwaysTraps") { - let input = getFloat32(16777215) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(16777215)_AlwaysFails") { - let input = getFloat32(16777215) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(-.infinity)_AlwaysTraps") { - let input = getFloat32(-.infinity) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(-.infinity)_AlwaysFails") { - let input = getFloat32(-.infinity) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(+.infinity)_AlwaysTraps") { - let input = getFloat32(+.infinity) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(+.infinity)_AlwaysFails") { - let input = getFloat32(+.infinity) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(-.nan)_AlwaysTraps") { - let input = getFloat32(-.nan) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(-.nan)_AlwaysFails") { - let input = getFloat32(-.nan) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(+.nan)_AlwaysTraps") { - let input = getFloat32(+.nan) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(+.nan)_AlwaysFails") { - let input = getFloat32(+.nan) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(-.signalingNaN)_AlwaysTraps") { - let input = getFloat32(-.signalingNaN) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(-.signalingNaN)_AlwaysFails") { - let input = getFloat32(-.signalingNaN) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(+.signalingNaN)_AlwaysTraps") { - let input = getFloat32(+.signalingNaN) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat32(+.signalingNaN)_AlwaysFails") { - let input = getFloat32(+.signalingNaN) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt8 +.test("FromFloat32_NeverTraps") +.forEach(in: [ + (getInt8(-128), getFloat32(-128.5)), + (getInt8(-128), getFloat32(-128)), + (getInt8(+0), getFloat32(-0.5)), + (getInt8(+0), getFloat32(+0)), + (getInt8(+0), getFloat32(-0)), + (getInt8(+0), getFloat32(+0.5)), + (getInt8(+127), getFloat32(+127)), + (getInt8(+127), getFloat32(+127.5)), +]) { + expectEqual($0.0, Int8($0.1)) +} + +FixedPointConversion_Release64_ToInt8 +.test("FromFloat32_NeverFails") +.forEach(in: [ + (getInt8(-128), getFloat32(-128)), + (getInt8(+0), getFloat32(+0)), + (getInt8(+0), getFloat32(-0)), + (getInt8(+127), getFloat32(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToInt8 +.test("FromFloat32_AlwaysTraps") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-129), + getFloat32(+128), + getFloat32(+255.5), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(+16777215), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int8($0)) +} + +FixedPointConversion_Release64_ToInt8 +.test("FromFloat32_AlwaysFails") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-129), + getFloat32(-128.5), + getFloat32(-0.5), + getFloat32(+0.5), + getFloat32(+127.5), + getFloat32(+128), + getFloat32(+255.5), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(+16777215), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float64: (-9007199254740991)...(9007199254740991) +// MARK: Float64: (-9007199254740991)...(+9007199254740991) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToInt8.test("FromFloat64(-9007199254740991)_AlwaysTraps") { - let input = getFloat64(-9007199254740991) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(-9007199254740991)_AlwaysFails") { - let input = getFloat64(-9007199254740991) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(-32768.5)_AlwaysTraps") { - let input = getFloat64(-32768.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(-32768.5)_AlwaysFails") { - let input = getFloat64(-32768.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(-129)_AlwaysTraps") { - let input = getFloat64(-129) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(-129)_AlwaysFails") { - let input = getFloat64(-129) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(-128.5)_NeverTraps") { - let input = getFloat64(-128.5) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(-128.5)_AlwaysFails") { - let input = getFloat64(-128.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(-128)_NeverTraps") { - let input = getFloat64(-128) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(-128)_NeverFails") { - let input = getFloat64(-128) - let actual = Int8(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(-0.5)_NeverTraps") { - let input = getFloat64(-0.5) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(-0.5)_AlwaysFails") { - let input = getFloat64(-0.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(-0.0)_NeverTraps") { - let input = getFloat64(-0.0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(-0.0)_NeverFails") { - let input = getFloat64(-0.0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(0.0)_NeverTraps") { - let input = getFloat64(0.0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(0.0)_NeverFails") { - let input = getFloat64(0.0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(0.5)_NeverTraps") { - let input = getFloat64(0.5) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(0.5)_AlwaysFails") { - let input = getFloat64(0.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(127)_NeverTraps") { - let input = getFloat64(127) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(127)_NeverFails") { - let input = getFloat64(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(127.5)_NeverTraps") { - let input = getFloat64(127.5) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(127.5)_AlwaysFails") { - let input = getFloat64(127.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(128)_AlwaysTraps") { - let input = getFloat64(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(128)_AlwaysFails") { - let input = getFloat64(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(255.5)_AlwaysTraps") { - let input = getFloat64(255.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(255.5)_AlwaysFails") { - let input = getFloat64(255.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(32767.5)_AlwaysTraps") { - let input = getFloat64(32767.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(32767.5)_AlwaysFails") { - let input = getFloat64(32767.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(65535.5)_AlwaysTraps") { - let input = getFloat64(65535.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(65535.5)_AlwaysFails") { - let input = getFloat64(65535.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(9007199254740991)_AlwaysTraps") { - let input = getFloat64(9007199254740991) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(9007199254740991)_AlwaysFails") { - let input = getFloat64(9007199254740991) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(-.infinity)_AlwaysTraps") { - let input = getFloat64(-.infinity) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(-.infinity)_AlwaysFails") { - let input = getFloat64(-.infinity) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(+.infinity)_AlwaysTraps") { - let input = getFloat64(+.infinity) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(+.infinity)_AlwaysFails") { - let input = getFloat64(+.infinity) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(-.nan)_AlwaysTraps") { - let input = getFloat64(-.nan) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(-.nan)_AlwaysFails") { - let input = getFloat64(-.nan) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(+.nan)_AlwaysTraps") { - let input = getFloat64(+.nan) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(+.nan)_AlwaysFails") { - let input = getFloat64(+.nan) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(-.signalingNaN)_AlwaysTraps") { - let input = getFloat64(-.signalingNaN) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(-.signalingNaN)_AlwaysFails") { - let input = getFloat64(-.signalingNaN) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(+.signalingNaN)_AlwaysTraps") { - let input = getFloat64(+.signalingNaN) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat64(+.signalingNaN)_AlwaysFails") { - let input = getFloat64(+.signalingNaN) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt8 +.test("FromFloat64_NeverTraps") +.forEach(in: [ + (getInt8(-128), getFloat64(-128.5)), + (getInt8(-128), getFloat64(-128)), + (getInt8(+0), getFloat64(-0.5)), + (getInt8(+0), getFloat64(+0)), + (getInt8(+0), getFloat64(-0)), + (getInt8(+0), getFloat64(+0.5)), + (getInt8(+127), getFloat64(+127)), + (getInt8(+127), getFloat64(+127.5)), +]) { + expectEqual($0.0, Int8($0.1)) +} + +FixedPointConversion_Release64_ToInt8 +.test("FromFloat64_NeverFails") +.forEach(in: [ + (getInt8(-128), getFloat64(-128)), + (getInt8(+0), getFloat64(+0)), + (getInt8(+0), getFloat64(-0)), + (getInt8(+127), getFloat64(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToInt8 +.test("FromFloat64_AlwaysTraps") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-129), + getFloat64(+128), + getFloat64(+255.5), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int8($0)) +} + +FixedPointConversion_Release64_ToInt8 +.test("FromFloat64_AlwaysFails") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-129), + getFloat64(-128.5), + getFloat64(-0.5), + getFloat64(+0.5), + getFloat64(+127.5), + getFloat64(+128), + getFloat64(+255.5), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectNil(Int8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float80: (-18446744073709551615)...(18446744073709551615) +// MARK: Float80: (-18446744073709551615)...(+18446744073709551615) //===----------------------------------------------------------------------===// #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) -FixedPointConversion_Release64_ToInt8.test("FromFloat80(-18446744073709551615)_AlwaysTraps") { - let input = getFloat80(-18446744073709551615) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(-18446744073709551615)_AlwaysFails") { - let input = getFloat80(-18446744073709551615) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(-32768.5)_AlwaysTraps") { - let input = getFloat80(-32768.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(-32768.5)_AlwaysFails") { - let input = getFloat80(-32768.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(-129)_AlwaysTraps") { - let input = getFloat80(-129) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(-129)_AlwaysFails") { - let input = getFloat80(-129) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(-128.5)_NeverTraps") { - let input = getFloat80(-128.5) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(-128.5)_AlwaysFails") { - let input = getFloat80(-128.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(-128)_NeverTraps") { - let input = getFloat80(-128) - let actual = Int8(input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(-128)_NeverFails") { - let input = getFloat80(-128) - let actual = Int8(exactly: input) - expectEqual(-128, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(-0.5)_NeverTraps") { - let input = getFloat80(-0.5) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(-0.5)_AlwaysFails") { - let input = getFloat80(-0.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(-0.0)_NeverTraps") { - let input = getFloat80(-0.0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(-0.0)_NeverFails") { - let input = getFloat80(-0.0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(0.0)_NeverTraps") { - let input = getFloat80(0.0) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(0.0)_NeverFails") { - let input = getFloat80(0.0) - let actual = Int8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(0.5)_NeverTraps") { - let input = getFloat80(0.5) - let actual = Int8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(0.5)_AlwaysFails") { - let input = getFloat80(0.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(127)_NeverTraps") { - let input = getFloat80(127) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(127)_NeverFails") { - let input = getFloat80(127) - let actual = Int8(exactly: input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(127.5)_NeverTraps") { - let input = getFloat80(127.5) - let actual = Int8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(127.5)_AlwaysFails") { - let input = getFloat80(127.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(128)_AlwaysTraps") { - let input = getFloat80(128) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(128)_AlwaysFails") { - let input = getFloat80(128) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(255.5)_AlwaysTraps") { - let input = getFloat80(255.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(255.5)_AlwaysFails") { - let input = getFloat80(255.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(32767.5)_AlwaysTraps") { - let input = getFloat80(32767.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(32767.5)_AlwaysFails") { - let input = getFloat80(32767.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(65535.5)_AlwaysTraps") { - let input = getFloat80(65535.5) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(65535.5)_AlwaysFails") { - let input = getFloat80(65535.5) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(18446744073709551615)_AlwaysTraps") { - let input = getFloat80(18446744073709551615) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(18446744073709551615)_AlwaysFails") { - let input = getFloat80(18446744073709551615) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(-.infinity)_AlwaysTraps") { - let input = getFloat80(-.infinity) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(-.infinity)_AlwaysFails") { - let input = getFloat80(-.infinity) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(+.infinity)_AlwaysTraps") { - let input = getFloat80(+.infinity) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(+.infinity)_AlwaysFails") { - let input = getFloat80(+.infinity) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(-.nan)_AlwaysTraps") { - let input = getFloat80(-.nan) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(-.nan)_AlwaysFails") { - let input = getFloat80(-.nan) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(+.nan)_AlwaysTraps") { - let input = getFloat80(+.nan) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(+.nan)_AlwaysFails") { - let input = getFloat80(+.nan) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(-.signalingNaN)_AlwaysTraps") { - let input = getFloat80(-.signalingNaN) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(-.signalingNaN)_AlwaysFails") { - let input = getFloat80(-.signalingNaN) - let actual = Int8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(+.signalingNaN)_AlwaysTraps") { - let input = getFloat80(+.signalingNaN) - expectCrash { - let actual = Int8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToInt8.test("FromFloat80(+.signalingNaN)_AlwaysFails") { - let input = getFloat80(+.signalingNaN) - let actual = Int8(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToInt8 +.test("FromFloat80_NeverTraps") +.forEach(in: [ + (getInt8(-128), getFloat80(-128.5)), + (getInt8(-128), getFloat80(-128)), + (getInt8(+0), getFloat80(-0.5)), + (getInt8(+0), getFloat80(-0)), + (getInt8(+0), getFloat80(+0)), + (getInt8(+0), getFloat80(+0.5)), + (getInt8(+127), getFloat80(+127)), + (getInt8(+127), getFloat80(+127.5)), +]) { + expectEqual($0.0, Int8($0.1)) +} + +FixedPointConversion_Release64_ToInt8 +.test("FromFloat80_NeverFails") +.forEach(in: [ + (getInt8(-128), getFloat80(-128)), + (getInt8(+0), getFloat80(-0)), + (getInt8(+0), getFloat80(+0)), + (getInt8(+127), getFloat80(+127)), +]) { + expectEqual($0.0, Int8(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToInt8 +.test("FromFloat80_AlwaysTraps") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-129), + getFloat80(+128), + getFloat80(+255.5), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(Int8($0)) +} + +FixedPointConversion_Release64_ToInt8 +.test("FromFloat80_AlwaysFails") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-129), + getFloat80(-128.5), + getFloat80(-0.5), + getFloat80(+0.5), + getFloat80(+127.5), + getFloat80(+128), + getFloat80(+255.5), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectNil(Int8(exactly: $0)) } #endif // Float80 diff --git a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release64_ToUInt.swift b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release64_ToUInt.swift index 3b318ed82ba75..e0510774f620f 100644 --- a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release64_ToUInt.swift +++ b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release64_ToUInt.swift @@ -14,1464 +14,609 @@ import StdlibUnittest -let FixedPointConversion_Release64_ToUInt = TestSuite("FixedPointConversion_Release64_ToUInt") +let FixedPointConversion_Release64_ToUInt = TestSuite( + "FixedPointConversion_Release64_ToUInt" +) //===----------------------------------------------------------------------===// -// MARK: UInt8: (0)...(255) +// MARK: UInt8: (+0)...(+255) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt.test("FromUInt8(0)_NeverTraps") { - let input = getUInt8(0) - let actual = UInt(input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt +.test("FromUInt8_NeverTraps") +.forEach(in: [ + (getUInt(+0), getUInt8(+0)), + (getUInt(+255), getUInt8(+255)), +]) { + expectEqual($0.0, UInt($0.1)) } -FixedPointConversion_Release64_ToUInt.test("FromUInt8(0)_NeverFails") { - let input = getUInt8(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromUInt8(255)_NeverTraps") { - let input = getUInt8(255) - let actual = UInt(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromUInt8(255)_NeverFails") { - let input = getUInt8(255) - let actual = UInt(exactly: input) - expectEqual(255, actual) +FixedPointConversion_Release64_ToUInt +.test("FromUInt8_NeverFails") +.forEach(in: [ + (getUInt(+0), getUInt8(+0)), + (getUInt(+255), getUInt8(+255)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int8: (-128)...(127) +// MARK: Int8: (-128)...(+127) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt.test("FromInt8(-128)_AlwaysTraps") { - let input = getInt8(-128) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromInt8(-128)_AlwaysFails") { - let input = getInt8(-128) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromInt8(-1)_AlwaysTraps") { - let input = getInt8(-1) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromInt8(-1)_AlwaysFails") { - let input = getInt8(-1) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromInt8(0)_NeverTraps") { - let input = getInt8(0) - let actual = UInt(input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt +.test("FromInt8_NeverTraps") +.forEach(in: [ + (getUInt(+0), getInt8(+0)), + (getUInt(+127), getInt8(+127)), +]) { + expectEqual($0.0, UInt($0.1)) } -FixedPointConversion_Release64_ToUInt.test("FromInt8(0)_NeverFails") { - let input = getInt8(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt +.test("FromInt8_NeverFails") +.forEach(in: [ + (getUInt(+0), getInt8(+0)), + (getUInt(+127), getInt8(+127)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) } -FixedPointConversion_Release64_ToUInt.test("FromInt8(127)_NeverTraps") { - let input = getInt8(127) - let actual = UInt(input) - expectEqual(127, actual) +FixedPointConversion_Release64_ToUInt +.test("FromInt8_AlwaysTraps") +.forEach(in: [ + getInt8(-128), + getInt8(-1), +]) { + expectCrashLater() + _blackHole(UInt($0)) } -FixedPointConversion_Release64_ToUInt.test("FromInt8(127)_NeverFails") { - let input = getInt8(127) - let actual = UInt(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Release64_ToUInt +.test("FromInt8_AlwaysFails") +.forEach(in: [ + getInt8(-128), + getInt8(-1), +]) { + expectNil(UInt(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt16: (0)...(65535) +// MARK: UInt16: (+0)...(+65535) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt.test("FromUInt16(0)_NeverTraps") { - let input = getUInt16(0) - let actual = UInt(input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt +.test("FromUInt16_NeverTraps") +.forEach(in: [ + (getUInt(+0), getUInt16(+0)), + (getUInt(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, UInt($0.1)) } -FixedPointConversion_Release64_ToUInt.test("FromUInt16(0)_NeverFails") { - let input = getUInt16(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromUInt16(65535)_NeverTraps") { - let input = getUInt16(65535) - let actual = UInt(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromUInt16(65535)_NeverFails") { - let input = getUInt16(65535) - let actual = UInt(exactly: input) - expectEqual(65535, actual) +FixedPointConversion_Release64_ToUInt +.test("FromUInt16_NeverFails") +.forEach(in: [ + (getUInt(+0), getUInt16(+0)), + (getUInt(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int16: (-32768)...(32767) +// MARK: Int16: (-32768)...(+32767) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt.test("FromInt16(-32768)_AlwaysTraps") { - let input = getInt16(-32768) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromInt16(-32768)_AlwaysFails") { - let input = getInt16(-32768) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromInt16(-1)_AlwaysTraps") { - let input = getInt16(-1) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromInt16(-1)_AlwaysFails") { - let input = getInt16(-1) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromInt16(0)_NeverTraps") { - let input = getInt16(0) - let actual = UInt(input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt +.test("FromInt16_NeverTraps") +.forEach(in: [ + (getUInt(+0), getInt16(+0)), + (getUInt(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, UInt($0.1)) } -FixedPointConversion_Release64_ToUInt.test("FromInt16(0)_NeverFails") { - let input = getInt16(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt +.test("FromInt16_NeverFails") +.forEach(in: [ + (getUInt(+0), getInt16(+0)), + (getUInt(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) } -FixedPointConversion_Release64_ToUInt.test("FromInt16(32767)_NeverTraps") { - let input = getInt16(32767) - let actual = UInt(input) - expectEqual(32767, actual) +FixedPointConversion_Release64_ToUInt +.test("FromInt16_AlwaysTraps") +.forEach(in: [ + getInt16(-32768), + getInt16(-1), +]) { + expectCrashLater() + _blackHole(UInt($0)) } -FixedPointConversion_Release64_ToUInt.test("FromInt16(32767)_NeverFails") { - let input = getInt16(32767) - let actual = UInt(exactly: input) - expectEqual(32767, actual) +FixedPointConversion_Release64_ToUInt +.test("FromInt16_AlwaysFails") +.forEach(in: [ + getInt16(-32768), + getInt16(-1), +]) { + expectNil(UInt(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt32: (0)...(4294967295) +// MARK: UInt32: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt.test("FromUInt32(0)_NeverTraps") { - let input = getUInt32(0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromUInt32(0)_NeverFails") { - let input = getUInt32(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt +.test("FromUInt32_NeverTraps") +.forEach(in: [ + (getUInt(+0), getUInt32(+0)), + (getUInt(+4294967295), getUInt32(+4294967295)), +]) { + expectEqual($0.0, UInt($0.1)) } -FixedPointConversion_Release64_ToUInt.test("FromUInt32(4294967295)_NeverTraps") { - let input = getUInt32(4294967295) - let actual = UInt(input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromUInt32(4294967295)_NeverFails") { - let input = getUInt32(4294967295) - let actual = UInt(exactly: input) - expectEqual(4294967295, actual) +FixedPointConversion_Release64_ToUInt +.test("FromUInt32_NeverFails") +.forEach(in: [ + (getUInt(+0), getUInt32(+0)), + (getUInt(+4294967295), getUInt32(+4294967295)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int32: (-2147483648)...(2147483647) +// MARK: Int32: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt.test("FromInt32(-2147483648)_AlwaysTraps") { - let input = getInt32(-2147483648) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromInt32(-2147483648)_AlwaysFails") { - let input = getInt32(-2147483648) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromInt32(-1)_AlwaysTraps") { - let input = getInt32(-1) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } +FixedPointConversion_Release64_ToUInt +.test("FromInt32_NeverTraps") +.forEach(in: [ + (getUInt(+0), getInt32(+0)), + (getUInt(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, UInt($0.1)) } -FixedPointConversion_Release64_ToUInt.test("FromInt32(-1)_AlwaysFails") { - let input = getInt32(-1) - let actual = UInt(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt +.test("FromInt32_NeverFails") +.forEach(in: [ + (getUInt(+0), getInt32(+0)), + (getUInt(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) } -FixedPointConversion_Release64_ToUInt.test("FromInt32(0)_NeverTraps") { - let input = getInt32(0) - let actual = UInt(input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt +.test("FromInt32_AlwaysTraps") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-1), +]) { + expectCrashLater() + _blackHole(UInt($0)) } -FixedPointConversion_Release64_ToUInt.test("FromInt32(0)_NeverFails") { - let input = getInt32(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromInt32(2147483647)_NeverTraps") { - let input = getInt32(2147483647) - let actual = UInt(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromInt32(2147483647)_NeverFails") { - let input = getInt32(2147483647) - let actual = UInt(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Release64_ToUInt +.test("FromInt32_AlwaysFails") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-1), +]) { + expectNil(UInt(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt64: (0)...(18446744073709551615) +// MARK: UInt64: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt.test("FromUInt64(0)_NeverTraps") { - let input = getUInt64(0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromUInt64(0)_NeverFails") { - let input = getUInt64(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt +.test("FromUInt64_NeverTraps") +.forEach(in: [ + (getUInt(+0), getUInt64(+0)), + (getUInt(+18446744073709551615), getUInt64(+18446744073709551615)), +]) { + expectEqual($0.0, UInt($0.1)) } -FixedPointConversion_Release64_ToUInt.test("FromUInt64(18446744073709551615)_NeverTraps") { - let input = getUInt64(18446744073709551615) - let actual = UInt(input) - expectEqual(18446744073709551615, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromUInt64(18446744073709551615)_NeverFails") { - let input = getUInt64(18446744073709551615) - let actual = UInt(exactly: input) - expectEqual(18446744073709551615, actual) +FixedPointConversion_Release64_ToUInt +.test("FromUInt64_NeverFails") +.forEach(in: [ + (getUInt(+0), getUInt64(+0)), + (getUInt(+18446744073709551615), getUInt64(+18446744073709551615)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int64: (-9223372036854775808)...(9223372036854775807) +// MARK: Int64: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt.test("FromInt64(-9223372036854775808)_AlwaysTraps") { - let input = getInt64(-9223372036854775808) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromInt64(-9223372036854775808)_AlwaysFails") { - let input = getInt64(-9223372036854775808) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromInt64(-1)_AlwaysTraps") { - let input = getInt64(-1) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromInt64(-1)_AlwaysFails") { - let input = getInt64(-1) - let actual = UInt(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt +.test("FromInt64_NeverTraps") +.forEach(in: [ + (getUInt(+0), getInt64(+0)), + (getUInt(+9223372036854775807), getInt64(+9223372036854775807)), +]) { + expectEqual($0.0, UInt($0.1)) } -FixedPointConversion_Release64_ToUInt.test("FromInt64(0)_NeverTraps") { - let input = getInt64(0) - let actual = UInt(input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt +.test("FromInt64_NeverFails") +.forEach(in: [ + (getUInt(+0), getInt64(+0)), + (getUInt(+9223372036854775807), getInt64(+9223372036854775807)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) } -FixedPointConversion_Release64_ToUInt.test("FromInt64(0)_NeverFails") { - let input = getInt64(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt +.test("FromInt64_AlwaysTraps") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-1), +]) { + expectCrashLater() + _blackHole(UInt($0)) } -FixedPointConversion_Release64_ToUInt.test("FromInt64(9223372036854775807)_NeverTraps") { - let input = getInt64(9223372036854775807) - let actual = UInt(input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromInt64(9223372036854775807)_NeverFails") { - let input = getInt64(9223372036854775807) - let actual = UInt(exactly: input) - expectEqual(9223372036854775807, actual) +FixedPointConversion_Release64_ToUInt +.test("FromInt64_AlwaysFails") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-1), +]) { + expectNil(UInt(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt: (0)...(18446744073709551615) +// MARK: UInt: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt.test("FromUInt(0)_NeverTraps") { - let input = getUInt(0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromUInt(0)_NeverFails") { - let input = getUInt(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromUInt(18446744073709551615)_NeverTraps") { - let input = getUInt(18446744073709551615) - let actual = UInt(input) - expectEqual(18446744073709551615, actual) +FixedPointConversion_Release64_ToUInt +.test("FromUInt_NeverTraps") +.forEach(in: [ + (getUInt(+0), getUInt(+0)), + (getUInt(+18446744073709551615), getUInt(+18446744073709551615)), +]) { + expectEqual($0.0, UInt($0.1)) } -FixedPointConversion_Release64_ToUInt.test("FromUInt(18446744073709551615)_NeverFails") { - let input = getUInt(18446744073709551615) - let actual = UInt(exactly: input) - expectEqual(18446744073709551615, actual) +FixedPointConversion_Release64_ToUInt +.test("FromUInt_NeverFails") +.forEach(in: [ + (getUInt(+0), getUInt(+0)), + (getUInt(+18446744073709551615), getUInt(+18446744073709551615)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int: (-9223372036854775808)...(9223372036854775807) +// MARK: Int: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt.test("FromInt(-9223372036854775808)_AlwaysTraps") { - let input = getInt(-9223372036854775808) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromInt(-9223372036854775808)_AlwaysFails") { - let input = getInt(-9223372036854775808) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromInt(-1)_AlwaysTraps") { - let input = getInt(-1) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromInt(-1)_AlwaysFails") { - let input = getInt(-1) - let actual = UInt(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt +.test("FromInt_NeverTraps") +.forEach(in: [ + (getUInt(+0), getInt(+0)), + (getUInt(+9223372036854775807), getInt(+9223372036854775807)), +]) { + expectEqual($0.0, UInt($0.1)) } -FixedPointConversion_Release64_ToUInt.test("FromInt(0)_NeverTraps") { - let input = getInt(0) - let actual = UInt(input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt +.test("FromInt_NeverFails") +.forEach(in: [ + (getUInt(+0), getInt(+0)), + (getUInt(+9223372036854775807), getInt(+9223372036854775807)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) } -FixedPointConversion_Release64_ToUInt.test("FromInt(0)_NeverFails") { - let input = getInt(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt +.test("FromInt_AlwaysTraps") +.forEach(in: [ + getInt(-9223372036854775808), + getInt(-1), +]) { + expectCrashLater() + _blackHole(UInt($0)) } -FixedPointConversion_Release64_ToUInt.test("FromInt(9223372036854775807)_NeverTraps") { - let input = getInt(9223372036854775807) - let actual = UInt(input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromInt(9223372036854775807)_NeverFails") { - let input = getInt(9223372036854775807) - let actual = UInt(exactly: input) - expectEqual(9223372036854775807, actual) +FixedPointConversion_Release64_ToUInt +.test("FromInt_AlwaysFails") +.forEach(in: [ + getInt(-9223372036854775808), + getInt(-1), +]) { + expectNil(UInt(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float16: (-2047)...(2047) +// MARK: Float16: (-2047)...(+2047) //===----------------------------------------------------------------------===// #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -FixedPointConversion_Release64_ToUInt.test("FromFloat16(-2047)_AlwaysTraps") { - let input = getFloat16(-2047) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat16(-2047)_AlwaysFails") { - let input = getFloat16(-2047) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat16(-128.5)_AlwaysTraps") { - let input = getFloat16(-128.5) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat16(-128.5)_AlwaysFails") { - let input = getFloat16(-128.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat16(-1)_AlwaysTraps") { - let input = getFloat16(-1) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat16(-1)_AlwaysFails") { - let input = getFloat16(-1) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat16(-0.5)_NeverTraps") { - let input = getFloat16(-0.5) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat16(-0.5)_AlwaysFails") { - let input = getFloat16(-0.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat16(0)_NeverTraps") { - let input = getFloat16(0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat16(0)_NeverFails") { - let input = getFloat16(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat16(-0.0)_NeverTraps") { - let input = getFloat16(-0.0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat16(-0.0)_NeverFails") { - let input = getFloat16(-0.0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat16(0.0)_NeverTraps") { - let input = getFloat16(0.0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat16(0.0)_NeverFails") { - let input = getFloat16(0.0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat16(0.5)_NeverTraps") { - let input = getFloat16(0.5) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat16(0.5)_AlwaysFails") { - let input = getFloat16(0.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat16(127.5)_NeverTraps") { - let input = getFloat16(127.5) - let actual = UInt(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat16(127.5)_AlwaysFails") { - let input = getFloat16(127.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat16(255.5)_NeverTraps") { - let input = getFloat16(255.5) - let actual = UInt(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat16(255.5)_AlwaysFails") { - let input = getFloat16(255.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat16(2047)_NeverTraps") { - let input = getFloat16(2047) - let actual = UInt(input) - expectEqual(2047, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat16(2047)_NeverFails") { - let input = getFloat16(2047) - let actual = UInt(exactly: input) - expectEqual(2047, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat16(-.infinity)_AlwaysTraps") { - let input = getFloat16(-.infinity) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat16(-.infinity)_AlwaysFails") { - let input = getFloat16(-.infinity) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat16(+.infinity)_AlwaysTraps") { - let input = getFloat16(+.infinity) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat16(+.infinity)_AlwaysFails") { - let input = getFloat16(+.infinity) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat16(-.nan)_AlwaysTraps") { - let input = getFloat16(-.nan) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat16(-.nan)_AlwaysFails") { - let input = getFloat16(-.nan) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat16(+.nan)_AlwaysTraps") { - let input = getFloat16(+.nan) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat16(+.nan)_AlwaysFails") { - let input = getFloat16(+.nan) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat16(-.signalingNaN)_AlwaysTraps") { - let input = getFloat16(-.signalingNaN) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat16(-.signalingNaN)_AlwaysFails") { - let input = getFloat16(-.signalingNaN) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat16(+.signalingNaN)_AlwaysTraps") { - let input = getFloat16(+.signalingNaN) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat16(+.signalingNaN)_AlwaysFails") { - let input = getFloat16(+.signalingNaN) - let actual = UInt(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt +.test("FromFloat16_NeverTraps") +.forEach(in: [ + (getUInt(+0), getFloat16(-0.5)), + (getUInt(+0), getFloat16(+0)), + (getUInt(+0), getFloat16(-0)), + (getUInt(+0), getFloat16(+0.5)), + (getUInt(+127), getFloat16(+127.5)), + (getUInt(+255), getFloat16(+255.5)), + (getUInt(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, UInt($0.1)) +} + +FixedPointConversion_Release64_ToUInt +.test("FromFloat16_NeverFails") +.forEach(in: [ + (getUInt(+0), getFloat16(+0)), + (getUInt(+0), getFloat16(-0)), + (getUInt(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToUInt +.test("FromFloat16_AlwaysTraps") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-128.5), + getFloat16(-1), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt($0)) +} + +FixedPointConversion_Release64_ToUInt +.test("FromFloat16_AlwaysFails") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-128.5), + getFloat16(-1), + getFloat16(-0.5), + getFloat16(+0.5), + getFloat16(+127.5), + getFloat16(+255.5), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectNil(UInt(exactly: $0)) } } #endif // Float16 //===----------------------------------------------------------------------===// -// MARK: Float32: (-16777215)...(16777215) +// MARK: Float32: (-16777215)...(+16777215) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt.test("FromFloat32(-16777215)_AlwaysTraps") { - let input = getFloat32(-16777215) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat32(-16777215)_AlwaysFails") { - let input = getFloat32(-16777215) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat32(-32768.5)_AlwaysTraps") { - let input = getFloat32(-32768.5) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat32(-32768.5)_AlwaysFails") { - let input = getFloat32(-32768.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat32(-128.5)_AlwaysTraps") { - let input = getFloat32(-128.5) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat32(-128.5)_AlwaysFails") { - let input = getFloat32(-128.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat32(-1)_AlwaysTraps") { - let input = getFloat32(-1) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat32(-1)_AlwaysFails") { - let input = getFloat32(-1) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat32(-0.5)_NeverTraps") { - let input = getFloat32(-0.5) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat32(-0.5)_AlwaysFails") { - let input = getFloat32(-0.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat32(0)_NeverTraps") { - let input = getFloat32(0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat32(0)_NeverFails") { - let input = getFloat32(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat32(-0.0)_NeverTraps") { - let input = getFloat32(-0.0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat32(-0.0)_NeverFails") { - let input = getFloat32(-0.0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat32(0.0)_NeverTraps") { - let input = getFloat32(0.0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat32(0.0)_NeverFails") { - let input = getFloat32(0.0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat32(0.5)_NeverTraps") { - let input = getFloat32(0.5) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat32(0.5)_AlwaysFails") { - let input = getFloat32(0.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat32(127.5)_NeverTraps") { - let input = getFloat32(127.5) - let actual = UInt(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat32(127.5)_AlwaysFails") { - let input = getFloat32(127.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat32(255.5)_NeverTraps") { - let input = getFloat32(255.5) - let actual = UInt(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat32(255.5)_AlwaysFails") { - let input = getFloat32(255.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat32(32767.5)_NeverTraps") { - let input = getFloat32(32767.5) - let actual = UInt(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat32(32767.5)_AlwaysFails") { - let input = getFloat32(32767.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat32(65535.5)_NeverTraps") { - let input = getFloat32(65535.5) - let actual = UInt(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat32(65535.5)_AlwaysFails") { - let input = getFloat32(65535.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat32(16777215)_NeverTraps") { - let input = getFloat32(16777215) - let actual = UInt(input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat32(16777215)_NeverFails") { - let input = getFloat32(16777215) - let actual = UInt(exactly: input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat32(-.infinity)_AlwaysTraps") { - let input = getFloat32(-.infinity) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat32(-.infinity)_AlwaysFails") { - let input = getFloat32(-.infinity) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat32(+.infinity)_AlwaysTraps") { - let input = getFloat32(+.infinity) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat32(+.infinity)_AlwaysFails") { - let input = getFloat32(+.infinity) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat32(-.nan)_AlwaysTraps") { - let input = getFloat32(-.nan) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat32(-.nan)_AlwaysFails") { - let input = getFloat32(-.nan) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat32(+.nan)_AlwaysTraps") { - let input = getFloat32(+.nan) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat32(+.nan)_AlwaysFails") { - let input = getFloat32(+.nan) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat32(-.signalingNaN)_AlwaysTraps") { - let input = getFloat32(-.signalingNaN) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat32(-.signalingNaN)_AlwaysFails") { - let input = getFloat32(-.signalingNaN) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat32(+.signalingNaN)_AlwaysTraps") { - let input = getFloat32(+.signalingNaN) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat32(+.signalingNaN)_AlwaysFails") { - let input = getFloat32(+.signalingNaN) - let actual = UInt(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt +.test("FromFloat32_NeverTraps") +.forEach(in: [ + (getUInt(+0), getFloat32(-0.5)), + (getUInt(+0), getFloat32(+0)), + (getUInt(+0), getFloat32(-0)), + (getUInt(+0), getFloat32(+0.5)), + (getUInt(+127), getFloat32(+127.5)), + (getUInt(+255), getFloat32(+255.5)), + (getUInt(+32767), getFloat32(+32767.5)), + (getUInt(+65535), getFloat32(+65535.5)), + (getUInt(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, UInt($0.1)) +} + +FixedPointConversion_Release64_ToUInt +.test("FromFloat32_NeverFails") +.forEach(in: [ + (getUInt(+0), getFloat32(+0)), + (getUInt(+0), getFloat32(-0)), + (getUInt(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToUInt +.test("FromFloat32_AlwaysTraps") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-1), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt($0)) +} + +FixedPointConversion_Release64_ToUInt +.test("FromFloat32_AlwaysFails") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-1), + getFloat32(-0.5), + getFloat32(+0.5), + getFloat32(+127.5), + getFloat32(+255.5), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectNil(UInt(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float64: (-9007199254740991)...(9007199254740991) +// MARK: Float64: (-9007199254740991)...(+9007199254740991) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt.test("FromFloat64(-9007199254740991)_AlwaysTraps") { - let input = getFloat64(-9007199254740991) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat64(-9007199254740991)_AlwaysFails") { - let input = getFloat64(-9007199254740991) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat64(-32768.5)_AlwaysTraps") { - let input = getFloat64(-32768.5) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat64(-32768.5)_AlwaysFails") { - let input = getFloat64(-32768.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat64(-128.5)_AlwaysTraps") { - let input = getFloat64(-128.5) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat64(-128.5)_AlwaysFails") { - let input = getFloat64(-128.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat64(-1)_AlwaysTraps") { - let input = getFloat64(-1) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat64(-1)_AlwaysFails") { - let input = getFloat64(-1) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat64(-0.5)_NeverTraps") { - let input = getFloat64(-0.5) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat64(-0.5)_AlwaysFails") { - let input = getFloat64(-0.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat64(0)_NeverTraps") { - let input = getFloat64(0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat64(0)_NeverFails") { - let input = getFloat64(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat64(-0.0)_NeverTraps") { - let input = getFloat64(-0.0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat64(-0.0)_NeverFails") { - let input = getFloat64(-0.0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat64(0.0)_NeverTraps") { - let input = getFloat64(0.0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat64(0.0)_NeverFails") { - let input = getFloat64(0.0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat64(0.5)_NeverTraps") { - let input = getFloat64(0.5) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat64(0.5)_AlwaysFails") { - let input = getFloat64(0.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat64(127.5)_NeverTraps") { - let input = getFloat64(127.5) - let actual = UInt(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat64(127.5)_AlwaysFails") { - let input = getFloat64(127.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat64(255.5)_NeverTraps") { - let input = getFloat64(255.5) - let actual = UInt(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat64(255.5)_AlwaysFails") { - let input = getFloat64(255.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat64(32767.5)_NeverTraps") { - let input = getFloat64(32767.5) - let actual = UInt(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat64(32767.5)_AlwaysFails") { - let input = getFloat64(32767.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat64(65535.5)_NeverTraps") { - let input = getFloat64(65535.5) - let actual = UInt(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat64(65535.5)_AlwaysFails") { - let input = getFloat64(65535.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat64(9007199254740991)_NeverTraps") { - let input = getFloat64(9007199254740991) - let actual = UInt(input) - expectEqual(9007199254740991, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat64(9007199254740991)_NeverFails") { - let input = getFloat64(9007199254740991) - let actual = UInt(exactly: input) - expectEqual(9007199254740991, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat64(-.infinity)_AlwaysTraps") { - let input = getFloat64(-.infinity) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat64(-.infinity)_AlwaysFails") { - let input = getFloat64(-.infinity) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat64(+.infinity)_AlwaysTraps") { - let input = getFloat64(+.infinity) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat64(+.infinity)_AlwaysFails") { - let input = getFloat64(+.infinity) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat64(-.nan)_AlwaysTraps") { - let input = getFloat64(-.nan) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat64(-.nan)_AlwaysFails") { - let input = getFloat64(-.nan) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat64(+.nan)_AlwaysTraps") { - let input = getFloat64(+.nan) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat64(+.nan)_AlwaysFails") { - let input = getFloat64(+.nan) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat64(-.signalingNaN)_AlwaysTraps") { - let input = getFloat64(-.signalingNaN) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat64(-.signalingNaN)_AlwaysFails") { - let input = getFloat64(-.signalingNaN) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat64(+.signalingNaN)_AlwaysTraps") { - let input = getFloat64(+.signalingNaN) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat64(+.signalingNaN)_AlwaysFails") { - let input = getFloat64(+.signalingNaN) - let actual = UInt(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt +.test("FromFloat64_NeverTraps") +.forEach(in: [ + (getUInt(+0), getFloat64(-0.5)), + (getUInt(+0), getFloat64(+0)), + (getUInt(+0), getFloat64(-0)), + (getUInt(+0), getFloat64(+0.5)), + (getUInt(+127), getFloat64(+127.5)), + (getUInt(+255), getFloat64(+255.5)), + (getUInt(+32767), getFloat64(+32767.5)), + (getUInt(+65535), getFloat64(+65535.5)), + (getUInt(+9007199254740991), getFloat64(+9007199254740991)), +]) { + expectEqual($0.0, UInt($0.1)) +} + +FixedPointConversion_Release64_ToUInt +.test("FromFloat64_NeverFails") +.forEach(in: [ + (getUInt(+0), getFloat64(+0)), + (getUInt(+0), getFloat64(-0)), + (getUInt(+9007199254740991), getFloat64(+9007199254740991)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToUInt +.test("FromFloat64_AlwaysTraps") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-1), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt($0)) +} + +FixedPointConversion_Release64_ToUInt +.test("FromFloat64_AlwaysFails") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-1), + getFloat64(-0.5), + getFloat64(+0.5), + getFloat64(+127.5), + getFloat64(+255.5), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectNil(UInt(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float80: (-18446744073709551615)...(18446744073709551615) +// MARK: Float80: (-18446744073709551615)...(+18446744073709551615) //===----------------------------------------------------------------------===// #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) -FixedPointConversion_Release64_ToUInt.test("FromFloat80(-18446744073709551615)_AlwaysTraps") { - let input = getFloat80(-18446744073709551615) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(-18446744073709551615)_AlwaysFails") { - let input = getFloat80(-18446744073709551615) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(-32768.5)_AlwaysTraps") { - let input = getFloat80(-32768.5) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(-32768.5)_AlwaysFails") { - let input = getFloat80(-32768.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(-128.5)_AlwaysTraps") { - let input = getFloat80(-128.5) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(-128.5)_AlwaysFails") { - let input = getFloat80(-128.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(-1)_AlwaysTraps") { - let input = getFloat80(-1) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(-1)_AlwaysFails") { - let input = getFloat80(-1) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(-0.5)_NeverTraps") { - let input = getFloat80(-0.5) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(-0.5)_AlwaysFails") { - let input = getFloat80(-0.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(0)_NeverTraps") { - let input = getFloat80(0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(0)_NeverFails") { - let input = getFloat80(0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(-0.0)_NeverTraps") { - let input = getFloat80(-0.0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(-0.0)_NeverFails") { - let input = getFloat80(-0.0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(0.0)_NeverTraps") { - let input = getFloat80(0.0) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(0.0)_NeverFails") { - let input = getFloat80(0.0) - let actual = UInt(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(0.5)_NeverTraps") { - let input = getFloat80(0.5) - let actual = UInt(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(0.5)_AlwaysFails") { - let input = getFloat80(0.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(127.5)_NeverTraps") { - let input = getFloat80(127.5) - let actual = UInt(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(127.5)_AlwaysFails") { - let input = getFloat80(127.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(255.5)_NeverTraps") { - let input = getFloat80(255.5) - let actual = UInt(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(255.5)_AlwaysFails") { - let input = getFloat80(255.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(32767.5)_NeverTraps") { - let input = getFloat80(32767.5) - let actual = UInt(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(32767.5)_AlwaysFails") { - let input = getFloat80(32767.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(65535.5)_NeverTraps") { - let input = getFloat80(65535.5) - let actual = UInt(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(65535.5)_AlwaysFails") { - let input = getFloat80(65535.5) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(18446744073709551615)_NeverTraps") { - let input = getFloat80(18446744073709551615) - let actual = UInt(input) - expectEqual(18446744073709551615, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(18446744073709551615)_NeverFails") { - let input = getFloat80(18446744073709551615) - let actual = UInt(exactly: input) - expectEqual(18446744073709551615, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(18446744073709551615)_NeverTraps") { - let input = getFloat80(18446744073709551615) - let actual = UInt(input) - expectEqual(18446744073709551615, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(18446744073709551615)_NeverFails") { - let input = getFloat80(18446744073709551615) - let actual = UInt(exactly: input) - expectEqual(18446744073709551615, actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(-.infinity)_AlwaysTraps") { - let input = getFloat80(-.infinity) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(-.infinity)_AlwaysFails") { - let input = getFloat80(-.infinity) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(+.infinity)_AlwaysTraps") { - let input = getFloat80(+.infinity) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(+.infinity)_AlwaysFails") { - let input = getFloat80(+.infinity) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(-.nan)_AlwaysTraps") { - let input = getFloat80(-.nan) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(-.nan)_AlwaysFails") { - let input = getFloat80(-.nan) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(+.nan)_AlwaysTraps") { - let input = getFloat80(+.nan) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(+.nan)_AlwaysFails") { - let input = getFloat80(+.nan) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(-.signalingNaN)_AlwaysTraps") { - let input = getFloat80(-.signalingNaN) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(-.signalingNaN)_AlwaysFails") { - let input = getFloat80(-.signalingNaN) - let actual = UInt(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(+.signalingNaN)_AlwaysTraps") { - let input = getFloat80(+.signalingNaN) - expectCrash { - let actual = UInt(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt.test("FromFloat80(+.signalingNaN)_AlwaysFails") { - let input = getFloat80(+.signalingNaN) - let actual = UInt(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt +.test("FromFloat80_NeverTraps") +.forEach(in: [ + (getUInt(+0), getFloat80(-0.5)), + (getUInt(+0), getFloat80(+0)), + (getUInt(+0), getFloat80(-0)), + (getUInt(+0), getFloat80(+0.5)), + (getUInt(+127), getFloat80(+127.5)), + (getUInt(+255), getFloat80(+255.5)), + (getUInt(+32767), getFloat80(+32767.5)), + (getUInt(+65535), getFloat80(+65535.5)), + (getUInt(+18446744073709551615), getFloat80(+18446744073709551615)), +]) { + expectEqual($0.0, UInt($0.1)) +} + +FixedPointConversion_Release64_ToUInt +.test("FromFloat80_NeverFails") +.forEach(in: [ + (getUInt(+0), getFloat80(+0)), + (getUInt(+0), getFloat80(-0)), + (getUInt(+18446744073709551615), getFloat80(+18446744073709551615)), +]) { + expectEqual($0.0, UInt(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToUInt +.test("FromFloat80_AlwaysTraps") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-1), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt($0)) +} + +FixedPointConversion_Release64_ToUInt +.test("FromFloat80_AlwaysFails") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-1), + getFloat80(-0.5), + getFloat80(+0.5), + getFloat80(+127.5), + getFloat80(+255.5), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectNil(UInt(exactly: $0)) } #endif // Float80 diff --git a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release64_ToUInt16.swift b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release64_ToUInt16.swift index 52543389f4009..dacac898c1889 100644 --- a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release64_ToUInt16.swift +++ b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release64_ToUInt16.swift @@ -14,1704 +14,690 @@ import StdlibUnittest -let FixedPointConversion_Release64_ToUInt16 = TestSuite("FixedPointConversion_Release64_ToUInt16") +let FixedPointConversion_Release64_ToUInt16 = TestSuite( + "FixedPointConversion_Release64_ToUInt16" +) //===----------------------------------------------------------------------===// -// MARK: UInt8: (0)...(255) +// MARK: UInt8: (+0)...(+255) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt16.test("FromUInt8(0)_NeverTraps") { - let input = getUInt8(0) - let actual = UInt16(input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt16 +.test("FromUInt8_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getUInt8(+0)), + (getUInt16(+255), getUInt8(+255)), +]) { + expectEqual($0.0, UInt16($0.1)) } -FixedPointConversion_Release64_ToUInt16.test("FromUInt8(0)_NeverFails") { - let input = getUInt8(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromUInt8(255)_NeverTraps") { - let input = getUInt8(255) - let actual = UInt16(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromUInt8(255)_NeverFails") { - let input = getUInt8(255) - let actual = UInt16(exactly: input) - expectEqual(255, actual) +FixedPointConversion_Release64_ToUInt16 +.test("FromUInt8_NeverFails") +.forEach(in: [ + (getUInt16(+0), getUInt8(+0)), + (getUInt16(+255), getUInt8(+255)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int8: (-128)...(127) +// MARK: Int8: (-128)...(+127) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt16.test("FromInt8(-128)_AlwaysTraps") { - let input = getInt8(-128) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt8(-128)_AlwaysFails") { - let input = getInt8(-128) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt8(-1)_AlwaysTraps") { - let input = getInt8(-1) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt8(-1)_AlwaysFails") { - let input = getInt8(-1) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt16 +.test("FromInt8_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getInt8(+0)), + (getUInt16(+127), getInt8(+127)), +]) { + expectEqual($0.0, UInt16($0.1)) } -FixedPointConversion_Release64_ToUInt16.test("FromInt8(0)_NeverTraps") { - let input = getInt8(0) - let actual = UInt16(input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt16 +.test("FromInt8_NeverFails") +.forEach(in: [ + (getUInt16(+0), getInt8(+0)), + (getUInt16(+127), getInt8(+127)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) } -FixedPointConversion_Release64_ToUInt16.test("FromInt8(0)_NeverFails") { - let input = getInt8(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt16 +.test("FromInt8_AlwaysTraps") +.forEach(in: [ + getInt8(-128), + getInt8(-1), +]) { + expectCrashLater() + _blackHole(UInt16($0)) } -FixedPointConversion_Release64_ToUInt16.test("FromInt8(127)_NeverTraps") { - let input = getInt8(127) - let actual = UInt16(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt8(127)_NeverFails") { - let input = getInt8(127) - let actual = UInt16(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Release64_ToUInt16 +.test("FromInt8_AlwaysFails") +.forEach(in: [ + getInt8(-128), + getInt8(-1), +]) { + expectNil(UInt16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt16: (0)...(65535) +// MARK: UInt16: (+0)...(+65535) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt16.test("FromUInt16(0)_NeverTraps") { - let input = getUInt16(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromUInt16(0)_NeverFails") { - let input = getUInt16(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt16 +.test("FromUInt16_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getUInt16(+0)), + (getUInt16(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, UInt16($0.1)) } -FixedPointConversion_Release64_ToUInt16.test("FromUInt16(65535)_NeverTraps") { - let input = getUInt16(65535) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromUInt16(65535)_NeverFails") { - let input = getUInt16(65535) - let actual = UInt16(exactly: input) - expectEqual(65535, actual) +FixedPointConversion_Release64_ToUInt16 +.test("FromUInt16_NeverFails") +.forEach(in: [ + (getUInt16(+0), getUInt16(+0)), + (getUInt16(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int16: (-32768)...(32767) +// MARK: Int16: (-32768)...(+32767) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt16.test("FromInt16(-32768)_AlwaysTraps") { - let input = getInt16(-32768) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt16(-32768)_AlwaysFails") { - let input = getInt16(-32768) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt16(-1)_AlwaysTraps") { - let input = getInt16(-1) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt16(-1)_AlwaysFails") { - let input = getInt16(-1) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt16(0)_NeverTraps") { - let input = getInt16(0) - let actual = UInt16(input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt16 +.test("FromInt16_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getInt16(+0)), + (getUInt16(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, UInt16($0.1)) } -FixedPointConversion_Release64_ToUInt16.test("FromInt16(0)_NeverFails") { - let input = getInt16(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt16 +.test("FromInt16_NeverFails") +.forEach(in: [ + (getUInt16(+0), getInt16(+0)), + (getUInt16(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) } -FixedPointConversion_Release64_ToUInt16.test("FromInt16(32767)_NeverTraps") { - let input = getInt16(32767) - let actual = UInt16(input) - expectEqual(32767, actual) +FixedPointConversion_Release64_ToUInt16 +.test("FromInt16_AlwaysTraps") +.forEach(in: [ + getInt16(-32768), + getInt16(-1), +]) { + expectCrashLater() + _blackHole(UInt16($0)) } -FixedPointConversion_Release64_ToUInt16.test("FromInt16(32767)_NeverFails") { - let input = getInt16(32767) - let actual = UInt16(exactly: input) - expectEqual(32767, actual) +FixedPointConversion_Release64_ToUInt16 +.test("FromInt16_AlwaysFails") +.forEach(in: [ + getInt16(-32768), + getInt16(-1), +]) { + expectNil(UInt16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt32: (0)...(4294967295) +// MARK: UInt32: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt16.test("FromUInt32(0)_NeverTraps") { - let input = getUInt32(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromUInt32(0)_NeverFails") { - let input = getUInt32(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromUInt32(65535)_NeverTraps") { - let input = getUInt32(65535) - let actual = UInt16(input) - expectEqual(65535, actual) +FixedPointConversion_Release64_ToUInt16 +.test("FromUInt32_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getUInt32(+0)), + (getUInt16(+65535), getUInt32(+65535)), +]) { + expectEqual($0.0, UInt16($0.1)) } -FixedPointConversion_Release64_ToUInt16.test("FromUInt32(65535)_NeverFails") { - let input = getUInt32(65535) - let actual = UInt16(exactly: input) - expectEqual(65535, actual) +FixedPointConversion_Release64_ToUInt16 +.test("FromUInt32_NeverFails") +.forEach(in: [ + (getUInt16(+0), getUInt32(+0)), + (getUInt16(+65535), getUInt32(+65535)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) } -FixedPointConversion_Release64_ToUInt16.test("FromUInt32(65536)_AlwaysTraps") { - let input = getUInt32(65536) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } +FixedPointConversion_Release64_ToUInt16 +.test("FromUInt32_AlwaysTraps") +.forEach(in: [ + getUInt32(+65536), + getUInt32(+4294967295), +]) { + expectCrashLater() + _blackHole(UInt16($0)) } -FixedPointConversion_Release64_ToUInt16.test("FromUInt32(65536)_AlwaysFails") { - let input = getUInt32(65536) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromUInt32(4294967295)_AlwaysTraps") { - let input = getUInt32(4294967295) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromUInt32(4294967295)_AlwaysFails") { - let input = getUInt32(4294967295) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt16 +.test("FromUInt32_AlwaysFails") +.forEach(in: [ + getUInt32(+65536), + getUInt32(+4294967295), +]) { + expectNil(UInt16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int32: (-2147483648)...(2147483647) +// MARK: Int32: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt16.test("FromInt32(-2147483648)_AlwaysTraps") { - let input = getInt32(-2147483648) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt32(-2147483648)_AlwaysFails") { - let input = getInt32(-2147483648) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt32(-1)_AlwaysTraps") { - let input = getInt32(-1) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt32(-1)_AlwaysFails") { - let input = getInt32(-1) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt32(0)_NeverTraps") { - let input = getInt32(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt32(0)_NeverFails") { - let input = getInt32(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt32(65535)_NeverTraps") { - let input = getInt32(65535) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt32(65535)_NeverFails") { - let input = getInt32(65535) - let actual = UInt16(exactly: input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt32(65536)_AlwaysTraps") { - let input = getInt32(65536) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt32(65536)_AlwaysFails") { - let input = getInt32(65536) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt32(2147483647)_AlwaysTraps") { - let input = getInt32(2147483647) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt32(2147483647)_AlwaysFails") { - let input = getInt32(2147483647) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt16 +.test("FromInt32_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getInt32(+0)), + (getUInt16(+65535), getInt32(+65535)), +]) { + expectEqual($0.0, UInt16($0.1)) +} + +FixedPointConversion_Release64_ToUInt16 +.test("FromInt32_NeverFails") +.forEach(in: [ + (getUInt16(+0), getInt32(+0)), + (getUInt16(+65535), getInt32(+65535)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToUInt16 +.test("FromInt32_AlwaysTraps") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-1), + getInt32(+65536), + getInt32(+2147483647), +]) { + expectCrashLater() + _blackHole(UInt16($0)) +} + +FixedPointConversion_Release64_ToUInt16 +.test("FromInt32_AlwaysFails") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-1), + getInt32(+65536), + getInt32(+2147483647), +]) { + expectNil(UInt16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt64: (0)...(18446744073709551615) +// MARK: UInt64: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt16.test("FromUInt64(0)_NeverTraps") { - let input = getUInt64(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromUInt64(0)_NeverFails") { - let input = getUInt64(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromUInt64(65535)_NeverTraps") { - let input = getUInt64(65535) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromUInt64(65535)_NeverFails") { - let input = getUInt64(65535) - let actual = UInt16(exactly: input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromUInt64(65536)_AlwaysTraps") { - let input = getUInt64(65536) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } +FixedPointConversion_Release64_ToUInt16 +.test("FromUInt64_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getUInt64(+0)), + (getUInt16(+65535), getUInt64(+65535)), +]) { + expectEqual($0.0, UInt16($0.1)) } -FixedPointConversion_Release64_ToUInt16.test("FromUInt64(65536)_AlwaysFails") { - let input = getUInt64(65536) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt16 +.test("FromUInt64_NeverFails") +.forEach(in: [ + (getUInt16(+0), getUInt64(+0)), + (getUInt16(+65535), getUInt64(+65535)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) } -FixedPointConversion_Release64_ToUInt16.test("FromUInt64(18446744073709551615)_AlwaysTraps") { - let input = getUInt64(18446744073709551615) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } +FixedPointConversion_Release64_ToUInt16 +.test("FromUInt64_AlwaysTraps") +.forEach(in: [ + getUInt64(+65536), + getUInt64(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(UInt16($0)) } -FixedPointConversion_Release64_ToUInt16.test("FromUInt64(18446744073709551615)_AlwaysFails") { - let input = getUInt64(18446744073709551615) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt16 +.test("FromUInt64_AlwaysFails") +.forEach(in: [ + getUInt64(+65536), + getUInt64(+18446744073709551615), +]) { + expectNil(UInt16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int64: (-9223372036854775808)...(9223372036854775807) +// MARK: Int64: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt16.test("FromInt64(-9223372036854775808)_AlwaysTraps") { - let input = getInt64(-9223372036854775808) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt64(-9223372036854775808)_AlwaysFails") { - let input = getInt64(-9223372036854775808) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt64(-1)_AlwaysTraps") { - let input = getInt64(-1) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt64(-1)_AlwaysFails") { - let input = getInt64(-1) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt64(0)_NeverTraps") { - let input = getInt64(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt64(0)_NeverFails") { - let input = getInt64(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt64(65535)_NeverTraps") { - let input = getInt64(65535) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt64(65535)_NeverFails") { - let input = getInt64(65535) - let actual = UInt16(exactly: input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt64(65536)_AlwaysTraps") { - let input = getInt64(65536) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt64(65536)_AlwaysFails") { - let input = getInt64(65536) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt64(9223372036854775807)_AlwaysTraps") { - let input = getInt64(9223372036854775807) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt64(9223372036854775807)_AlwaysFails") { - let input = getInt64(9223372036854775807) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt16 +.test("FromInt64_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getInt64(+0)), + (getUInt16(+65535), getInt64(+65535)), +]) { + expectEqual($0.0, UInt16($0.1)) +} + +FixedPointConversion_Release64_ToUInt16 +.test("FromInt64_NeverFails") +.forEach(in: [ + (getUInt16(+0), getInt64(+0)), + (getUInt16(+65535), getInt64(+65535)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToUInt16 +.test("FromInt64_AlwaysTraps") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-1), + getInt64(+65536), + getInt64(+9223372036854775807), +]) { + expectCrashLater() + _blackHole(UInt16($0)) +} + +FixedPointConversion_Release64_ToUInt16 +.test("FromInt64_AlwaysFails") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-1), + getInt64(+65536), + getInt64(+9223372036854775807), +]) { + expectNil(UInt16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt: (0)...(18446744073709551615) +// MARK: UInt: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt16.test("FromUInt(0)_NeverTraps") { - let input = getUInt(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromUInt(0)_NeverFails") { - let input = getUInt(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromUInt(65535)_NeverTraps") { - let input = getUInt(65535) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromUInt(65535)_NeverFails") { - let input = getUInt(65535) - let actual = UInt16(exactly: input) - expectEqual(65535, actual) +FixedPointConversion_Release64_ToUInt16 +.test("FromUInt_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getUInt(+0)), + (getUInt16(+65535), getUInt(+65535)), +]) { + expectEqual($0.0, UInt16($0.1)) } -FixedPointConversion_Release64_ToUInt16.test("FromUInt(65536)_AlwaysTraps") { - let input = getUInt(65536) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } +FixedPointConversion_Release64_ToUInt16 +.test("FromUInt_NeverFails") +.forEach(in: [ + (getUInt16(+0), getUInt(+0)), + (getUInt16(+65535), getUInt(+65535)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) } -FixedPointConversion_Release64_ToUInt16.test("FromUInt(65536)_AlwaysFails") { - let input = getUInt(65536) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt16 +.test("FromUInt_AlwaysTraps") +.forEach(in: [ + getUInt(+65536), + getUInt(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(UInt16($0)) } -FixedPointConversion_Release64_ToUInt16.test("FromUInt(18446744073709551615)_AlwaysTraps") { - let input = getUInt(18446744073709551615) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromUInt(18446744073709551615)_AlwaysFails") { - let input = getUInt(18446744073709551615) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt16 +.test("FromUInt_AlwaysFails") +.forEach(in: [ + getUInt(+65536), + getUInt(+18446744073709551615), +]) { + expectNil(UInt16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int: (-9223372036854775808)...(9223372036854775807) +// MARK: Int: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt16.test("FromInt(-9223372036854775808)_AlwaysTraps") { - let input = getInt(-9223372036854775808) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt(-9223372036854775808)_AlwaysFails") { - let input = getInt(-9223372036854775808) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt(-1)_AlwaysTraps") { - let input = getInt(-1) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt(-1)_AlwaysFails") { - let input = getInt(-1) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt(0)_NeverTraps") { - let input = getInt(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt(0)_NeverFails") { - let input = getInt(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt(65535)_NeverTraps") { - let input = getInt(65535) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt(65535)_NeverFails") { - let input = getInt(65535) - let actual = UInt16(exactly: input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt(65536)_AlwaysTraps") { - let input = getInt(65536) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt(65536)_AlwaysFails") { - let input = getInt(65536) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt(9223372036854775807)_AlwaysTraps") { - let input = getInt(9223372036854775807) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromInt(9223372036854775807)_AlwaysFails") { - let input = getInt(9223372036854775807) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt16 +.test("FromInt_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getInt(+0)), + (getUInt16(+65535), getInt(+65535)), +]) { + expectEqual($0.0, UInt16($0.1)) +} + +FixedPointConversion_Release64_ToUInt16 +.test("FromInt_NeverFails") +.forEach(in: [ + (getUInt16(+0), getInt(+0)), + (getUInt16(+65535), getInt(+65535)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToUInt16 +.test("FromInt_AlwaysTraps") +.forEach(in: [ + getInt(-9223372036854775808), + getInt(-1), + getInt(+65536), + getInt(+9223372036854775807), +]) { + expectCrashLater() + _blackHole(UInt16($0)) +} + +FixedPointConversion_Release64_ToUInt16 +.test("FromInt_AlwaysFails") +.forEach(in: [ + getInt(-9223372036854775808), + getInt(-1), + getInt(+65536), + getInt(+9223372036854775807), +]) { + expectNil(UInt16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float16: (-2047)...(2047) +// MARK: Float16: (-2047)...(+2047) //===----------------------------------------------------------------------===// #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -FixedPointConversion_Release64_ToUInt16.test("FromFloat16(-2047)_AlwaysTraps") { - let input = getFloat16(-2047) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat16(-2047)_AlwaysFails") { - let input = getFloat16(-2047) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat16(-128.5)_AlwaysTraps") { - let input = getFloat16(-128.5) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat16(-128.5)_AlwaysFails") { - let input = getFloat16(-128.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat16(-1)_AlwaysTraps") { - let input = getFloat16(-1) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat16(-1)_AlwaysFails") { - let input = getFloat16(-1) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat16(-0.5)_NeverTraps") { - let input = getFloat16(-0.5) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat16(-0.5)_AlwaysFails") { - let input = getFloat16(-0.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat16(0)_NeverTraps") { - let input = getFloat16(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat16(0)_NeverFails") { - let input = getFloat16(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat16(-0.0)_NeverTraps") { - let input = getFloat16(-0.0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat16(-0.0)_NeverFails") { - let input = getFloat16(-0.0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat16(0.0)_NeverTraps") { - let input = getFloat16(0.0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat16(0.0)_NeverFails") { - let input = getFloat16(0.0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat16(0.5)_NeverTraps") { - let input = getFloat16(0.5) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat16(0.5)_AlwaysFails") { - let input = getFloat16(0.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat16(127.5)_NeverTraps") { - let input = getFloat16(127.5) - let actual = UInt16(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat16(127.5)_AlwaysFails") { - let input = getFloat16(127.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat16(255.5)_NeverTraps") { - let input = getFloat16(255.5) - let actual = UInt16(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat16(255.5)_AlwaysFails") { - let input = getFloat16(255.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat16(2047)_NeverTraps") { - let input = getFloat16(2047) - let actual = UInt16(input) - expectEqual(2047, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat16(2047)_NeverFails") { - let input = getFloat16(2047) - let actual = UInt16(exactly: input) - expectEqual(2047, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat16(-.infinity)_AlwaysTraps") { - let input = getFloat16(-.infinity) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat16(-.infinity)_AlwaysFails") { - let input = getFloat16(-.infinity) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat16(+.infinity)_AlwaysTraps") { - let input = getFloat16(+.infinity) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat16(+.infinity)_AlwaysFails") { - let input = getFloat16(+.infinity) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat16(-.nan)_AlwaysTraps") { - let input = getFloat16(-.nan) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat16(-.nan)_AlwaysFails") { - let input = getFloat16(-.nan) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat16(+.nan)_AlwaysTraps") { - let input = getFloat16(+.nan) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat16(+.nan)_AlwaysFails") { - let input = getFloat16(+.nan) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat16(-.signalingNaN)_AlwaysTraps") { - let input = getFloat16(-.signalingNaN) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat16(-.signalingNaN)_AlwaysFails") { - let input = getFloat16(-.signalingNaN) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat16(+.signalingNaN)_AlwaysTraps") { - let input = getFloat16(+.signalingNaN) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat16(+.signalingNaN)_AlwaysFails") { - let input = getFloat16(+.signalingNaN) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt16 +.test("FromFloat16_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getFloat16(-0.5)), + (getUInt16(+0), getFloat16(+0)), + (getUInt16(+0), getFloat16(-0)), + (getUInt16(+0), getFloat16(+0.5)), + (getUInt16(+127), getFloat16(+127.5)), + (getUInt16(+255), getFloat16(+255.5)), + (getUInt16(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, UInt16($0.1)) +} + +FixedPointConversion_Release64_ToUInt16 +.test("FromFloat16_NeverFails") +.forEach(in: [ + (getUInt16(+0), getFloat16(+0)), + (getUInt16(+0), getFloat16(-0)), + (getUInt16(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToUInt16 +.test("FromFloat16_AlwaysTraps") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-128.5), + getFloat16(-1), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt16($0)) +} + +FixedPointConversion_Release64_ToUInt16 +.test("FromFloat16_AlwaysFails") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-128.5), + getFloat16(-1), + getFloat16(-0.5), + getFloat16(+0.5), + getFloat16(+127.5), + getFloat16(+255.5), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectNil(UInt16(exactly: $0)) } } #endif // Float16 //===----------------------------------------------------------------------===// -// MARK: Float32: (-16777215)...(16777215) +// MARK: Float32: (-16777215)...(+16777215) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(-16777215)_AlwaysTraps") { - let input = getFloat32(-16777215) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(-16777215)_AlwaysFails") { - let input = getFloat32(-16777215) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(-32768.5)_AlwaysTraps") { - let input = getFloat32(-32768.5) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(-32768.5)_AlwaysFails") { - let input = getFloat32(-32768.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(-128.5)_AlwaysTraps") { - let input = getFloat32(-128.5) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(-128.5)_AlwaysFails") { - let input = getFloat32(-128.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(-1)_AlwaysTraps") { - let input = getFloat32(-1) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(-1)_AlwaysFails") { - let input = getFloat32(-1) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(-0.5)_NeverTraps") { - let input = getFloat32(-0.5) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(-0.5)_AlwaysFails") { - let input = getFloat32(-0.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(0)_NeverTraps") { - let input = getFloat32(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(0)_NeverFails") { - let input = getFloat32(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(-0.0)_NeverTraps") { - let input = getFloat32(-0.0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(-0.0)_NeverFails") { - let input = getFloat32(-0.0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(0.0)_NeverTraps") { - let input = getFloat32(0.0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(0.0)_NeverFails") { - let input = getFloat32(0.0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(0.5)_NeverTraps") { - let input = getFloat32(0.5) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(0.5)_AlwaysFails") { - let input = getFloat32(0.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(127.5)_NeverTraps") { - let input = getFloat32(127.5) - let actual = UInt16(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(127.5)_AlwaysFails") { - let input = getFloat32(127.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(255.5)_NeverTraps") { - let input = getFloat32(255.5) - let actual = UInt16(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(255.5)_AlwaysFails") { - let input = getFloat32(255.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(32767.5)_NeverTraps") { - let input = getFloat32(32767.5) - let actual = UInt16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(32767.5)_AlwaysFails") { - let input = getFloat32(32767.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(65535)_NeverTraps") { - let input = getFloat32(65535) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(65535)_NeverFails") { - let input = getFloat32(65535) - let actual = UInt16(exactly: input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(65535.5)_NeverTraps") { - let input = getFloat32(65535.5) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(65535.5)_AlwaysFails") { - let input = getFloat32(65535.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(65536)_AlwaysTraps") { - let input = getFloat32(65536) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(65536)_AlwaysFails") { - let input = getFloat32(65536) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(16777215)_AlwaysTraps") { - let input = getFloat32(16777215) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(16777215)_AlwaysFails") { - let input = getFloat32(16777215) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(-.infinity)_AlwaysTraps") { - let input = getFloat32(-.infinity) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(-.infinity)_AlwaysFails") { - let input = getFloat32(-.infinity) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(+.infinity)_AlwaysTraps") { - let input = getFloat32(+.infinity) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(+.infinity)_AlwaysFails") { - let input = getFloat32(+.infinity) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(-.nan)_AlwaysTraps") { - let input = getFloat32(-.nan) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(-.nan)_AlwaysFails") { - let input = getFloat32(-.nan) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(+.nan)_AlwaysTraps") { - let input = getFloat32(+.nan) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(+.nan)_AlwaysFails") { - let input = getFloat32(+.nan) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(-.signalingNaN)_AlwaysTraps") { - let input = getFloat32(-.signalingNaN) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(-.signalingNaN)_AlwaysFails") { - let input = getFloat32(-.signalingNaN) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(+.signalingNaN)_AlwaysTraps") { - let input = getFloat32(+.signalingNaN) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat32(+.signalingNaN)_AlwaysFails") { - let input = getFloat32(+.signalingNaN) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt16 +.test("FromFloat32_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getFloat32(-0.5)), + (getUInt16(+0), getFloat32(+0)), + (getUInt16(+0), getFloat32(-0)), + (getUInt16(+0), getFloat32(+0.5)), + (getUInt16(+127), getFloat32(+127.5)), + (getUInt16(+255), getFloat32(+255.5)), + (getUInt16(+32767), getFloat32(+32767.5)), + (getUInt16(+65535), getFloat32(+65535)), + (getUInt16(+65535), getFloat32(+65535.5)), +]) { + expectEqual($0.0, UInt16($0.1)) +} + +FixedPointConversion_Release64_ToUInt16 +.test("FromFloat32_NeverFails") +.forEach(in: [ + (getUInt16(+0), getFloat32(+0)), + (getUInt16(+0), getFloat32(-0)), + (getUInt16(+65535), getFloat32(+65535)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToUInt16 +.test("FromFloat32_AlwaysTraps") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-1), + getFloat32(+65536), + getFloat32(+16777215), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt16($0)) +} + +FixedPointConversion_Release64_ToUInt16 +.test("FromFloat32_AlwaysFails") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-1), + getFloat32(-0.5), + getFloat32(+0.5), + getFloat32(+127.5), + getFloat32(+255.5), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(+65536), + getFloat32(+16777215), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectNil(UInt16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float64: (-9007199254740991)...(9007199254740991) +// MARK: Float64: (-9007199254740991)...(+9007199254740991) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(-9007199254740991)_AlwaysTraps") { - let input = getFloat64(-9007199254740991) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(-9007199254740991)_AlwaysFails") { - let input = getFloat64(-9007199254740991) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(-32768.5)_AlwaysTraps") { - let input = getFloat64(-32768.5) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(-32768.5)_AlwaysFails") { - let input = getFloat64(-32768.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(-128.5)_AlwaysTraps") { - let input = getFloat64(-128.5) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(-128.5)_AlwaysFails") { - let input = getFloat64(-128.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(-1)_AlwaysTraps") { - let input = getFloat64(-1) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(-1)_AlwaysFails") { - let input = getFloat64(-1) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(-0.5)_NeverTraps") { - let input = getFloat64(-0.5) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(-0.5)_AlwaysFails") { - let input = getFloat64(-0.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(0)_NeverTraps") { - let input = getFloat64(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(0)_NeverFails") { - let input = getFloat64(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(-0.0)_NeverTraps") { - let input = getFloat64(-0.0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(-0.0)_NeverFails") { - let input = getFloat64(-0.0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(0.0)_NeverTraps") { - let input = getFloat64(0.0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(0.0)_NeverFails") { - let input = getFloat64(0.0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(0.5)_NeverTraps") { - let input = getFloat64(0.5) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(0.5)_AlwaysFails") { - let input = getFloat64(0.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(127.5)_NeverTraps") { - let input = getFloat64(127.5) - let actual = UInt16(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(127.5)_AlwaysFails") { - let input = getFloat64(127.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(255.5)_NeverTraps") { - let input = getFloat64(255.5) - let actual = UInt16(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(255.5)_AlwaysFails") { - let input = getFloat64(255.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(32767.5)_NeverTraps") { - let input = getFloat64(32767.5) - let actual = UInt16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(32767.5)_AlwaysFails") { - let input = getFloat64(32767.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(65535)_NeverTraps") { - let input = getFloat64(65535) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(65535)_NeverFails") { - let input = getFloat64(65535) - let actual = UInt16(exactly: input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(65535.5)_NeverTraps") { - let input = getFloat64(65535.5) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(65535.5)_AlwaysFails") { - let input = getFloat64(65535.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(65536)_AlwaysTraps") { - let input = getFloat64(65536) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(65536)_AlwaysFails") { - let input = getFloat64(65536) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(9007199254740991)_AlwaysTraps") { - let input = getFloat64(9007199254740991) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(9007199254740991)_AlwaysFails") { - let input = getFloat64(9007199254740991) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(-.infinity)_AlwaysTraps") { - let input = getFloat64(-.infinity) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(-.infinity)_AlwaysFails") { - let input = getFloat64(-.infinity) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(+.infinity)_AlwaysTraps") { - let input = getFloat64(+.infinity) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(+.infinity)_AlwaysFails") { - let input = getFloat64(+.infinity) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(-.nan)_AlwaysTraps") { - let input = getFloat64(-.nan) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(-.nan)_AlwaysFails") { - let input = getFloat64(-.nan) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(+.nan)_AlwaysTraps") { - let input = getFloat64(+.nan) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(+.nan)_AlwaysFails") { - let input = getFloat64(+.nan) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(-.signalingNaN)_AlwaysTraps") { - let input = getFloat64(-.signalingNaN) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(-.signalingNaN)_AlwaysFails") { - let input = getFloat64(-.signalingNaN) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(+.signalingNaN)_AlwaysTraps") { - let input = getFloat64(+.signalingNaN) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat64(+.signalingNaN)_AlwaysFails") { - let input = getFloat64(+.signalingNaN) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt16 +.test("FromFloat64_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getFloat64(-0.5)), + (getUInt16(+0), getFloat64(+0)), + (getUInt16(+0), getFloat64(-0)), + (getUInt16(+0), getFloat64(+0.5)), + (getUInt16(+127), getFloat64(+127.5)), + (getUInt16(+255), getFloat64(+255.5)), + (getUInt16(+32767), getFloat64(+32767.5)), + (getUInt16(+65535), getFloat64(+65535)), + (getUInt16(+65535), getFloat64(+65535.5)), +]) { + expectEqual($0.0, UInt16($0.1)) +} + +FixedPointConversion_Release64_ToUInt16 +.test("FromFloat64_NeverFails") +.forEach(in: [ + (getUInt16(+0), getFloat64(+0)), + (getUInt16(+0), getFloat64(-0)), + (getUInt16(+65535), getFloat64(+65535)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToUInt16 +.test("FromFloat64_AlwaysTraps") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-1), + getFloat64(+65536), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt16($0)) +} + +FixedPointConversion_Release64_ToUInt16 +.test("FromFloat64_AlwaysFails") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-1), + getFloat64(-0.5), + getFloat64(+0.5), + getFloat64(+127.5), + getFloat64(+255.5), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(+65536), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectNil(UInt16(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float80: (-18446744073709551615)...(18446744073709551615) +// MARK: Float80: (-18446744073709551615)...(+18446744073709551615) //===----------------------------------------------------------------------===// #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(-18446744073709551615)_AlwaysTraps") { - let input = getFloat80(-18446744073709551615) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(-18446744073709551615)_AlwaysFails") { - let input = getFloat80(-18446744073709551615) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(-32768.5)_AlwaysTraps") { - let input = getFloat80(-32768.5) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(-32768.5)_AlwaysFails") { - let input = getFloat80(-32768.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(-128.5)_AlwaysTraps") { - let input = getFloat80(-128.5) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(-128.5)_AlwaysFails") { - let input = getFloat80(-128.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(-1)_AlwaysTraps") { - let input = getFloat80(-1) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(-1)_AlwaysFails") { - let input = getFloat80(-1) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(-0.5)_NeverTraps") { - let input = getFloat80(-0.5) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(-0.5)_AlwaysFails") { - let input = getFloat80(-0.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(0)_NeverTraps") { - let input = getFloat80(0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(0)_NeverFails") { - let input = getFloat80(0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(-0.0)_NeverTraps") { - let input = getFloat80(-0.0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(-0.0)_NeverFails") { - let input = getFloat80(-0.0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(0.0)_NeverTraps") { - let input = getFloat80(0.0) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(0.0)_NeverFails") { - let input = getFloat80(0.0) - let actual = UInt16(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(0.5)_NeverTraps") { - let input = getFloat80(0.5) - let actual = UInt16(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(0.5)_AlwaysFails") { - let input = getFloat80(0.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(127.5)_NeverTraps") { - let input = getFloat80(127.5) - let actual = UInt16(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(127.5)_AlwaysFails") { - let input = getFloat80(127.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(255.5)_NeverTraps") { - let input = getFloat80(255.5) - let actual = UInt16(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(255.5)_AlwaysFails") { - let input = getFloat80(255.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(32767.5)_NeverTraps") { - let input = getFloat80(32767.5) - let actual = UInt16(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(32767.5)_AlwaysFails") { - let input = getFloat80(32767.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(65535)_NeverTraps") { - let input = getFloat80(65535) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(65535)_NeverFails") { - let input = getFloat80(65535) - let actual = UInt16(exactly: input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(65535.5)_NeverTraps") { - let input = getFloat80(65535.5) - let actual = UInt16(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(65535.5)_AlwaysFails") { - let input = getFloat80(65535.5) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(65536)_AlwaysTraps") { - let input = getFloat80(65536) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(65536)_AlwaysFails") { - let input = getFloat80(65536) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(18446744073709551615)_AlwaysTraps") { - let input = getFloat80(18446744073709551615) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(18446744073709551615)_AlwaysFails") { - let input = getFloat80(18446744073709551615) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(-.infinity)_AlwaysTraps") { - let input = getFloat80(-.infinity) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(-.infinity)_AlwaysFails") { - let input = getFloat80(-.infinity) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(+.infinity)_AlwaysTraps") { - let input = getFloat80(+.infinity) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(+.infinity)_AlwaysFails") { - let input = getFloat80(+.infinity) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(-.nan)_AlwaysTraps") { - let input = getFloat80(-.nan) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(-.nan)_AlwaysFails") { - let input = getFloat80(-.nan) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(+.nan)_AlwaysTraps") { - let input = getFloat80(+.nan) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(+.nan)_AlwaysFails") { - let input = getFloat80(+.nan) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(-.signalingNaN)_AlwaysTraps") { - let input = getFloat80(-.signalingNaN) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(-.signalingNaN)_AlwaysFails") { - let input = getFloat80(-.signalingNaN) - let actual = UInt16(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(+.signalingNaN)_AlwaysTraps") { - let input = getFloat80(+.signalingNaN) - expectCrash { - let actual = UInt16(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt16.test("FromFloat80(+.signalingNaN)_AlwaysFails") { - let input = getFloat80(+.signalingNaN) - let actual = UInt16(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt16 +.test("FromFloat80_NeverTraps") +.forEach(in: [ + (getUInt16(+0), getFloat80(-0.5)), + (getUInt16(+0), getFloat80(+0)), + (getUInt16(+0), getFloat80(-0)), + (getUInt16(+0), getFloat80(+0.5)), + (getUInt16(+127), getFloat80(+127.5)), + (getUInt16(+255), getFloat80(+255.5)), + (getUInt16(+32767), getFloat80(+32767.5)), + (getUInt16(+65535), getFloat80(+65535)), + (getUInt16(+65535), getFloat80(+65535.5)), +]) { + expectEqual($0.0, UInt16($0.1)) +} + +FixedPointConversion_Release64_ToUInt16 +.test("FromFloat80_NeverFails") +.forEach(in: [ + (getUInt16(+0), getFloat80(+0)), + (getUInt16(+0), getFloat80(-0)), + (getUInt16(+65535), getFloat80(+65535)), +]) { + expectEqual($0.0, UInt16(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToUInt16 +.test("FromFloat80_AlwaysTraps") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-1), + getFloat80(+65536), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt16($0)) +} + +FixedPointConversion_Release64_ToUInt16 +.test("FromFloat80_AlwaysFails") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-1), + getFloat80(-0.5), + getFloat80(+0.5), + getFloat80(+127.5), + getFloat80(+255.5), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(+65536), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectNil(UInt16(exactly: $0)) } #endif // Float80 diff --git a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release64_ToUInt32.swift b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release64_ToUInt32.swift index 8c8f6d7f123e8..f81445496c2ed 100644 --- a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release64_ToUInt32.swift +++ b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release64_ToUInt32.swift @@ -14,1620 +14,663 @@ import StdlibUnittest -let FixedPointConversion_Release64_ToUInt32 = TestSuite("FixedPointConversion_Release64_ToUInt32") +let FixedPointConversion_Release64_ToUInt32 = TestSuite( + "FixedPointConversion_Release64_ToUInt32" +) //===----------------------------------------------------------------------===// -// MARK: UInt8: (0)...(255) +// MARK: UInt8: (+0)...(+255) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt32.test("FromUInt8(0)_NeverTraps") { - let input = getUInt8(0) - let actual = UInt32(input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt32 +.test("FromUInt8_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getUInt8(+0)), + (getUInt32(+255), getUInt8(+255)), +]) { + expectEqual($0.0, UInt32($0.1)) } -FixedPointConversion_Release64_ToUInt32.test("FromUInt8(0)_NeverFails") { - let input = getUInt8(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromUInt8(255)_NeverTraps") { - let input = getUInt8(255) - let actual = UInt32(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromUInt8(255)_NeverFails") { - let input = getUInt8(255) - let actual = UInt32(exactly: input) - expectEqual(255, actual) +FixedPointConversion_Release64_ToUInt32 +.test("FromUInt8_NeverFails") +.forEach(in: [ + (getUInt32(+0), getUInt8(+0)), + (getUInt32(+255), getUInt8(+255)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int8: (-128)...(127) +// MARK: Int8: (-128)...(+127) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt32.test("FromInt8(-128)_AlwaysTraps") { - let input = getInt8(-128) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } +FixedPointConversion_Release64_ToUInt32 +.test("FromInt8_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getInt8(+0)), + (getUInt32(+127), getInt8(+127)), +]) { + expectEqual($0.0, UInt32($0.1)) } -FixedPointConversion_Release64_ToUInt32.test("FromInt8(-128)_AlwaysFails") { - let input = getInt8(-128) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt32 +.test("FromInt8_NeverFails") +.forEach(in: [ + (getUInt32(+0), getInt8(+0)), + (getUInt32(+127), getInt8(+127)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) } -FixedPointConversion_Release64_ToUInt32.test("FromInt8(-1)_AlwaysTraps") { - let input = getInt8(-1) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } +FixedPointConversion_Release64_ToUInt32 +.test("FromInt8_AlwaysTraps") +.forEach(in: [ + getInt8(-128), + getInt8(-1), +]) { + expectCrashLater() + _blackHole(UInt32($0)) } -FixedPointConversion_Release64_ToUInt32.test("FromInt8(-1)_AlwaysFails") { - let input = getInt8(-1) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromInt8(0)_NeverTraps") { - let input = getInt8(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromInt8(0)_NeverFails") { - let input = getInt8(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromInt8(127)_NeverTraps") { - let input = getInt8(127) - let actual = UInt32(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromInt8(127)_NeverFails") { - let input = getInt8(127) - let actual = UInt32(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Release64_ToUInt32 +.test("FromInt8_AlwaysFails") +.forEach(in: [ + getInt8(-128), + getInt8(-1), +]) { + expectNil(UInt32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt16: (0)...(65535) +// MARK: UInt16: (+0)...(+65535) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt32.test("FromUInt16(0)_NeverTraps") { - let input = getUInt16(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromUInt16(0)_NeverFails") { - let input = getUInt16(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromUInt16(65535)_NeverTraps") { - let input = getUInt16(65535) - let actual = UInt32(input) - expectEqual(65535, actual) +FixedPointConversion_Release64_ToUInt32 +.test("FromUInt16_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getUInt16(+0)), + (getUInt32(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, UInt32($0.1)) } -FixedPointConversion_Release64_ToUInt32.test("FromUInt16(65535)_NeverFails") { - let input = getUInt16(65535) - let actual = UInt32(exactly: input) - expectEqual(65535, actual) +FixedPointConversion_Release64_ToUInt32 +.test("FromUInt16_NeverFails") +.forEach(in: [ + (getUInt32(+0), getUInt16(+0)), + (getUInt32(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int16: (-32768)...(32767) +// MARK: Int16: (-32768)...(+32767) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt32.test("FromInt16(-32768)_AlwaysTraps") { - let input = getInt16(-32768) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromInt16(-32768)_AlwaysFails") { - let input = getInt16(-32768) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromInt16(-1)_AlwaysTraps") { - let input = getInt16(-1) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } +FixedPointConversion_Release64_ToUInt32 +.test("FromInt16_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getInt16(+0)), + (getUInt32(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, UInt32($0.1)) } -FixedPointConversion_Release64_ToUInt32.test("FromInt16(-1)_AlwaysFails") { - let input = getInt16(-1) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt32 +.test("FromInt16_NeverFails") +.forEach(in: [ + (getUInt32(+0), getInt16(+0)), + (getUInt32(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) } -FixedPointConversion_Release64_ToUInt32.test("FromInt16(0)_NeverTraps") { - let input = getInt16(0) - let actual = UInt32(input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt32 +.test("FromInt16_AlwaysTraps") +.forEach(in: [ + getInt16(-32768), + getInt16(-1), +]) { + expectCrashLater() + _blackHole(UInt32($0)) } -FixedPointConversion_Release64_ToUInt32.test("FromInt16(0)_NeverFails") { - let input = getInt16(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromInt16(32767)_NeverTraps") { - let input = getInt16(32767) - let actual = UInt32(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromInt16(32767)_NeverFails") { - let input = getInt16(32767) - let actual = UInt32(exactly: input) - expectEqual(32767, actual) +FixedPointConversion_Release64_ToUInt32 +.test("FromInt16_AlwaysFails") +.forEach(in: [ + getInt16(-32768), + getInt16(-1), +]) { + expectNil(UInt32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt32: (0)...(4294967295) +// MARK: UInt32: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt32.test("FromUInt32(0)_NeverTraps") { - let input = getUInt32(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromUInt32(0)_NeverFails") { - let input = getUInt32(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt32 +.test("FromUInt32_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getUInt32(+0)), + (getUInt32(+4294967295), getUInt32(+4294967295)), +]) { + expectEqual($0.0, UInt32($0.1)) } -FixedPointConversion_Release64_ToUInt32.test("FromUInt32(4294967295)_NeverTraps") { - let input = getUInt32(4294967295) - let actual = UInt32(input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromUInt32(4294967295)_NeverFails") { - let input = getUInt32(4294967295) - let actual = UInt32(exactly: input) - expectEqual(4294967295, actual) +FixedPointConversion_Release64_ToUInt32 +.test("FromUInt32_NeverFails") +.forEach(in: [ + (getUInt32(+0), getUInt32(+0)), + (getUInt32(+4294967295), getUInt32(+4294967295)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int32: (-2147483648)...(2147483647) +// MARK: Int32: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt32.test("FromInt32(-2147483648)_AlwaysTraps") { - let input = getInt32(-2147483648) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromInt32(-2147483648)_AlwaysFails") { - let input = getInt32(-2147483648) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt32 +.test("FromInt32_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getInt32(+0)), + (getUInt32(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, UInt32($0.1)) } -FixedPointConversion_Release64_ToUInt32.test("FromInt32(-1)_AlwaysTraps") { - let input = getInt32(-1) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } +FixedPointConversion_Release64_ToUInt32 +.test("FromInt32_NeverFails") +.forEach(in: [ + (getUInt32(+0), getInt32(+0)), + (getUInt32(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) } -FixedPointConversion_Release64_ToUInt32.test("FromInt32(-1)_AlwaysFails") { - let input = getInt32(-1) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt32 +.test("FromInt32_AlwaysTraps") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-1), +]) { + expectCrashLater() + _blackHole(UInt32($0)) } -FixedPointConversion_Release64_ToUInt32.test("FromInt32(0)_NeverTraps") { - let input = getInt32(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromInt32(0)_NeverFails") { - let input = getInt32(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromInt32(2147483647)_NeverTraps") { - let input = getInt32(2147483647) - let actual = UInt32(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromInt32(2147483647)_NeverFails") { - let input = getInt32(2147483647) - let actual = UInt32(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Release64_ToUInt32 +.test("FromInt32_AlwaysFails") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-1), +]) { + expectNil(UInt32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt64: (0)...(18446744073709551615) +// MARK: UInt64: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt32.test("FromUInt64(0)_NeverTraps") { - let input = getUInt64(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromUInt64(0)_NeverFails") { - let input = getUInt64(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromUInt64(4294967295)_NeverTraps") { - let input = getUInt64(4294967295) - let actual = UInt32(input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromUInt64(4294967295)_NeverFails") { - let input = getUInt64(4294967295) - let actual = UInt32(exactly: input) - expectEqual(4294967295, actual) +FixedPointConversion_Release64_ToUInt32 +.test("FromUInt64_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getUInt64(+0)), + (getUInt32(+4294967295), getUInt64(+4294967295)), +]) { + expectEqual($0.0, UInt32($0.1)) } -FixedPointConversion_Release64_ToUInt32.test("FromUInt64(4294967296)_AlwaysTraps") { - let input = getUInt64(4294967296) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } +FixedPointConversion_Release64_ToUInt32 +.test("FromUInt64_NeverFails") +.forEach(in: [ + (getUInt32(+0), getUInt64(+0)), + (getUInt32(+4294967295), getUInt64(+4294967295)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) } -FixedPointConversion_Release64_ToUInt32.test("FromUInt64(4294967296)_AlwaysFails") { - let input = getUInt64(4294967296) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt32 +.test("FromUInt64_AlwaysTraps") +.forEach(in: [ + getUInt64(+4294967296), + getUInt64(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(UInt32($0)) } -FixedPointConversion_Release64_ToUInt32.test("FromUInt64(18446744073709551615)_AlwaysTraps") { - let input = getUInt64(18446744073709551615) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromUInt64(18446744073709551615)_AlwaysFails") { - let input = getUInt64(18446744073709551615) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt32 +.test("FromUInt64_AlwaysFails") +.forEach(in: [ + getUInt64(+4294967296), + getUInt64(+18446744073709551615), +]) { + expectNil(UInt32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int64: (-9223372036854775808)...(9223372036854775807) +// MARK: Int64: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt32.test("FromInt64(-9223372036854775808)_AlwaysTraps") { - let input = getInt64(-9223372036854775808) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromInt64(-9223372036854775808)_AlwaysFails") { - let input = getInt64(-9223372036854775808) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromInt64(-1)_AlwaysTraps") { - let input = getInt64(-1) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromInt64(-1)_AlwaysFails") { - let input = getInt64(-1) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromInt64(0)_NeverTraps") { - let input = getInt64(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromInt64(0)_NeverFails") { - let input = getInt64(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromInt64(4294967295)_NeverTraps") { - let input = getInt64(4294967295) - let actual = UInt32(input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromInt64(4294967295)_NeverFails") { - let input = getInt64(4294967295) - let actual = UInt32(exactly: input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromInt64(4294967296)_AlwaysTraps") { - let input = getInt64(4294967296) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromInt64(4294967296)_AlwaysFails") { - let input = getInt64(4294967296) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromInt64(9223372036854775807)_AlwaysTraps") { - let input = getInt64(9223372036854775807) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromInt64(9223372036854775807)_AlwaysFails") { - let input = getInt64(9223372036854775807) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt32 +.test("FromInt64_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getInt64(+0)), + (getUInt32(+4294967295), getInt64(+4294967295)), +]) { + expectEqual($0.0, UInt32($0.1)) +} + +FixedPointConversion_Release64_ToUInt32 +.test("FromInt64_NeverFails") +.forEach(in: [ + (getUInt32(+0), getInt64(+0)), + (getUInt32(+4294967295), getInt64(+4294967295)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToUInt32 +.test("FromInt64_AlwaysTraps") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-1), + getInt64(+4294967296), + getInt64(+9223372036854775807), +]) { + expectCrashLater() + _blackHole(UInt32($0)) +} + +FixedPointConversion_Release64_ToUInt32 +.test("FromInt64_AlwaysFails") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-1), + getInt64(+4294967296), + getInt64(+9223372036854775807), +]) { + expectNil(UInt32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt: (0)...(18446744073709551615) +// MARK: UInt: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt32.test("FromUInt(0)_NeverTraps") { - let input = getUInt(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromUInt(0)_NeverFails") { - let input = getUInt(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromUInt(4294967295)_NeverTraps") { - let input = getUInt(4294967295) - let actual = UInt32(input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromUInt(4294967295)_NeverFails") { - let input = getUInt(4294967295) - let actual = UInt32(exactly: input) - expectEqual(4294967295, actual) +FixedPointConversion_Release64_ToUInt32 +.test("FromUInt_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getUInt(+0)), + (getUInt32(+4294967295), getUInt(+4294967295)), +]) { + expectEqual($0.0, UInt32($0.1)) } -FixedPointConversion_Release64_ToUInt32.test("FromUInt(4294967296)_AlwaysTraps") { - let input = getUInt(4294967296) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } +FixedPointConversion_Release64_ToUInt32 +.test("FromUInt_NeverFails") +.forEach(in: [ + (getUInt32(+0), getUInt(+0)), + (getUInt32(+4294967295), getUInt(+4294967295)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) } -FixedPointConversion_Release64_ToUInt32.test("FromUInt(4294967296)_AlwaysFails") { - let input = getUInt(4294967296) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt32 +.test("FromUInt_AlwaysTraps") +.forEach(in: [ + getUInt(+4294967296), + getUInt(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(UInt32($0)) } -FixedPointConversion_Release64_ToUInt32.test("FromUInt(18446744073709551615)_AlwaysTraps") { - let input = getUInt(18446744073709551615) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromUInt(18446744073709551615)_AlwaysFails") { - let input = getUInt(18446744073709551615) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt32 +.test("FromUInt_AlwaysFails") +.forEach(in: [ + getUInt(+4294967296), + getUInt(+18446744073709551615), +]) { + expectNil(UInt32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int: (-9223372036854775808)...(9223372036854775807) +// MARK: Int: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt32.test("FromInt(-9223372036854775808)_AlwaysTraps") { - let input = getInt(-9223372036854775808) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromInt(-9223372036854775808)_AlwaysFails") { - let input = getInt(-9223372036854775808) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromInt(-1)_AlwaysTraps") { - let input = getInt(-1) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromInt(-1)_AlwaysFails") { - let input = getInt(-1) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromInt(0)_NeverTraps") { - let input = getInt(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromInt(0)_NeverFails") { - let input = getInt(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromInt(4294967295)_NeverTraps") { - let input = getInt(4294967295) - let actual = UInt32(input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromInt(4294967295)_NeverFails") { - let input = getInt(4294967295) - let actual = UInt32(exactly: input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromInt(4294967296)_AlwaysTraps") { - let input = getInt(4294967296) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromInt(4294967296)_AlwaysFails") { - let input = getInt(4294967296) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromInt(9223372036854775807)_AlwaysTraps") { - let input = getInt(9223372036854775807) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromInt(9223372036854775807)_AlwaysFails") { - let input = getInt(9223372036854775807) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt32 +.test("FromInt_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getInt(+0)), + (getUInt32(+4294967295), getInt(+4294967295)), +]) { + expectEqual($0.0, UInt32($0.1)) +} + +FixedPointConversion_Release64_ToUInt32 +.test("FromInt_NeverFails") +.forEach(in: [ + (getUInt32(+0), getInt(+0)), + (getUInt32(+4294967295), getInt(+4294967295)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToUInt32 +.test("FromInt_AlwaysTraps") +.forEach(in: [ + getInt(-9223372036854775808), + getInt(-1), + getInt(+4294967296), + getInt(+9223372036854775807), +]) { + expectCrashLater() + _blackHole(UInt32($0)) +} + +FixedPointConversion_Release64_ToUInt32 +.test("FromInt_AlwaysFails") +.forEach(in: [ + getInt(-9223372036854775808), + getInt(-1), + getInt(+4294967296), + getInt(+9223372036854775807), +]) { + expectNil(UInt32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float16: (-2047)...(2047) +// MARK: Float16: (-2047)...(+2047) //===----------------------------------------------------------------------===// #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -FixedPointConversion_Release64_ToUInt32.test("FromFloat16(-2047)_AlwaysTraps") { - let input = getFloat16(-2047) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat16(-2047)_AlwaysFails") { - let input = getFloat16(-2047) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat16(-128.5)_AlwaysTraps") { - let input = getFloat16(-128.5) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat16(-128.5)_AlwaysFails") { - let input = getFloat16(-128.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat16(-1)_AlwaysTraps") { - let input = getFloat16(-1) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat16(-1)_AlwaysFails") { - let input = getFloat16(-1) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat16(-0.5)_NeverTraps") { - let input = getFloat16(-0.5) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat16(-0.5)_AlwaysFails") { - let input = getFloat16(-0.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat16(0)_NeverTraps") { - let input = getFloat16(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat16(0)_NeverFails") { - let input = getFloat16(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat16(-0.0)_NeverTraps") { - let input = getFloat16(-0.0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat16(-0.0)_NeverFails") { - let input = getFloat16(-0.0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat16(0.0)_NeverTraps") { - let input = getFloat16(0.0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat16(0.0)_NeverFails") { - let input = getFloat16(0.0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat16(0.5)_NeverTraps") { - let input = getFloat16(0.5) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat16(0.5)_AlwaysFails") { - let input = getFloat16(0.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat16(127.5)_NeverTraps") { - let input = getFloat16(127.5) - let actual = UInt32(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat16(127.5)_AlwaysFails") { - let input = getFloat16(127.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat16(255.5)_NeverTraps") { - let input = getFloat16(255.5) - let actual = UInt32(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat16(255.5)_AlwaysFails") { - let input = getFloat16(255.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat16(2047)_NeverTraps") { - let input = getFloat16(2047) - let actual = UInt32(input) - expectEqual(2047, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat16(2047)_NeverFails") { - let input = getFloat16(2047) - let actual = UInt32(exactly: input) - expectEqual(2047, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat16(-.infinity)_AlwaysTraps") { - let input = getFloat16(-.infinity) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat16(-.infinity)_AlwaysFails") { - let input = getFloat16(-.infinity) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat16(+.infinity)_AlwaysTraps") { - let input = getFloat16(+.infinity) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat16(+.infinity)_AlwaysFails") { - let input = getFloat16(+.infinity) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat16(-.nan)_AlwaysTraps") { - let input = getFloat16(-.nan) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat16(-.nan)_AlwaysFails") { - let input = getFloat16(-.nan) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat16(+.nan)_AlwaysTraps") { - let input = getFloat16(+.nan) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat16(+.nan)_AlwaysFails") { - let input = getFloat16(+.nan) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat16(-.signalingNaN)_AlwaysTraps") { - let input = getFloat16(-.signalingNaN) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat16(-.signalingNaN)_AlwaysFails") { - let input = getFloat16(-.signalingNaN) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat16(+.signalingNaN)_AlwaysTraps") { - let input = getFloat16(+.signalingNaN) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat16(+.signalingNaN)_AlwaysFails") { - let input = getFloat16(+.signalingNaN) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt32 +.test("FromFloat16_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getFloat16(-0.5)), + (getUInt32(+0), getFloat16(+0)), + (getUInt32(+0), getFloat16(-0)), + (getUInt32(+0), getFloat16(+0.5)), + (getUInt32(+127), getFloat16(+127.5)), + (getUInt32(+255), getFloat16(+255.5)), + (getUInt32(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, UInt32($0.1)) +} + +FixedPointConversion_Release64_ToUInt32 +.test("FromFloat16_NeverFails") +.forEach(in: [ + (getUInt32(+0), getFloat16(+0)), + (getUInt32(+0), getFloat16(-0)), + (getUInt32(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToUInt32 +.test("FromFloat16_AlwaysTraps") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-128.5), + getFloat16(-1), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt32($0)) +} + +FixedPointConversion_Release64_ToUInt32 +.test("FromFloat16_AlwaysFails") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-128.5), + getFloat16(-1), + getFloat16(-0.5), + getFloat16(+0.5), + getFloat16(+127.5), + getFloat16(+255.5), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectNil(UInt32(exactly: $0)) } } #endif // Float16 //===----------------------------------------------------------------------===// -// MARK: Float32: (-16777215)...(16777215) +// MARK: Float32: (-16777215)...(+16777215) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt32.test("FromFloat32(-16777215)_AlwaysTraps") { - let input = getFloat32(-16777215) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat32(-16777215)_AlwaysFails") { - let input = getFloat32(-16777215) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat32(-32768.5)_AlwaysTraps") { - let input = getFloat32(-32768.5) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat32(-32768.5)_AlwaysFails") { - let input = getFloat32(-32768.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat32(-128.5)_AlwaysTraps") { - let input = getFloat32(-128.5) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat32(-128.5)_AlwaysFails") { - let input = getFloat32(-128.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat32(-1)_AlwaysTraps") { - let input = getFloat32(-1) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat32(-1)_AlwaysFails") { - let input = getFloat32(-1) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat32(-0.5)_NeverTraps") { - let input = getFloat32(-0.5) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat32(-0.5)_AlwaysFails") { - let input = getFloat32(-0.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat32(0)_NeverTraps") { - let input = getFloat32(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat32(0)_NeverFails") { - let input = getFloat32(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat32(-0.0)_NeverTraps") { - let input = getFloat32(-0.0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat32(-0.0)_NeverFails") { - let input = getFloat32(-0.0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat32(0.0)_NeverTraps") { - let input = getFloat32(0.0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat32(0.0)_NeverFails") { - let input = getFloat32(0.0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat32(0.5)_NeverTraps") { - let input = getFloat32(0.5) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat32(0.5)_AlwaysFails") { - let input = getFloat32(0.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat32(127.5)_NeverTraps") { - let input = getFloat32(127.5) - let actual = UInt32(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat32(127.5)_AlwaysFails") { - let input = getFloat32(127.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat32(255.5)_NeverTraps") { - let input = getFloat32(255.5) - let actual = UInt32(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat32(255.5)_AlwaysFails") { - let input = getFloat32(255.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat32(32767.5)_NeverTraps") { - let input = getFloat32(32767.5) - let actual = UInt32(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat32(32767.5)_AlwaysFails") { - let input = getFloat32(32767.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat32(65535.5)_NeverTraps") { - let input = getFloat32(65535.5) - let actual = UInt32(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat32(65535.5)_AlwaysFails") { - let input = getFloat32(65535.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat32(16777215)_NeverTraps") { - let input = getFloat32(16777215) - let actual = UInt32(input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat32(16777215)_NeverFails") { - let input = getFloat32(16777215) - let actual = UInt32(exactly: input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat32(-.infinity)_AlwaysTraps") { - let input = getFloat32(-.infinity) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat32(-.infinity)_AlwaysFails") { - let input = getFloat32(-.infinity) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat32(+.infinity)_AlwaysTraps") { - let input = getFloat32(+.infinity) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat32(+.infinity)_AlwaysFails") { - let input = getFloat32(+.infinity) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat32(-.nan)_AlwaysTraps") { - let input = getFloat32(-.nan) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat32(-.nan)_AlwaysFails") { - let input = getFloat32(-.nan) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat32(+.nan)_AlwaysTraps") { - let input = getFloat32(+.nan) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat32(+.nan)_AlwaysFails") { - let input = getFloat32(+.nan) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat32(-.signalingNaN)_AlwaysTraps") { - let input = getFloat32(-.signalingNaN) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat32(-.signalingNaN)_AlwaysFails") { - let input = getFloat32(-.signalingNaN) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat32(+.signalingNaN)_AlwaysTraps") { - let input = getFloat32(+.signalingNaN) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat32(+.signalingNaN)_AlwaysFails") { - let input = getFloat32(+.signalingNaN) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt32 +.test("FromFloat32_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getFloat32(-0.5)), + (getUInt32(+0), getFloat32(+0)), + (getUInt32(+0), getFloat32(-0)), + (getUInt32(+0), getFloat32(+0.5)), + (getUInt32(+127), getFloat32(+127.5)), + (getUInt32(+255), getFloat32(+255.5)), + (getUInt32(+32767), getFloat32(+32767.5)), + (getUInt32(+65535), getFloat32(+65535.5)), + (getUInt32(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, UInt32($0.1)) +} + +FixedPointConversion_Release64_ToUInt32 +.test("FromFloat32_NeverFails") +.forEach(in: [ + (getUInt32(+0), getFloat32(+0)), + (getUInt32(+0), getFloat32(-0)), + (getUInt32(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToUInt32 +.test("FromFloat32_AlwaysTraps") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-1), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt32($0)) +} + +FixedPointConversion_Release64_ToUInt32 +.test("FromFloat32_AlwaysFails") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-1), + getFloat32(-0.5), + getFloat32(+0.5), + getFloat32(+127.5), + getFloat32(+255.5), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectNil(UInt32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float64: (-9007199254740991)...(9007199254740991) +// MARK: Float64: (-9007199254740991)...(+9007199254740991) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(-9007199254740991)_AlwaysTraps") { - let input = getFloat64(-9007199254740991) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(-9007199254740991)_AlwaysFails") { - let input = getFloat64(-9007199254740991) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(-32768.5)_AlwaysTraps") { - let input = getFloat64(-32768.5) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(-32768.5)_AlwaysFails") { - let input = getFloat64(-32768.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(-128.5)_AlwaysTraps") { - let input = getFloat64(-128.5) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(-128.5)_AlwaysFails") { - let input = getFloat64(-128.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(-1)_AlwaysTraps") { - let input = getFloat64(-1) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(-1)_AlwaysFails") { - let input = getFloat64(-1) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(-0.5)_NeverTraps") { - let input = getFloat64(-0.5) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(-0.5)_AlwaysFails") { - let input = getFloat64(-0.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(0)_NeverTraps") { - let input = getFloat64(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(0)_NeverFails") { - let input = getFloat64(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(-0.0)_NeverTraps") { - let input = getFloat64(-0.0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(-0.0)_NeverFails") { - let input = getFloat64(-0.0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(0.0)_NeverTraps") { - let input = getFloat64(0.0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(0.0)_NeverFails") { - let input = getFloat64(0.0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(0.5)_NeverTraps") { - let input = getFloat64(0.5) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(0.5)_AlwaysFails") { - let input = getFloat64(0.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(127.5)_NeverTraps") { - let input = getFloat64(127.5) - let actual = UInt32(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(127.5)_AlwaysFails") { - let input = getFloat64(127.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(255.5)_NeverTraps") { - let input = getFloat64(255.5) - let actual = UInt32(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(255.5)_AlwaysFails") { - let input = getFloat64(255.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(32767.5)_NeverTraps") { - let input = getFloat64(32767.5) - let actual = UInt32(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(32767.5)_AlwaysFails") { - let input = getFloat64(32767.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(65535.5)_NeverTraps") { - let input = getFloat64(65535.5) - let actual = UInt32(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(65535.5)_AlwaysFails") { - let input = getFloat64(65535.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(4294967295)_NeverTraps") { - let input = getFloat64(4294967295) - let actual = UInt32(input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(4294967295)_NeverFails") { - let input = getFloat64(4294967295) - let actual = UInt32(exactly: input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(4294967296)_AlwaysTraps") { - let input = getFloat64(4294967296) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(4294967296)_AlwaysFails") { - let input = getFloat64(4294967296) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(9007199254740991)_AlwaysTraps") { - let input = getFloat64(9007199254740991) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(9007199254740991)_AlwaysFails") { - let input = getFloat64(9007199254740991) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(-.infinity)_AlwaysTraps") { - let input = getFloat64(-.infinity) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(-.infinity)_AlwaysFails") { - let input = getFloat64(-.infinity) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(+.infinity)_AlwaysTraps") { - let input = getFloat64(+.infinity) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(+.infinity)_AlwaysFails") { - let input = getFloat64(+.infinity) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(-.nan)_AlwaysTraps") { - let input = getFloat64(-.nan) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(-.nan)_AlwaysFails") { - let input = getFloat64(-.nan) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(+.nan)_AlwaysTraps") { - let input = getFloat64(+.nan) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(+.nan)_AlwaysFails") { - let input = getFloat64(+.nan) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(-.signalingNaN)_AlwaysTraps") { - let input = getFloat64(-.signalingNaN) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(-.signalingNaN)_AlwaysFails") { - let input = getFloat64(-.signalingNaN) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(+.signalingNaN)_AlwaysTraps") { - let input = getFloat64(+.signalingNaN) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat64(+.signalingNaN)_AlwaysFails") { - let input = getFloat64(+.signalingNaN) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt32 +.test("FromFloat64_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getFloat64(-0.5)), + (getUInt32(+0), getFloat64(+0)), + (getUInt32(+0), getFloat64(-0)), + (getUInt32(+0), getFloat64(+0.5)), + (getUInt32(+127), getFloat64(+127.5)), + (getUInt32(+255), getFloat64(+255.5)), + (getUInt32(+32767), getFloat64(+32767.5)), + (getUInt32(+65535), getFloat64(+65535.5)), + (getUInt32(+4294967295), getFloat64(+4294967295)), +]) { + expectEqual($0.0, UInt32($0.1)) +} + +FixedPointConversion_Release64_ToUInt32 +.test("FromFloat64_NeverFails") +.forEach(in: [ + (getUInt32(+0), getFloat64(+0)), + (getUInt32(+0), getFloat64(-0)), + (getUInt32(+4294967295), getFloat64(+4294967295)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToUInt32 +.test("FromFloat64_AlwaysTraps") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-1), + getFloat64(+4294967296), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt32($0)) +} + +FixedPointConversion_Release64_ToUInt32 +.test("FromFloat64_AlwaysFails") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-1), + getFloat64(-0.5), + getFloat64(+0.5), + getFloat64(+127.5), + getFloat64(+255.5), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(+4294967296), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectNil(UInt32(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float80: (-18446744073709551615)...(18446744073709551615) +// MARK: Float80: (-18446744073709551615)...(+18446744073709551615) //===----------------------------------------------------------------------===// #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(-18446744073709551615)_AlwaysTraps") { - let input = getFloat80(-18446744073709551615) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(-18446744073709551615)_AlwaysFails") { - let input = getFloat80(-18446744073709551615) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(-32768.5)_AlwaysTraps") { - let input = getFloat80(-32768.5) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(-32768.5)_AlwaysFails") { - let input = getFloat80(-32768.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(-128.5)_AlwaysTraps") { - let input = getFloat80(-128.5) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(-128.5)_AlwaysFails") { - let input = getFloat80(-128.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(-1)_AlwaysTraps") { - let input = getFloat80(-1) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(-1)_AlwaysFails") { - let input = getFloat80(-1) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(-0.5)_NeverTraps") { - let input = getFloat80(-0.5) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(-0.5)_AlwaysFails") { - let input = getFloat80(-0.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(0)_NeverTraps") { - let input = getFloat80(0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(0)_NeverFails") { - let input = getFloat80(0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(-0.0)_NeverTraps") { - let input = getFloat80(-0.0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(-0.0)_NeverFails") { - let input = getFloat80(-0.0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(0.0)_NeverTraps") { - let input = getFloat80(0.0) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(0.0)_NeverFails") { - let input = getFloat80(0.0) - let actual = UInt32(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(0.5)_NeverTraps") { - let input = getFloat80(0.5) - let actual = UInt32(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(0.5)_AlwaysFails") { - let input = getFloat80(0.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(127.5)_NeverTraps") { - let input = getFloat80(127.5) - let actual = UInt32(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(127.5)_AlwaysFails") { - let input = getFloat80(127.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(255.5)_NeverTraps") { - let input = getFloat80(255.5) - let actual = UInt32(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(255.5)_AlwaysFails") { - let input = getFloat80(255.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(32767.5)_NeverTraps") { - let input = getFloat80(32767.5) - let actual = UInt32(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(32767.5)_AlwaysFails") { - let input = getFloat80(32767.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(65535.5)_NeverTraps") { - let input = getFloat80(65535.5) - let actual = UInt32(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(65535.5)_AlwaysFails") { - let input = getFloat80(65535.5) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(4294967295)_NeverTraps") { - let input = getFloat80(4294967295) - let actual = UInt32(input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(4294967295)_NeverFails") { - let input = getFloat80(4294967295) - let actual = UInt32(exactly: input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(4294967296)_AlwaysTraps") { - let input = getFloat80(4294967296) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(4294967296)_AlwaysFails") { - let input = getFloat80(4294967296) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(18446744073709551615)_AlwaysTraps") { - let input = getFloat80(18446744073709551615) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(18446744073709551615)_AlwaysFails") { - let input = getFloat80(18446744073709551615) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(-.infinity)_AlwaysTraps") { - let input = getFloat80(-.infinity) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(-.infinity)_AlwaysFails") { - let input = getFloat80(-.infinity) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(+.infinity)_AlwaysTraps") { - let input = getFloat80(+.infinity) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(+.infinity)_AlwaysFails") { - let input = getFloat80(+.infinity) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(-.nan)_AlwaysTraps") { - let input = getFloat80(-.nan) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(-.nan)_AlwaysFails") { - let input = getFloat80(-.nan) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(+.nan)_AlwaysTraps") { - let input = getFloat80(+.nan) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(+.nan)_AlwaysFails") { - let input = getFloat80(+.nan) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(-.signalingNaN)_AlwaysTraps") { - let input = getFloat80(-.signalingNaN) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(-.signalingNaN)_AlwaysFails") { - let input = getFloat80(-.signalingNaN) - let actual = UInt32(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(+.signalingNaN)_AlwaysTraps") { - let input = getFloat80(+.signalingNaN) - expectCrash { - let actual = UInt32(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt32.test("FromFloat80(+.signalingNaN)_AlwaysFails") { - let input = getFloat80(+.signalingNaN) - let actual = UInt32(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt32 +.test("FromFloat80_NeverTraps") +.forEach(in: [ + (getUInt32(+0), getFloat80(-0.5)), + (getUInt32(+0), getFloat80(+0)), + (getUInt32(+0), getFloat80(-0)), + (getUInt32(+0), getFloat80(+0.5)), + (getUInt32(+127), getFloat80(+127.5)), + (getUInt32(+255), getFloat80(+255.5)), + (getUInt32(+32767), getFloat80(+32767.5)), + (getUInt32(+65535), getFloat80(+65535.5)), + (getUInt32(+4294967295), getFloat80(+4294967295)), +]) { + expectEqual($0.0, UInt32($0.1)) +} + +FixedPointConversion_Release64_ToUInt32 +.test("FromFloat80_NeverFails") +.forEach(in: [ + (getUInt32(+0), getFloat80(+0)), + (getUInt32(+0), getFloat80(-0)), + (getUInt32(+4294967295), getFloat80(+4294967295)), +]) { + expectEqual($0.0, UInt32(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToUInt32 +.test("FromFloat80_AlwaysTraps") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-1), + getFloat80(+4294967296), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt32($0)) +} + +FixedPointConversion_Release64_ToUInt32 +.test("FromFloat80_AlwaysFails") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-1), + getFloat80(-0.5), + getFloat80(+0.5), + getFloat80(+127.5), + getFloat80(+255.5), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(+4294967296), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectNil(UInt32(exactly: $0)) } #endif // Float80 diff --git a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release64_ToUInt64.swift b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release64_ToUInt64.swift index d56af408b0bb2..02e39e9966a98 100644 --- a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release64_ToUInt64.swift +++ b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release64_ToUInt64.swift @@ -14,1464 +14,609 @@ import StdlibUnittest -let FixedPointConversion_Release64_ToUInt64 = TestSuite("FixedPointConversion_Release64_ToUInt64") +let FixedPointConversion_Release64_ToUInt64 = TestSuite( + "FixedPointConversion_Release64_ToUInt64" +) //===----------------------------------------------------------------------===// -// MARK: UInt8: (0)...(255) +// MARK: UInt8: (+0)...(+255) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt64.test("FromUInt8(0)_NeverTraps") { - let input = getUInt8(0) - let actual = UInt64(input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt64 +.test("FromUInt8_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getUInt8(+0)), + (getUInt64(+255), getUInt8(+255)), +]) { + expectEqual($0.0, UInt64($0.1)) } -FixedPointConversion_Release64_ToUInt64.test("FromUInt8(0)_NeverFails") { - let input = getUInt8(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromUInt8(255)_NeverTraps") { - let input = getUInt8(255) - let actual = UInt64(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromUInt8(255)_NeverFails") { - let input = getUInt8(255) - let actual = UInt64(exactly: input) - expectEqual(255, actual) +FixedPointConversion_Release64_ToUInt64 +.test("FromUInt8_NeverFails") +.forEach(in: [ + (getUInt64(+0), getUInt8(+0)), + (getUInt64(+255), getUInt8(+255)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int8: (-128)...(127) +// MARK: Int8: (-128)...(+127) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt64.test("FromInt8(-128)_AlwaysTraps") { - let input = getInt8(-128) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromInt8(-128)_AlwaysFails") { - let input = getInt8(-128) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromInt8(-1)_AlwaysTraps") { - let input = getInt8(-1) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromInt8(-1)_AlwaysFails") { - let input = getInt8(-1) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromInt8(0)_NeverTraps") { - let input = getInt8(0) - let actual = UInt64(input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt64 +.test("FromInt8_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getInt8(+0)), + (getUInt64(+127), getInt8(+127)), +]) { + expectEqual($0.0, UInt64($0.1)) } -FixedPointConversion_Release64_ToUInt64.test("FromInt8(0)_NeverFails") { - let input = getInt8(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt64 +.test("FromInt8_NeverFails") +.forEach(in: [ + (getUInt64(+0), getInt8(+0)), + (getUInt64(+127), getInt8(+127)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) } -FixedPointConversion_Release64_ToUInt64.test("FromInt8(127)_NeverTraps") { - let input = getInt8(127) - let actual = UInt64(input) - expectEqual(127, actual) +FixedPointConversion_Release64_ToUInt64 +.test("FromInt8_AlwaysTraps") +.forEach(in: [ + getInt8(-128), + getInt8(-1), +]) { + expectCrashLater() + _blackHole(UInt64($0)) } -FixedPointConversion_Release64_ToUInt64.test("FromInt8(127)_NeverFails") { - let input = getInt8(127) - let actual = UInt64(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Release64_ToUInt64 +.test("FromInt8_AlwaysFails") +.forEach(in: [ + getInt8(-128), + getInt8(-1), +]) { + expectNil(UInt64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt16: (0)...(65535) +// MARK: UInt16: (+0)...(+65535) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt64.test("FromUInt16(0)_NeverTraps") { - let input = getUInt16(0) - let actual = UInt64(input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt64 +.test("FromUInt16_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getUInt16(+0)), + (getUInt64(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, UInt64($0.1)) } -FixedPointConversion_Release64_ToUInt64.test("FromUInt16(0)_NeverFails") { - let input = getUInt16(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromUInt16(65535)_NeverTraps") { - let input = getUInt16(65535) - let actual = UInt64(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromUInt16(65535)_NeverFails") { - let input = getUInt16(65535) - let actual = UInt64(exactly: input) - expectEqual(65535, actual) +FixedPointConversion_Release64_ToUInt64 +.test("FromUInt16_NeverFails") +.forEach(in: [ + (getUInt64(+0), getUInt16(+0)), + (getUInt64(+65535), getUInt16(+65535)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int16: (-32768)...(32767) +// MARK: Int16: (-32768)...(+32767) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt64.test("FromInt16(-32768)_AlwaysTraps") { - let input = getInt16(-32768) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromInt16(-32768)_AlwaysFails") { - let input = getInt16(-32768) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromInt16(-1)_AlwaysTraps") { - let input = getInt16(-1) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromInt16(-1)_AlwaysFails") { - let input = getInt16(-1) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromInt16(0)_NeverTraps") { - let input = getInt16(0) - let actual = UInt64(input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt64 +.test("FromInt16_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getInt16(+0)), + (getUInt64(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, UInt64($0.1)) } -FixedPointConversion_Release64_ToUInt64.test("FromInt16(0)_NeverFails") { - let input = getInt16(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt64 +.test("FromInt16_NeverFails") +.forEach(in: [ + (getUInt64(+0), getInt16(+0)), + (getUInt64(+32767), getInt16(+32767)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) } -FixedPointConversion_Release64_ToUInt64.test("FromInt16(32767)_NeverTraps") { - let input = getInt16(32767) - let actual = UInt64(input) - expectEqual(32767, actual) +FixedPointConversion_Release64_ToUInt64 +.test("FromInt16_AlwaysTraps") +.forEach(in: [ + getInt16(-32768), + getInt16(-1), +]) { + expectCrashLater() + _blackHole(UInt64($0)) } -FixedPointConversion_Release64_ToUInt64.test("FromInt16(32767)_NeverFails") { - let input = getInt16(32767) - let actual = UInt64(exactly: input) - expectEqual(32767, actual) +FixedPointConversion_Release64_ToUInt64 +.test("FromInt16_AlwaysFails") +.forEach(in: [ + getInt16(-32768), + getInt16(-1), +]) { + expectNil(UInt64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt32: (0)...(4294967295) +// MARK: UInt32: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt64.test("FromUInt32(0)_NeverTraps") { - let input = getUInt32(0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromUInt32(0)_NeverFails") { - let input = getUInt32(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt64 +.test("FromUInt32_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getUInt32(+0)), + (getUInt64(+4294967295), getUInt32(+4294967295)), +]) { + expectEqual($0.0, UInt64($0.1)) } -FixedPointConversion_Release64_ToUInt64.test("FromUInt32(4294967295)_NeverTraps") { - let input = getUInt32(4294967295) - let actual = UInt64(input) - expectEqual(4294967295, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromUInt32(4294967295)_NeverFails") { - let input = getUInt32(4294967295) - let actual = UInt64(exactly: input) - expectEqual(4294967295, actual) +FixedPointConversion_Release64_ToUInt64 +.test("FromUInt32_NeverFails") +.forEach(in: [ + (getUInt64(+0), getUInt32(+0)), + (getUInt64(+4294967295), getUInt32(+4294967295)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int32: (-2147483648)...(2147483647) +// MARK: Int32: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt64.test("FromInt32(-2147483648)_AlwaysTraps") { - let input = getInt32(-2147483648) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromInt32(-2147483648)_AlwaysFails") { - let input = getInt32(-2147483648) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromInt32(-1)_AlwaysTraps") { - let input = getInt32(-1) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } +FixedPointConversion_Release64_ToUInt64 +.test("FromInt32_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getInt32(+0)), + (getUInt64(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, UInt64($0.1)) } -FixedPointConversion_Release64_ToUInt64.test("FromInt32(-1)_AlwaysFails") { - let input = getInt32(-1) - let actual = UInt64(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt64 +.test("FromInt32_NeverFails") +.forEach(in: [ + (getUInt64(+0), getInt32(+0)), + (getUInt64(+2147483647), getInt32(+2147483647)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) } -FixedPointConversion_Release64_ToUInt64.test("FromInt32(0)_NeverTraps") { - let input = getInt32(0) - let actual = UInt64(input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt64 +.test("FromInt32_AlwaysTraps") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-1), +]) { + expectCrashLater() + _blackHole(UInt64($0)) } -FixedPointConversion_Release64_ToUInt64.test("FromInt32(0)_NeverFails") { - let input = getInt32(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromInt32(2147483647)_NeverTraps") { - let input = getInt32(2147483647) - let actual = UInt64(input) - expectEqual(2147483647, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromInt32(2147483647)_NeverFails") { - let input = getInt32(2147483647) - let actual = UInt64(exactly: input) - expectEqual(2147483647, actual) +FixedPointConversion_Release64_ToUInt64 +.test("FromInt32_AlwaysFails") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-1), +]) { + expectNil(UInt64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt64: (0)...(18446744073709551615) +// MARK: UInt64: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt64.test("FromUInt64(0)_NeverTraps") { - let input = getUInt64(0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromUInt64(0)_NeverFails") { - let input = getUInt64(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt64 +.test("FromUInt64_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getUInt64(+0)), + (getUInt64(+18446744073709551615), getUInt64(+18446744073709551615)), +]) { + expectEqual($0.0, UInt64($0.1)) } -FixedPointConversion_Release64_ToUInt64.test("FromUInt64(18446744073709551615)_NeverTraps") { - let input = getUInt64(18446744073709551615) - let actual = UInt64(input) - expectEqual(18446744073709551615, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromUInt64(18446744073709551615)_NeverFails") { - let input = getUInt64(18446744073709551615) - let actual = UInt64(exactly: input) - expectEqual(18446744073709551615, actual) +FixedPointConversion_Release64_ToUInt64 +.test("FromUInt64_NeverFails") +.forEach(in: [ + (getUInt64(+0), getUInt64(+0)), + (getUInt64(+18446744073709551615), getUInt64(+18446744073709551615)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int64: (-9223372036854775808)...(9223372036854775807) +// MARK: Int64: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt64.test("FromInt64(-9223372036854775808)_AlwaysTraps") { - let input = getInt64(-9223372036854775808) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromInt64(-9223372036854775808)_AlwaysFails") { - let input = getInt64(-9223372036854775808) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromInt64(-1)_AlwaysTraps") { - let input = getInt64(-1) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromInt64(-1)_AlwaysFails") { - let input = getInt64(-1) - let actual = UInt64(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt64 +.test("FromInt64_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getInt64(+0)), + (getUInt64(+9223372036854775807), getInt64(+9223372036854775807)), +]) { + expectEqual($0.0, UInt64($0.1)) } -FixedPointConversion_Release64_ToUInt64.test("FromInt64(0)_NeverTraps") { - let input = getInt64(0) - let actual = UInt64(input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt64 +.test("FromInt64_NeverFails") +.forEach(in: [ + (getUInt64(+0), getInt64(+0)), + (getUInt64(+9223372036854775807), getInt64(+9223372036854775807)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) } -FixedPointConversion_Release64_ToUInt64.test("FromInt64(0)_NeverFails") { - let input = getInt64(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt64 +.test("FromInt64_AlwaysTraps") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-1), +]) { + expectCrashLater() + _blackHole(UInt64($0)) } -FixedPointConversion_Release64_ToUInt64.test("FromInt64(9223372036854775807)_NeverTraps") { - let input = getInt64(9223372036854775807) - let actual = UInt64(input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromInt64(9223372036854775807)_NeverFails") { - let input = getInt64(9223372036854775807) - let actual = UInt64(exactly: input) - expectEqual(9223372036854775807, actual) +FixedPointConversion_Release64_ToUInt64 +.test("FromInt64_AlwaysFails") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-1), +]) { + expectNil(UInt64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt: (0)...(18446744073709551615) +// MARK: UInt: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt64.test("FromUInt(0)_NeverTraps") { - let input = getUInt(0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromUInt(0)_NeverFails") { - let input = getUInt(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromUInt(18446744073709551615)_NeverTraps") { - let input = getUInt(18446744073709551615) - let actual = UInt64(input) - expectEqual(18446744073709551615, actual) +FixedPointConversion_Release64_ToUInt64 +.test("FromUInt_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getUInt(+0)), + (getUInt64(+18446744073709551615), getUInt(+18446744073709551615)), +]) { + expectEqual($0.0, UInt64($0.1)) } -FixedPointConversion_Release64_ToUInt64.test("FromUInt(18446744073709551615)_NeverFails") { - let input = getUInt(18446744073709551615) - let actual = UInt64(exactly: input) - expectEqual(18446744073709551615, actual) +FixedPointConversion_Release64_ToUInt64 +.test("FromUInt_NeverFails") +.forEach(in: [ + (getUInt64(+0), getUInt(+0)), + (getUInt64(+18446744073709551615), getUInt(+18446744073709551615)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int: (-9223372036854775808)...(9223372036854775807) +// MARK: Int: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt64.test("FromInt(-9223372036854775808)_AlwaysTraps") { - let input = getInt(-9223372036854775808) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromInt(-9223372036854775808)_AlwaysFails") { - let input = getInt(-9223372036854775808) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromInt(-1)_AlwaysTraps") { - let input = getInt(-1) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromInt(-1)_AlwaysFails") { - let input = getInt(-1) - let actual = UInt64(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt64 +.test("FromInt_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getInt(+0)), + (getUInt64(+9223372036854775807), getInt(+9223372036854775807)), +]) { + expectEqual($0.0, UInt64($0.1)) } -FixedPointConversion_Release64_ToUInt64.test("FromInt(0)_NeverTraps") { - let input = getInt(0) - let actual = UInt64(input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt64 +.test("FromInt_NeverFails") +.forEach(in: [ + (getUInt64(+0), getInt(+0)), + (getUInt64(+9223372036854775807), getInt(+9223372036854775807)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) } -FixedPointConversion_Release64_ToUInt64.test("FromInt(0)_NeverFails") { - let input = getInt(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt64 +.test("FromInt_AlwaysTraps") +.forEach(in: [ + getInt(-9223372036854775808), + getInt(-1), +]) { + expectCrashLater() + _blackHole(UInt64($0)) } -FixedPointConversion_Release64_ToUInt64.test("FromInt(9223372036854775807)_NeverTraps") { - let input = getInt(9223372036854775807) - let actual = UInt64(input) - expectEqual(9223372036854775807, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromInt(9223372036854775807)_NeverFails") { - let input = getInt(9223372036854775807) - let actual = UInt64(exactly: input) - expectEqual(9223372036854775807, actual) +FixedPointConversion_Release64_ToUInt64 +.test("FromInt_AlwaysFails") +.forEach(in: [ + getInt(-9223372036854775808), + getInt(-1), +]) { + expectNil(UInt64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float16: (-2047)...(2047) +// MARK: Float16: (-2047)...(+2047) //===----------------------------------------------------------------------===// #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -FixedPointConversion_Release64_ToUInt64.test("FromFloat16(-2047)_AlwaysTraps") { - let input = getFloat16(-2047) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat16(-2047)_AlwaysFails") { - let input = getFloat16(-2047) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat16(-128.5)_AlwaysTraps") { - let input = getFloat16(-128.5) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat16(-128.5)_AlwaysFails") { - let input = getFloat16(-128.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat16(-1)_AlwaysTraps") { - let input = getFloat16(-1) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat16(-1)_AlwaysFails") { - let input = getFloat16(-1) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat16(-0.5)_NeverTraps") { - let input = getFloat16(-0.5) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat16(-0.5)_AlwaysFails") { - let input = getFloat16(-0.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat16(0)_NeverTraps") { - let input = getFloat16(0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat16(0)_NeverFails") { - let input = getFloat16(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat16(-0.0)_NeverTraps") { - let input = getFloat16(-0.0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat16(-0.0)_NeverFails") { - let input = getFloat16(-0.0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat16(0.0)_NeverTraps") { - let input = getFloat16(0.0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat16(0.0)_NeverFails") { - let input = getFloat16(0.0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat16(0.5)_NeverTraps") { - let input = getFloat16(0.5) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat16(0.5)_AlwaysFails") { - let input = getFloat16(0.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat16(127.5)_NeverTraps") { - let input = getFloat16(127.5) - let actual = UInt64(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat16(127.5)_AlwaysFails") { - let input = getFloat16(127.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat16(255.5)_NeverTraps") { - let input = getFloat16(255.5) - let actual = UInt64(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat16(255.5)_AlwaysFails") { - let input = getFloat16(255.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat16(2047)_NeverTraps") { - let input = getFloat16(2047) - let actual = UInt64(input) - expectEqual(2047, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat16(2047)_NeverFails") { - let input = getFloat16(2047) - let actual = UInt64(exactly: input) - expectEqual(2047, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat16(-.infinity)_AlwaysTraps") { - let input = getFloat16(-.infinity) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat16(-.infinity)_AlwaysFails") { - let input = getFloat16(-.infinity) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat16(+.infinity)_AlwaysTraps") { - let input = getFloat16(+.infinity) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat16(+.infinity)_AlwaysFails") { - let input = getFloat16(+.infinity) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat16(-.nan)_AlwaysTraps") { - let input = getFloat16(-.nan) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat16(-.nan)_AlwaysFails") { - let input = getFloat16(-.nan) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat16(+.nan)_AlwaysTraps") { - let input = getFloat16(+.nan) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat16(+.nan)_AlwaysFails") { - let input = getFloat16(+.nan) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat16(-.signalingNaN)_AlwaysTraps") { - let input = getFloat16(-.signalingNaN) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat16(-.signalingNaN)_AlwaysFails") { - let input = getFloat16(-.signalingNaN) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat16(+.signalingNaN)_AlwaysTraps") { - let input = getFloat16(+.signalingNaN) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat16(+.signalingNaN)_AlwaysFails") { - let input = getFloat16(+.signalingNaN) - let actual = UInt64(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt64 +.test("FromFloat16_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getFloat16(-0.5)), + (getUInt64(+0), getFloat16(+0)), + (getUInt64(+0), getFloat16(-0)), + (getUInt64(+0), getFloat16(+0.5)), + (getUInt64(+127), getFloat16(+127.5)), + (getUInt64(+255), getFloat16(+255.5)), + (getUInt64(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, UInt64($0.1)) +} + +FixedPointConversion_Release64_ToUInt64 +.test("FromFloat16_NeverFails") +.forEach(in: [ + (getUInt64(+0), getFloat16(+0)), + (getUInt64(+0), getFloat16(-0)), + (getUInt64(+2047), getFloat16(+2047)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToUInt64 +.test("FromFloat16_AlwaysTraps") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-128.5), + getFloat16(-1), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt64($0)) +} + +FixedPointConversion_Release64_ToUInt64 +.test("FromFloat16_AlwaysFails") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-128.5), + getFloat16(-1), + getFloat16(-0.5), + getFloat16(+0.5), + getFloat16(+127.5), + getFloat16(+255.5), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectNil(UInt64(exactly: $0)) } } #endif // Float16 //===----------------------------------------------------------------------===// -// MARK: Float32: (-16777215)...(16777215) +// MARK: Float32: (-16777215)...(+16777215) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt64.test("FromFloat32(-16777215)_AlwaysTraps") { - let input = getFloat32(-16777215) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat32(-16777215)_AlwaysFails") { - let input = getFloat32(-16777215) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat32(-32768.5)_AlwaysTraps") { - let input = getFloat32(-32768.5) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat32(-32768.5)_AlwaysFails") { - let input = getFloat32(-32768.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat32(-128.5)_AlwaysTraps") { - let input = getFloat32(-128.5) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat32(-128.5)_AlwaysFails") { - let input = getFloat32(-128.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat32(-1)_AlwaysTraps") { - let input = getFloat32(-1) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat32(-1)_AlwaysFails") { - let input = getFloat32(-1) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat32(-0.5)_NeverTraps") { - let input = getFloat32(-0.5) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat32(-0.5)_AlwaysFails") { - let input = getFloat32(-0.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat32(0)_NeverTraps") { - let input = getFloat32(0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat32(0)_NeverFails") { - let input = getFloat32(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat32(-0.0)_NeverTraps") { - let input = getFloat32(-0.0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat32(-0.0)_NeverFails") { - let input = getFloat32(-0.0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat32(0.0)_NeverTraps") { - let input = getFloat32(0.0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat32(0.0)_NeverFails") { - let input = getFloat32(0.0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat32(0.5)_NeverTraps") { - let input = getFloat32(0.5) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat32(0.5)_AlwaysFails") { - let input = getFloat32(0.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat32(127.5)_NeverTraps") { - let input = getFloat32(127.5) - let actual = UInt64(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat32(127.5)_AlwaysFails") { - let input = getFloat32(127.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat32(255.5)_NeverTraps") { - let input = getFloat32(255.5) - let actual = UInt64(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat32(255.5)_AlwaysFails") { - let input = getFloat32(255.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat32(32767.5)_NeverTraps") { - let input = getFloat32(32767.5) - let actual = UInt64(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat32(32767.5)_AlwaysFails") { - let input = getFloat32(32767.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat32(65535.5)_NeverTraps") { - let input = getFloat32(65535.5) - let actual = UInt64(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat32(65535.5)_AlwaysFails") { - let input = getFloat32(65535.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat32(16777215)_NeverTraps") { - let input = getFloat32(16777215) - let actual = UInt64(input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat32(16777215)_NeverFails") { - let input = getFloat32(16777215) - let actual = UInt64(exactly: input) - expectEqual(16777215, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat32(-.infinity)_AlwaysTraps") { - let input = getFloat32(-.infinity) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat32(-.infinity)_AlwaysFails") { - let input = getFloat32(-.infinity) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat32(+.infinity)_AlwaysTraps") { - let input = getFloat32(+.infinity) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat32(+.infinity)_AlwaysFails") { - let input = getFloat32(+.infinity) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat32(-.nan)_AlwaysTraps") { - let input = getFloat32(-.nan) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat32(-.nan)_AlwaysFails") { - let input = getFloat32(-.nan) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat32(+.nan)_AlwaysTraps") { - let input = getFloat32(+.nan) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat32(+.nan)_AlwaysFails") { - let input = getFloat32(+.nan) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat32(-.signalingNaN)_AlwaysTraps") { - let input = getFloat32(-.signalingNaN) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat32(-.signalingNaN)_AlwaysFails") { - let input = getFloat32(-.signalingNaN) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat32(+.signalingNaN)_AlwaysTraps") { - let input = getFloat32(+.signalingNaN) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat32(+.signalingNaN)_AlwaysFails") { - let input = getFloat32(+.signalingNaN) - let actual = UInt64(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt64 +.test("FromFloat32_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getFloat32(-0.5)), + (getUInt64(+0), getFloat32(+0)), + (getUInt64(+0), getFloat32(-0)), + (getUInt64(+0), getFloat32(+0.5)), + (getUInt64(+127), getFloat32(+127.5)), + (getUInt64(+255), getFloat32(+255.5)), + (getUInt64(+32767), getFloat32(+32767.5)), + (getUInt64(+65535), getFloat32(+65535.5)), + (getUInt64(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, UInt64($0.1)) +} + +FixedPointConversion_Release64_ToUInt64 +.test("FromFloat32_NeverFails") +.forEach(in: [ + (getUInt64(+0), getFloat32(+0)), + (getUInt64(+0), getFloat32(-0)), + (getUInt64(+16777215), getFloat32(+16777215)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToUInt64 +.test("FromFloat32_AlwaysTraps") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-1), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt64($0)) +} + +FixedPointConversion_Release64_ToUInt64 +.test("FromFloat32_AlwaysFails") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-1), + getFloat32(-0.5), + getFloat32(+0.5), + getFloat32(+127.5), + getFloat32(+255.5), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectNil(UInt64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float64: (-9007199254740991)...(9007199254740991) +// MARK: Float64: (-9007199254740991)...(+9007199254740991) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt64.test("FromFloat64(-9007199254740991)_AlwaysTraps") { - let input = getFloat64(-9007199254740991) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat64(-9007199254740991)_AlwaysFails") { - let input = getFloat64(-9007199254740991) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat64(-32768.5)_AlwaysTraps") { - let input = getFloat64(-32768.5) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat64(-32768.5)_AlwaysFails") { - let input = getFloat64(-32768.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat64(-128.5)_AlwaysTraps") { - let input = getFloat64(-128.5) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat64(-128.5)_AlwaysFails") { - let input = getFloat64(-128.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat64(-1)_AlwaysTraps") { - let input = getFloat64(-1) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat64(-1)_AlwaysFails") { - let input = getFloat64(-1) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat64(-0.5)_NeverTraps") { - let input = getFloat64(-0.5) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat64(-0.5)_AlwaysFails") { - let input = getFloat64(-0.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat64(0)_NeverTraps") { - let input = getFloat64(0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat64(0)_NeverFails") { - let input = getFloat64(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat64(-0.0)_NeverTraps") { - let input = getFloat64(-0.0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat64(-0.0)_NeverFails") { - let input = getFloat64(-0.0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat64(0.0)_NeverTraps") { - let input = getFloat64(0.0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat64(0.0)_NeverFails") { - let input = getFloat64(0.0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat64(0.5)_NeverTraps") { - let input = getFloat64(0.5) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat64(0.5)_AlwaysFails") { - let input = getFloat64(0.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat64(127.5)_NeverTraps") { - let input = getFloat64(127.5) - let actual = UInt64(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat64(127.5)_AlwaysFails") { - let input = getFloat64(127.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat64(255.5)_NeverTraps") { - let input = getFloat64(255.5) - let actual = UInt64(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat64(255.5)_AlwaysFails") { - let input = getFloat64(255.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat64(32767.5)_NeverTraps") { - let input = getFloat64(32767.5) - let actual = UInt64(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat64(32767.5)_AlwaysFails") { - let input = getFloat64(32767.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat64(65535.5)_NeverTraps") { - let input = getFloat64(65535.5) - let actual = UInt64(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat64(65535.5)_AlwaysFails") { - let input = getFloat64(65535.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat64(9007199254740991)_NeverTraps") { - let input = getFloat64(9007199254740991) - let actual = UInt64(input) - expectEqual(9007199254740991, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat64(9007199254740991)_NeverFails") { - let input = getFloat64(9007199254740991) - let actual = UInt64(exactly: input) - expectEqual(9007199254740991, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat64(-.infinity)_AlwaysTraps") { - let input = getFloat64(-.infinity) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat64(-.infinity)_AlwaysFails") { - let input = getFloat64(-.infinity) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat64(+.infinity)_AlwaysTraps") { - let input = getFloat64(+.infinity) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat64(+.infinity)_AlwaysFails") { - let input = getFloat64(+.infinity) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat64(-.nan)_AlwaysTraps") { - let input = getFloat64(-.nan) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat64(-.nan)_AlwaysFails") { - let input = getFloat64(-.nan) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat64(+.nan)_AlwaysTraps") { - let input = getFloat64(+.nan) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat64(+.nan)_AlwaysFails") { - let input = getFloat64(+.nan) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat64(-.signalingNaN)_AlwaysTraps") { - let input = getFloat64(-.signalingNaN) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat64(-.signalingNaN)_AlwaysFails") { - let input = getFloat64(-.signalingNaN) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat64(+.signalingNaN)_AlwaysTraps") { - let input = getFloat64(+.signalingNaN) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat64(+.signalingNaN)_AlwaysFails") { - let input = getFloat64(+.signalingNaN) - let actual = UInt64(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt64 +.test("FromFloat64_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getFloat64(-0.5)), + (getUInt64(+0), getFloat64(+0)), + (getUInt64(+0), getFloat64(-0)), + (getUInt64(+0), getFloat64(+0.5)), + (getUInt64(+127), getFloat64(+127.5)), + (getUInt64(+255), getFloat64(+255.5)), + (getUInt64(+32767), getFloat64(+32767.5)), + (getUInt64(+65535), getFloat64(+65535.5)), + (getUInt64(+9007199254740991), getFloat64(+9007199254740991)), +]) { + expectEqual($0.0, UInt64($0.1)) +} + +FixedPointConversion_Release64_ToUInt64 +.test("FromFloat64_NeverFails") +.forEach(in: [ + (getUInt64(+0), getFloat64(+0)), + (getUInt64(+0), getFloat64(-0)), + (getUInt64(+9007199254740991), getFloat64(+9007199254740991)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToUInt64 +.test("FromFloat64_AlwaysTraps") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-1), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt64($0)) +} + +FixedPointConversion_Release64_ToUInt64 +.test("FromFloat64_AlwaysFails") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-1), + getFloat64(-0.5), + getFloat64(+0.5), + getFloat64(+127.5), + getFloat64(+255.5), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectNil(UInt64(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float80: (-18446744073709551615)...(18446744073709551615) +// MARK: Float80: (-18446744073709551615)...(+18446744073709551615) //===----------------------------------------------------------------------===// #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(-18446744073709551615)_AlwaysTraps") { - let input = getFloat80(-18446744073709551615) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(-18446744073709551615)_AlwaysFails") { - let input = getFloat80(-18446744073709551615) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(-32768.5)_AlwaysTraps") { - let input = getFloat80(-32768.5) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(-32768.5)_AlwaysFails") { - let input = getFloat80(-32768.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(-128.5)_AlwaysTraps") { - let input = getFloat80(-128.5) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(-128.5)_AlwaysFails") { - let input = getFloat80(-128.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(-1)_AlwaysTraps") { - let input = getFloat80(-1) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(-1)_AlwaysFails") { - let input = getFloat80(-1) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(-0.5)_NeverTraps") { - let input = getFloat80(-0.5) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(-0.5)_AlwaysFails") { - let input = getFloat80(-0.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(0)_NeverTraps") { - let input = getFloat80(0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(0)_NeverFails") { - let input = getFloat80(0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(-0.0)_NeverTraps") { - let input = getFloat80(-0.0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(-0.0)_NeverFails") { - let input = getFloat80(-0.0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(0.0)_NeverTraps") { - let input = getFloat80(0.0) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(0.0)_NeverFails") { - let input = getFloat80(0.0) - let actual = UInt64(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(0.5)_NeverTraps") { - let input = getFloat80(0.5) - let actual = UInt64(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(0.5)_AlwaysFails") { - let input = getFloat80(0.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(127.5)_NeverTraps") { - let input = getFloat80(127.5) - let actual = UInt64(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(127.5)_AlwaysFails") { - let input = getFloat80(127.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(255.5)_NeverTraps") { - let input = getFloat80(255.5) - let actual = UInt64(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(255.5)_AlwaysFails") { - let input = getFloat80(255.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(32767.5)_NeverTraps") { - let input = getFloat80(32767.5) - let actual = UInt64(input) - expectEqual(32767, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(32767.5)_AlwaysFails") { - let input = getFloat80(32767.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(65535.5)_NeverTraps") { - let input = getFloat80(65535.5) - let actual = UInt64(input) - expectEqual(65535, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(65535.5)_AlwaysFails") { - let input = getFloat80(65535.5) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(18446744073709551615)_NeverTraps") { - let input = getFloat80(18446744073709551615) - let actual = UInt64(input) - expectEqual(18446744073709551615, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(18446744073709551615)_NeverFails") { - let input = getFloat80(18446744073709551615) - let actual = UInt64(exactly: input) - expectEqual(18446744073709551615, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(18446744073709551615)_NeverTraps") { - let input = getFloat80(18446744073709551615) - let actual = UInt64(input) - expectEqual(18446744073709551615, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(18446744073709551615)_NeverFails") { - let input = getFloat80(18446744073709551615) - let actual = UInt64(exactly: input) - expectEqual(18446744073709551615, actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(-.infinity)_AlwaysTraps") { - let input = getFloat80(-.infinity) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(-.infinity)_AlwaysFails") { - let input = getFloat80(-.infinity) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(+.infinity)_AlwaysTraps") { - let input = getFloat80(+.infinity) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(+.infinity)_AlwaysFails") { - let input = getFloat80(+.infinity) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(-.nan)_AlwaysTraps") { - let input = getFloat80(-.nan) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(-.nan)_AlwaysFails") { - let input = getFloat80(-.nan) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(+.nan)_AlwaysTraps") { - let input = getFloat80(+.nan) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(+.nan)_AlwaysFails") { - let input = getFloat80(+.nan) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(-.signalingNaN)_AlwaysTraps") { - let input = getFloat80(-.signalingNaN) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(-.signalingNaN)_AlwaysFails") { - let input = getFloat80(-.signalingNaN) - let actual = UInt64(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(+.signalingNaN)_AlwaysTraps") { - let input = getFloat80(+.signalingNaN) - expectCrash { - let actual = UInt64(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt64.test("FromFloat80(+.signalingNaN)_AlwaysFails") { - let input = getFloat80(+.signalingNaN) - let actual = UInt64(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt64 +.test("FromFloat80_NeverTraps") +.forEach(in: [ + (getUInt64(+0), getFloat80(-0.5)), + (getUInt64(+0), getFloat80(+0)), + (getUInt64(+0), getFloat80(-0)), + (getUInt64(+0), getFloat80(+0.5)), + (getUInt64(+127), getFloat80(+127.5)), + (getUInt64(+255), getFloat80(+255.5)), + (getUInt64(+32767), getFloat80(+32767.5)), + (getUInt64(+65535), getFloat80(+65535.5)), + (getUInt64(+18446744073709551615), getFloat80(+18446744073709551615)), +]) { + expectEqual($0.0, UInt64($0.1)) +} + +FixedPointConversion_Release64_ToUInt64 +.test("FromFloat80_NeverFails") +.forEach(in: [ + (getUInt64(+0), getFloat80(+0)), + (getUInt64(+0), getFloat80(-0)), + (getUInt64(+18446744073709551615), getFloat80(+18446744073709551615)), +]) { + expectEqual($0.0, UInt64(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToUInt64 +.test("FromFloat80_AlwaysTraps") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-1), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt64($0)) +} + +FixedPointConversion_Release64_ToUInt64 +.test("FromFloat80_AlwaysFails") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-1), + getFloat80(-0.5), + getFloat80(+0.5), + getFloat80(+127.5), + getFloat80(+255.5), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectNil(UInt64(exactly: $0)) } #endif // Float80 diff --git a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release64_ToUInt8.swift b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release64_ToUInt8.swift index 01eba5f87980a..f8f7cf6ce32b2 100644 --- a/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release64_ToUInt8.swift +++ b/validation-test/stdlib/FixedPointConversion/FixedPointConversion_Release64_ToUInt8.swift @@ -14,1800 +14,717 @@ import StdlibUnittest -let FixedPointConversion_Release64_ToUInt8 = TestSuite("FixedPointConversion_Release64_ToUInt8") +let FixedPointConversion_Release64_ToUInt8 = TestSuite( + "FixedPointConversion_Release64_ToUInt8" +) //===----------------------------------------------------------------------===// -// MARK: UInt8: (0)...(255) +// MARK: UInt8: (+0)...(+255) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt8.test("FromUInt8(0)_NeverTraps") { - let input = getUInt8(0) - let actual = UInt8(input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt8 +.test("FromUInt8_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getUInt8(+0)), + (getUInt8(+255), getUInt8(+255)), +]) { + expectEqual($0.0, UInt8($0.1)) } -FixedPointConversion_Release64_ToUInt8.test("FromUInt8(0)_NeverFails") { - let input = getUInt8(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromUInt8(255)_NeverTraps") { - let input = getUInt8(255) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromUInt8(255)_NeverFails") { - let input = getUInt8(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) +FixedPointConversion_Release64_ToUInt8 +.test("FromUInt8_NeverFails") +.forEach(in: [ + (getUInt8(+0), getUInt8(+0)), + (getUInt8(+255), getUInt8(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) } //===----------------------------------------------------------------------===// -// MARK: Int8: (-128)...(127) +// MARK: Int8: (-128)...(+127) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt8.test("FromInt8(-128)_AlwaysTraps") { - let input = getInt8(-128) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt8(-128)_AlwaysFails") { - let input = getInt8(-128) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt8(-1)_AlwaysTraps") { - let input = getInt8(-1) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } +FixedPointConversion_Release64_ToUInt8 +.test("FromInt8_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getInt8(+0)), + (getUInt8(+127), getInt8(+127)), +]) { + expectEqual($0.0, UInt8($0.1)) } -FixedPointConversion_Release64_ToUInt8.test("FromInt8(-1)_AlwaysFails") { - let input = getInt8(-1) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt8 +.test("FromInt8_NeverFails") +.forEach(in: [ + (getUInt8(+0), getInt8(+0)), + (getUInt8(+127), getInt8(+127)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) } -FixedPointConversion_Release64_ToUInt8.test("FromInt8(0)_NeverTraps") { - let input = getInt8(0) - let actual = UInt8(input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt8 +.test("FromInt8_AlwaysTraps") +.forEach(in: [ + getInt8(-128), + getInt8(-1), +]) { + expectCrashLater() + _blackHole(UInt8($0)) } -FixedPointConversion_Release64_ToUInt8.test("FromInt8(0)_NeverFails") { - let input = getInt8(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt8(127)_NeverTraps") { - let input = getInt8(127) - let actual = UInt8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt8(127)_NeverFails") { - let input = getInt8(127) - let actual = UInt8(exactly: input) - expectEqual(127, actual) +FixedPointConversion_Release64_ToUInt8 +.test("FromInt8_AlwaysFails") +.forEach(in: [ + getInt8(-128), + getInt8(-1), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt16: (0)...(65535) +// MARK: UInt16: (+0)...(+65535) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt8.test("FromUInt16(0)_NeverTraps") { - let input = getUInt16(0) - let actual = UInt8(input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt8 +.test("FromUInt16_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getUInt16(+0)), + (getUInt8(+255), getUInt16(+255)), +]) { + expectEqual($0.0, UInt8($0.1)) } -FixedPointConversion_Release64_ToUInt8.test("FromUInt16(0)_NeverFails") { - let input = getUInt16(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt8 +.test("FromUInt16_NeverFails") +.forEach(in: [ + (getUInt8(+0), getUInt16(+0)), + (getUInt8(+255), getUInt16(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) } -FixedPointConversion_Release64_ToUInt8.test("FromUInt16(255)_NeverTraps") { - let input = getUInt16(255) - let actual = UInt8(input) - expectEqual(255, actual) +FixedPointConversion_Release64_ToUInt8 +.test("FromUInt16_AlwaysTraps") +.forEach(in: [ + getUInt16(+256), + getUInt16(+65535), +]) { + expectCrashLater() + _blackHole(UInt8($0)) } -FixedPointConversion_Release64_ToUInt8.test("FromUInt16(255)_NeverFails") { - let input = getUInt16(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromUInt16(256)_AlwaysTraps") { - let input = getUInt16(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromUInt16(256)_AlwaysFails") { - let input = getUInt16(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromUInt16(65535)_AlwaysTraps") { - let input = getUInt16(65535) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromUInt16(65535)_AlwaysFails") { - let input = getUInt16(65535) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt8 +.test("FromUInt16_AlwaysFails") +.forEach(in: [ + getUInt16(+256), + getUInt16(+65535), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int16: (-32768)...(32767) +// MARK: Int16: (-32768)...(+32767) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt8.test("FromInt16(-32768)_AlwaysTraps") { - let input = getInt16(-32768) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt16(-32768)_AlwaysFails") { - let input = getInt16(-32768) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt16(-1)_AlwaysTraps") { - let input = getInt16(-1) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt16(-1)_AlwaysFails") { - let input = getInt16(-1) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt16(0)_NeverTraps") { - let input = getInt16(0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt16(0)_NeverFails") { - let input = getInt16(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt16(255)_NeverTraps") { - let input = getInt16(255) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt16(255)_NeverFails") { - let input = getInt16(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt16(256)_AlwaysTraps") { - let input = getInt16(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt16(256)_AlwaysFails") { - let input = getInt16(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt16(32767)_AlwaysTraps") { - let input = getInt16(32767) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt16(32767)_AlwaysFails") { - let input = getInt16(32767) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt8 +.test("FromInt16_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getInt16(+0)), + (getUInt8(+255), getInt16(+255)), +]) { + expectEqual($0.0, UInt8($0.1)) +} + +FixedPointConversion_Release64_ToUInt8 +.test("FromInt16_NeverFails") +.forEach(in: [ + (getUInt8(+0), getInt16(+0)), + (getUInt8(+255), getInt16(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToUInt8 +.test("FromInt16_AlwaysTraps") +.forEach(in: [ + getInt16(-32768), + getInt16(-1), + getInt16(+256), + getInt16(+32767), +]) { + expectCrashLater() + _blackHole(UInt8($0)) +} + +FixedPointConversion_Release64_ToUInt8 +.test("FromInt16_AlwaysFails") +.forEach(in: [ + getInt16(-32768), + getInt16(-1), + getInt16(+256), + getInt16(+32767), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt32: (0)...(4294967295) +// MARK: UInt32: (+0)...(+4294967295) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt8.test("FromUInt32(0)_NeverTraps") { - let input = getUInt32(0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromUInt32(0)_NeverFails") { - let input = getUInt32(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt8 +.test("FromUInt32_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getUInt32(+0)), + (getUInt8(+255), getUInt32(+255)), +]) { + expectEqual($0.0, UInt8($0.1)) } -FixedPointConversion_Release64_ToUInt8.test("FromUInt32(255)_NeverTraps") { - let input = getUInt32(255) - let actual = UInt8(input) - expectEqual(255, actual) +FixedPointConversion_Release64_ToUInt8 +.test("FromUInt32_NeverFails") +.forEach(in: [ + (getUInt8(+0), getUInt32(+0)), + (getUInt8(+255), getUInt32(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) } -FixedPointConversion_Release64_ToUInt8.test("FromUInt32(255)_NeverFails") { - let input = getUInt32(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) +FixedPointConversion_Release64_ToUInt8 +.test("FromUInt32_AlwaysTraps") +.forEach(in: [ + getUInt32(+256), + getUInt32(+4294967295), +]) { + expectCrashLater() + _blackHole(UInt8($0)) } -FixedPointConversion_Release64_ToUInt8.test("FromUInt32(256)_AlwaysTraps") { - let input = getUInt32(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromUInt32(256)_AlwaysFails") { - let input = getUInt32(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromUInt32(4294967295)_AlwaysTraps") { - let input = getUInt32(4294967295) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromUInt32(4294967295)_AlwaysFails") { - let input = getUInt32(4294967295) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt8 +.test("FromUInt32_AlwaysFails") +.forEach(in: [ + getUInt32(+256), + getUInt32(+4294967295), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int32: (-2147483648)...(2147483647) +// MARK: Int32: (-2147483648)...(+2147483647) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt8.test("FromInt32(-2147483648)_AlwaysTraps") { - let input = getInt32(-2147483648) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt32(-2147483648)_AlwaysFails") { - let input = getInt32(-2147483648) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt32(-1)_AlwaysTraps") { - let input = getInt32(-1) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt32(-1)_AlwaysFails") { - let input = getInt32(-1) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt32(0)_NeverTraps") { - let input = getInt32(0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt32(0)_NeverFails") { - let input = getInt32(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt32(255)_NeverTraps") { - let input = getInt32(255) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt32(255)_NeverFails") { - let input = getInt32(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt32(256)_AlwaysTraps") { - let input = getInt32(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt32(256)_AlwaysFails") { - let input = getInt32(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt32(2147483647)_AlwaysTraps") { - let input = getInt32(2147483647) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt32(2147483647)_AlwaysFails") { - let input = getInt32(2147483647) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt8 +.test("FromInt32_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getInt32(+0)), + (getUInt8(+255), getInt32(+255)), +]) { + expectEqual($0.0, UInt8($0.1)) +} + +FixedPointConversion_Release64_ToUInt8 +.test("FromInt32_NeverFails") +.forEach(in: [ + (getUInt8(+0), getInt32(+0)), + (getUInt8(+255), getInt32(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToUInt8 +.test("FromInt32_AlwaysTraps") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-1), + getInt32(+256), + getInt32(+2147483647), +]) { + expectCrashLater() + _blackHole(UInt8($0)) +} + +FixedPointConversion_Release64_ToUInt8 +.test("FromInt32_AlwaysFails") +.forEach(in: [ + getInt32(-2147483648), + getInt32(-1), + getInt32(+256), + getInt32(+2147483647), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt64: (0)...(18446744073709551615) +// MARK: UInt64: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt8.test("FromUInt64(0)_NeverTraps") { - let input = getUInt64(0) - let actual = UInt8(input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt8 +.test("FromUInt64_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getUInt64(+0)), + (getUInt8(+255), getUInt64(+255)), +]) { + expectEqual($0.0, UInt8($0.1)) } -FixedPointConversion_Release64_ToUInt8.test("FromUInt64(0)_NeverFails") { - let input = getUInt64(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt8 +.test("FromUInt64_NeverFails") +.forEach(in: [ + (getUInt8(+0), getUInt64(+0)), + (getUInt8(+255), getUInt64(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) } -FixedPointConversion_Release64_ToUInt8.test("FromUInt64(255)_NeverTraps") { - let input = getUInt64(255) - let actual = UInt8(input) - expectEqual(255, actual) +FixedPointConversion_Release64_ToUInt8 +.test("FromUInt64_AlwaysTraps") +.forEach(in: [ + getUInt64(+256), + getUInt64(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(UInt8($0)) } -FixedPointConversion_Release64_ToUInt8.test("FromUInt64(255)_NeverFails") { - let input = getUInt64(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromUInt64(256)_AlwaysTraps") { - let input = getUInt64(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromUInt64(256)_AlwaysFails") { - let input = getUInt64(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromUInt64(18446744073709551615)_AlwaysTraps") { - let input = getUInt64(18446744073709551615) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromUInt64(18446744073709551615)_AlwaysFails") { - let input = getUInt64(18446744073709551615) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt8 +.test("FromUInt64_AlwaysFails") +.forEach(in: [ + getUInt64(+256), + getUInt64(+18446744073709551615), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int64: (-9223372036854775808)...(9223372036854775807) +// MARK: Int64: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt8.test("FromInt64(-9223372036854775808)_AlwaysTraps") { - let input = getInt64(-9223372036854775808) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt64(-9223372036854775808)_AlwaysFails") { - let input = getInt64(-9223372036854775808) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt64(-1)_AlwaysTraps") { - let input = getInt64(-1) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt64(-1)_AlwaysFails") { - let input = getInt64(-1) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt64(0)_NeverTraps") { - let input = getInt64(0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt64(0)_NeverFails") { - let input = getInt64(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt64(255)_NeverTraps") { - let input = getInt64(255) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt64(255)_NeverFails") { - let input = getInt64(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt64(256)_AlwaysTraps") { - let input = getInt64(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt64(256)_AlwaysFails") { - let input = getInt64(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt64(9223372036854775807)_AlwaysTraps") { - let input = getInt64(9223372036854775807) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt64(9223372036854775807)_AlwaysFails") { - let input = getInt64(9223372036854775807) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt8 +.test("FromInt64_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getInt64(+0)), + (getUInt8(+255), getInt64(+255)), +]) { + expectEqual($0.0, UInt8($0.1)) +} + +FixedPointConversion_Release64_ToUInt8 +.test("FromInt64_NeverFails") +.forEach(in: [ + (getUInt8(+0), getInt64(+0)), + (getUInt8(+255), getInt64(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToUInt8 +.test("FromInt64_AlwaysTraps") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-1), + getInt64(+256), + getInt64(+9223372036854775807), +]) { + expectCrashLater() + _blackHole(UInt8($0)) +} + +FixedPointConversion_Release64_ToUInt8 +.test("FromInt64_AlwaysFails") +.forEach(in: [ + getInt64(-9223372036854775808), + getInt64(-1), + getInt64(+256), + getInt64(+9223372036854775807), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: UInt: (0)...(18446744073709551615) +// MARK: UInt: (+0)...(+18446744073709551615) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt8.test("FromUInt(0)_NeverTraps") { - let input = getUInt(0) - let actual = UInt8(input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt8 +.test("FromUInt_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getUInt(+0)), + (getUInt8(+255), getUInt(+255)), +]) { + expectEqual($0.0, UInt8($0.1)) } -FixedPointConversion_Release64_ToUInt8.test("FromUInt(0)_NeverFails") { - let input = getUInt(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) +FixedPointConversion_Release64_ToUInt8 +.test("FromUInt_NeverFails") +.forEach(in: [ + (getUInt8(+0), getUInt(+0)), + (getUInt8(+255), getUInt(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) } -FixedPointConversion_Release64_ToUInt8.test("FromUInt(255)_NeverTraps") { - let input = getUInt(255) - let actual = UInt8(input) - expectEqual(255, actual) +FixedPointConversion_Release64_ToUInt8 +.test("FromUInt_AlwaysTraps") +.forEach(in: [ + getUInt(+256), + getUInt(+18446744073709551615), +]) { + expectCrashLater() + _blackHole(UInt8($0)) } -FixedPointConversion_Release64_ToUInt8.test("FromUInt(255)_NeverFails") { - let input = getUInt(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromUInt(256)_AlwaysTraps") { - let input = getUInt(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromUInt(256)_AlwaysFails") { - let input = getUInt(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromUInt(18446744073709551615)_AlwaysTraps") { - let input = getUInt(18446744073709551615) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromUInt(18446744073709551615)_AlwaysFails") { - let input = getUInt(18446744073709551615) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt8 +.test("FromUInt_AlwaysFails") +.forEach(in: [ + getUInt(+256), + getUInt(+18446744073709551615), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Int: (-9223372036854775808)...(9223372036854775807) +// MARK: Int: (-9223372036854775808)...(+9223372036854775807) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt8.test("FromInt(-9223372036854775808)_AlwaysTraps") { - let input = getInt(-9223372036854775808) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt(-9223372036854775808)_AlwaysFails") { - let input = getInt(-9223372036854775808) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt(-1)_AlwaysTraps") { - let input = getInt(-1) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt(-1)_AlwaysFails") { - let input = getInt(-1) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt(0)_NeverTraps") { - let input = getInt(0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt(0)_NeverFails") { - let input = getInt(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt(255)_NeverTraps") { - let input = getInt(255) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt(255)_NeverFails") { - let input = getInt(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt(256)_AlwaysTraps") { - let input = getInt(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt(256)_AlwaysFails") { - let input = getInt(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt(9223372036854775807)_AlwaysTraps") { - let input = getInt(9223372036854775807) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromInt(9223372036854775807)_AlwaysFails") { - let input = getInt(9223372036854775807) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt8 +.test("FromInt_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getInt(+0)), + (getUInt8(+255), getInt(+255)), +]) { + expectEqual($0.0, UInt8($0.1)) +} + +FixedPointConversion_Release64_ToUInt8 +.test("FromInt_NeverFails") +.forEach(in: [ + (getUInt8(+0), getInt(+0)), + (getUInt8(+255), getInt(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToUInt8 +.test("FromInt_AlwaysTraps") +.forEach(in: [ + getInt(-9223372036854775808), + getInt(-1), + getInt(+256), + getInt(+9223372036854775807), +]) { + expectCrashLater() + _blackHole(UInt8($0)) +} + +FixedPointConversion_Release64_ToUInt8 +.test("FromInt_AlwaysFails") +.forEach(in: [ + getInt(-9223372036854775808), + getInt(-1), + getInt(+256), + getInt(+9223372036854775807), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float16: (-2047)...(2047) +// MARK: Float16: (-2047)...(+2047) //===----------------------------------------------------------------------===// #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -FixedPointConversion_Release64_ToUInt8.test("FromFloat16(-2047)_AlwaysTraps") { - let input = getFloat16(-2047) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat16(-2047)_AlwaysFails") { - let input = getFloat16(-2047) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat16(-128.5)_AlwaysTraps") { - let input = getFloat16(-128.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat16(-128.5)_AlwaysFails") { - let input = getFloat16(-128.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat16(-1)_AlwaysTraps") { - let input = getFloat16(-1) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat16(-1)_AlwaysFails") { - let input = getFloat16(-1) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat16(-0.5)_NeverTraps") { - let input = getFloat16(-0.5) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat16(-0.5)_AlwaysFails") { - let input = getFloat16(-0.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat16(0)_NeverTraps") { - let input = getFloat16(0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat16(0)_NeverFails") { - let input = getFloat16(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat16(-0.0)_NeverTraps") { - let input = getFloat16(-0.0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat16(-0.0)_NeverFails") { - let input = getFloat16(-0.0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat16(0.0)_NeverTraps") { - let input = getFloat16(0.0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat16(0.0)_NeverFails") { - let input = getFloat16(0.0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat16(0.5)_NeverTraps") { - let input = getFloat16(0.5) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat16(0.5)_AlwaysFails") { - let input = getFloat16(0.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat16(127.5)_NeverTraps") { - let input = getFloat16(127.5) - let actual = UInt8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat16(127.5)_AlwaysFails") { - let input = getFloat16(127.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat16(255)_NeverTraps") { - let input = getFloat16(255) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat16(255)_NeverFails") { - let input = getFloat16(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat16(255.5)_NeverTraps") { - let input = getFloat16(255.5) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat16(255.5)_AlwaysFails") { - let input = getFloat16(255.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat16(256)_AlwaysTraps") { - let input = getFloat16(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat16(256)_AlwaysFails") { - let input = getFloat16(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat16(2047)_AlwaysTraps") { - let input = getFloat16(2047) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat16(2047)_AlwaysFails") { - let input = getFloat16(2047) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat16(-.infinity)_AlwaysTraps") { - let input = getFloat16(-.infinity) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat16(-.infinity)_AlwaysFails") { - let input = getFloat16(-.infinity) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat16(+.infinity)_AlwaysTraps") { - let input = getFloat16(+.infinity) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat16(+.infinity)_AlwaysFails") { - let input = getFloat16(+.infinity) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat16(-.nan)_AlwaysTraps") { - let input = getFloat16(-.nan) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat16(-.nan)_AlwaysFails") { - let input = getFloat16(-.nan) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat16(+.nan)_AlwaysTraps") { - let input = getFloat16(+.nan) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat16(+.nan)_AlwaysFails") { - let input = getFloat16(+.nan) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat16(-.signalingNaN)_AlwaysTraps") { - let input = getFloat16(-.signalingNaN) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat16(-.signalingNaN)_AlwaysFails") { - let input = getFloat16(-.signalingNaN) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat16(+.signalingNaN)_AlwaysTraps") { - let input = getFloat16(+.signalingNaN) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat16(+.signalingNaN)_AlwaysFails") { - let input = getFloat16(+.signalingNaN) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt8 +.test("FromFloat16_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getFloat16(-0.5)), + (getUInt8(+0), getFloat16(-0)), + (getUInt8(+0), getFloat16(+0)), + (getUInt8(+0), getFloat16(+0.5)), + (getUInt8(+127), getFloat16(+127.5)), + (getUInt8(+255), getFloat16(+255)), + (getUInt8(+255), getFloat16(+255.5)), +]) { + expectEqual($0.0, UInt8($0.1)) +} + +FixedPointConversion_Release64_ToUInt8 +.test("FromFloat16_NeverFails") +.forEach(in: [ + (getUInt8(+0), getFloat16(-0)), + (getUInt8(+0), getFloat16(+0)), + (getUInt8(+255), getFloat16(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToUInt8 +.test("FromFloat16_AlwaysTraps") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-128.5), + getFloat16(-1), + getFloat16(+256), + getFloat16(+2047), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt8($0)) +} + +FixedPointConversion_Release64_ToUInt8 +.test("FromFloat16_AlwaysFails") +.forEach(in: [ + getFloat16(-2047), + getFloat16(-128.5), + getFloat16(-1), + getFloat16(-0.5), + getFloat16(+0.5), + getFloat16(+127.5), + getFloat16(+255.5), + getFloat16(+256), + getFloat16(+2047), + getFloat16(-.infinity), + getFloat16(-.nan), + getFloat16(-.signalingNaN), + getFloat16(+.infinity), + getFloat16(+.nan), + getFloat16(+.signalingNaN), +]) { + expectNil(UInt8(exactly: $0)) } } #endif // Float16 //===----------------------------------------------------------------------===// -// MARK: Float32: (-16777215)...(16777215) +// MARK: Float32: (-16777215)...(+16777215) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(-16777215)_AlwaysTraps") { - let input = getFloat32(-16777215) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(-16777215)_AlwaysFails") { - let input = getFloat32(-16777215) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(-32768.5)_AlwaysTraps") { - let input = getFloat32(-32768.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(-32768.5)_AlwaysFails") { - let input = getFloat32(-32768.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(-128.5)_AlwaysTraps") { - let input = getFloat32(-128.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(-128.5)_AlwaysFails") { - let input = getFloat32(-128.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(-1)_AlwaysTraps") { - let input = getFloat32(-1) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(-1)_AlwaysFails") { - let input = getFloat32(-1) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(-0.5)_NeverTraps") { - let input = getFloat32(-0.5) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(-0.5)_AlwaysFails") { - let input = getFloat32(-0.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(0)_NeverTraps") { - let input = getFloat32(0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(0)_NeverFails") { - let input = getFloat32(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(-0.0)_NeverTraps") { - let input = getFloat32(-0.0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(-0.0)_NeverFails") { - let input = getFloat32(-0.0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(0.0)_NeverTraps") { - let input = getFloat32(0.0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(0.0)_NeverFails") { - let input = getFloat32(0.0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(0.5)_NeverTraps") { - let input = getFloat32(0.5) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(0.5)_AlwaysFails") { - let input = getFloat32(0.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(127.5)_NeverTraps") { - let input = getFloat32(127.5) - let actual = UInt8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(127.5)_AlwaysFails") { - let input = getFloat32(127.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(255)_NeverTraps") { - let input = getFloat32(255) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(255)_NeverFails") { - let input = getFloat32(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(255.5)_NeverTraps") { - let input = getFloat32(255.5) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(255.5)_AlwaysFails") { - let input = getFloat32(255.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(256)_AlwaysTraps") { - let input = getFloat32(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(256)_AlwaysFails") { - let input = getFloat32(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(32767.5)_AlwaysTraps") { - let input = getFloat32(32767.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(32767.5)_AlwaysFails") { - let input = getFloat32(32767.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(65535.5)_AlwaysTraps") { - let input = getFloat32(65535.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(65535.5)_AlwaysFails") { - let input = getFloat32(65535.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(16777215)_AlwaysTraps") { - let input = getFloat32(16777215) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(16777215)_AlwaysFails") { - let input = getFloat32(16777215) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(-.infinity)_AlwaysTraps") { - let input = getFloat32(-.infinity) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(-.infinity)_AlwaysFails") { - let input = getFloat32(-.infinity) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(+.infinity)_AlwaysTraps") { - let input = getFloat32(+.infinity) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(+.infinity)_AlwaysFails") { - let input = getFloat32(+.infinity) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(-.nan)_AlwaysTraps") { - let input = getFloat32(-.nan) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(-.nan)_AlwaysFails") { - let input = getFloat32(-.nan) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(+.nan)_AlwaysTraps") { - let input = getFloat32(+.nan) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(+.nan)_AlwaysFails") { - let input = getFloat32(+.nan) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(-.signalingNaN)_AlwaysTraps") { - let input = getFloat32(-.signalingNaN) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(-.signalingNaN)_AlwaysFails") { - let input = getFloat32(-.signalingNaN) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(+.signalingNaN)_AlwaysTraps") { - let input = getFloat32(+.signalingNaN) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat32(+.signalingNaN)_AlwaysFails") { - let input = getFloat32(+.signalingNaN) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt8 +.test("FromFloat32_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getFloat32(-0.5)), + (getUInt8(+0), getFloat32(+0)), + (getUInt8(+0), getFloat32(-0)), + (getUInt8(+0), getFloat32(+0.5)), + (getUInt8(+127), getFloat32(+127.5)), + (getUInt8(+255), getFloat32(+255)), + (getUInt8(+255), getFloat32(+255.5)), +]) { + expectEqual($0.0, UInt8($0.1)) +} + +FixedPointConversion_Release64_ToUInt8 +.test("FromFloat32_NeverFails") +.forEach(in: [ + (getUInt8(+0), getFloat32(+0)), + (getUInt8(+0), getFloat32(-0)), + (getUInt8(+255), getFloat32(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToUInt8 +.test("FromFloat32_AlwaysTraps") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-1), + getFloat32(+256), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(+16777215), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt8($0)) +} + +FixedPointConversion_Release64_ToUInt8 +.test("FromFloat32_AlwaysFails") +.forEach(in: [ + getFloat32(-16777215), + getFloat32(-32768.5), + getFloat32(-128.5), + getFloat32(-1), + getFloat32(-0.5), + getFloat32(+0.5), + getFloat32(+127.5), + getFloat32(+255.5), + getFloat32(+256), + getFloat32(+32767.5), + getFloat32(+65535.5), + getFloat32(+16777215), + getFloat32(-.infinity), + getFloat32(-.nan), + getFloat32(-.signalingNaN), + getFloat32(+.infinity), + getFloat32(+.nan), + getFloat32(+.signalingNaN), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float64: (-9007199254740991)...(9007199254740991) +// MARK: Float64: (-9007199254740991)...(+9007199254740991) //===----------------------------------------------------------------------===// -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(-9007199254740991)_AlwaysTraps") { - let input = getFloat64(-9007199254740991) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(-9007199254740991)_AlwaysFails") { - let input = getFloat64(-9007199254740991) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(-32768.5)_AlwaysTraps") { - let input = getFloat64(-32768.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(-32768.5)_AlwaysFails") { - let input = getFloat64(-32768.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(-128.5)_AlwaysTraps") { - let input = getFloat64(-128.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(-128.5)_AlwaysFails") { - let input = getFloat64(-128.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(-1)_AlwaysTraps") { - let input = getFloat64(-1) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(-1)_AlwaysFails") { - let input = getFloat64(-1) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(-0.5)_NeverTraps") { - let input = getFloat64(-0.5) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(-0.5)_AlwaysFails") { - let input = getFloat64(-0.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(0)_NeverTraps") { - let input = getFloat64(0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(0)_NeverFails") { - let input = getFloat64(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(-0.0)_NeverTraps") { - let input = getFloat64(-0.0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(-0.0)_NeverFails") { - let input = getFloat64(-0.0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(0.0)_NeverTraps") { - let input = getFloat64(0.0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(0.0)_NeverFails") { - let input = getFloat64(0.0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(0.5)_NeverTraps") { - let input = getFloat64(0.5) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(0.5)_AlwaysFails") { - let input = getFloat64(0.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(127.5)_NeverTraps") { - let input = getFloat64(127.5) - let actual = UInt8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(127.5)_AlwaysFails") { - let input = getFloat64(127.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(255)_NeverTraps") { - let input = getFloat64(255) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(255)_NeverFails") { - let input = getFloat64(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(255.5)_NeverTraps") { - let input = getFloat64(255.5) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(255.5)_AlwaysFails") { - let input = getFloat64(255.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(256)_AlwaysTraps") { - let input = getFloat64(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(256)_AlwaysFails") { - let input = getFloat64(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(32767.5)_AlwaysTraps") { - let input = getFloat64(32767.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(32767.5)_AlwaysFails") { - let input = getFloat64(32767.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(65535.5)_AlwaysTraps") { - let input = getFloat64(65535.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(65535.5)_AlwaysFails") { - let input = getFloat64(65535.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(9007199254740991)_AlwaysTraps") { - let input = getFloat64(9007199254740991) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(9007199254740991)_AlwaysFails") { - let input = getFloat64(9007199254740991) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(-.infinity)_AlwaysTraps") { - let input = getFloat64(-.infinity) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(-.infinity)_AlwaysFails") { - let input = getFloat64(-.infinity) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(+.infinity)_AlwaysTraps") { - let input = getFloat64(+.infinity) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(+.infinity)_AlwaysFails") { - let input = getFloat64(+.infinity) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(-.nan)_AlwaysTraps") { - let input = getFloat64(-.nan) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(-.nan)_AlwaysFails") { - let input = getFloat64(-.nan) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(+.nan)_AlwaysTraps") { - let input = getFloat64(+.nan) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(+.nan)_AlwaysFails") { - let input = getFloat64(+.nan) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(-.signalingNaN)_AlwaysTraps") { - let input = getFloat64(-.signalingNaN) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(-.signalingNaN)_AlwaysFails") { - let input = getFloat64(-.signalingNaN) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(+.signalingNaN)_AlwaysTraps") { - let input = getFloat64(+.signalingNaN) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat64(+.signalingNaN)_AlwaysFails") { - let input = getFloat64(+.signalingNaN) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt8 +.test("FromFloat64_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getFloat64(-0.5)), + (getUInt8(+0), getFloat64(+0)), + (getUInt8(+0), getFloat64(-0)), + (getUInt8(+0), getFloat64(+0.5)), + (getUInt8(+127), getFloat64(+127.5)), + (getUInt8(+255), getFloat64(+255)), + (getUInt8(+255), getFloat64(+255.5)), +]) { + expectEqual($0.0, UInt8($0.1)) +} + +FixedPointConversion_Release64_ToUInt8 +.test("FromFloat64_NeverFails") +.forEach(in: [ + (getUInt8(+0), getFloat64(+0)), + (getUInt8(+0), getFloat64(-0)), + (getUInt8(+255), getFloat64(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToUInt8 +.test("FromFloat64_AlwaysTraps") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-1), + getFloat64(+256), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt8($0)) +} + +FixedPointConversion_Release64_ToUInt8 +.test("FromFloat64_AlwaysFails") +.forEach(in: [ + getFloat64(-9007199254740991), + getFloat64(-32768.5), + getFloat64(-128.5), + getFloat64(-1), + getFloat64(-0.5), + getFloat64(+0.5), + getFloat64(+127.5), + getFloat64(+255.5), + getFloat64(+256), + getFloat64(+32767.5), + getFloat64(+65535.5), + getFloat64(+9007199254740991), + getFloat64(-.infinity), + getFloat64(-.nan), + getFloat64(-.signalingNaN), + getFloat64(+.infinity), + getFloat64(+.nan), + getFloat64(+.signalingNaN), +]) { + expectNil(UInt8(exactly: $0)) } //===----------------------------------------------------------------------===// -// MARK: Float80: (-18446744073709551615)...(18446744073709551615) +// MARK: Float80: (-18446744073709551615)...(+18446744073709551615) //===----------------------------------------------------------------------===// #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(-18446744073709551615)_AlwaysTraps") { - let input = getFloat80(-18446744073709551615) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(-18446744073709551615)_AlwaysFails") { - let input = getFloat80(-18446744073709551615) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(-32768.5)_AlwaysTraps") { - let input = getFloat80(-32768.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(-32768.5)_AlwaysFails") { - let input = getFloat80(-32768.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(-128.5)_AlwaysTraps") { - let input = getFloat80(-128.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(-128.5)_AlwaysFails") { - let input = getFloat80(-128.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(-1)_AlwaysTraps") { - let input = getFloat80(-1) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(-1)_AlwaysFails") { - let input = getFloat80(-1) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(-0.5)_NeverTraps") { - let input = getFloat80(-0.5) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(-0.5)_AlwaysFails") { - let input = getFloat80(-0.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(0)_NeverTraps") { - let input = getFloat80(0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(0)_NeverFails") { - let input = getFloat80(0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(-0.0)_NeverTraps") { - let input = getFloat80(-0.0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(-0.0)_NeverFails") { - let input = getFloat80(-0.0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(0.0)_NeverTraps") { - let input = getFloat80(0.0) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(0.0)_NeverFails") { - let input = getFloat80(0.0) - let actual = UInt8(exactly: input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(0.5)_NeverTraps") { - let input = getFloat80(0.5) - let actual = UInt8(input) - expectEqual(0, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(0.5)_AlwaysFails") { - let input = getFloat80(0.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(127.5)_NeverTraps") { - let input = getFloat80(127.5) - let actual = UInt8(input) - expectEqual(127, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(127.5)_AlwaysFails") { - let input = getFloat80(127.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(255)_NeverTraps") { - let input = getFloat80(255) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(255)_NeverFails") { - let input = getFloat80(255) - let actual = UInt8(exactly: input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(255.5)_NeverTraps") { - let input = getFloat80(255.5) - let actual = UInt8(input) - expectEqual(255, actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(255.5)_AlwaysFails") { - let input = getFloat80(255.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(256)_AlwaysTraps") { - let input = getFloat80(256) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(256)_AlwaysFails") { - let input = getFloat80(256) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(32767.5)_AlwaysTraps") { - let input = getFloat80(32767.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(32767.5)_AlwaysFails") { - let input = getFloat80(32767.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(65535.5)_AlwaysTraps") { - let input = getFloat80(65535.5) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(65535.5)_AlwaysFails") { - let input = getFloat80(65535.5) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(18446744073709551615)_AlwaysTraps") { - let input = getFloat80(18446744073709551615) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(18446744073709551615)_AlwaysFails") { - let input = getFloat80(18446744073709551615) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(-.infinity)_AlwaysTraps") { - let input = getFloat80(-.infinity) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(-.infinity)_AlwaysFails") { - let input = getFloat80(-.infinity) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(+.infinity)_AlwaysTraps") { - let input = getFloat80(+.infinity) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(+.infinity)_AlwaysFails") { - let input = getFloat80(+.infinity) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(-.nan)_AlwaysTraps") { - let input = getFloat80(-.nan) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(-.nan)_AlwaysFails") { - let input = getFloat80(-.nan) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(+.nan)_AlwaysTraps") { - let input = getFloat80(+.nan) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(+.nan)_AlwaysFails") { - let input = getFloat80(+.nan) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(-.signalingNaN)_AlwaysTraps") { - let input = getFloat80(-.signalingNaN) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(-.signalingNaN)_AlwaysFails") { - let input = getFloat80(-.signalingNaN) - let actual = UInt8(exactly: input) - expectNil(actual) -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(+.signalingNaN)_AlwaysTraps") { - let input = getFloat80(+.signalingNaN) - expectCrash { - let actual = UInt8(input) - _blackHole(actual) - } -} - -FixedPointConversion_Release64_ToUInt8.test("FromFloat80(+.signalingNaN)_AlwaysFails") { - let input = getFloat80(+.signalingNaN) - let actual = UInt8(exactly: input) - expectNil(actual) +FixedPointConversion_Release64_ToUInt8 +.test("FromFloat80_NeverTraps") +.forEach(in: [ + (getUInt8(+0), getFloat80(-0.5)), + (getUInt8(+0), getFloat80(-0)), + (getUInt8(+0), getFloat80(+0)), + (getUInt8(+0), getFloat80(+0.5)), + (getUInt8(+127), getFloat80(+127.5)), + (getUInt8(+255), getFloat80(+255)), + (getUInt8(+255), getFloat80(+255.5)), +]) { + expectEqual($0.0, UInt8($0.1)) +} + +FixedPointConversion_Release64_ToUInt8 +.test("FromFloat80_NeverFails") +.forEach(in: [ + (getUInt8(+0), getFloat80(-0)), + (getUInt8(+0), getFloat80(+0)), + (getUInt8(+255), getFloat80(+255)), +]) { + expectEqual($0.0, UInt8(exactly: $0.1)) +} + +FixedPointConversion_Release64_ToUInt8 +.test("FromFloat80_AlwaysTraps") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-1), + getFloat80(+256), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectCrashLater() + _blackHole(UInt8($0)) +} + +FixedPointConversion_Release64_ToUInt8 +.test("FromFloat80_AlwaysFails") +.forEach(in: [ + getFloat80(-18446744073709551615), + getFloat80(-32768.5), + getFloat80(-128.5), + getFloat80(-1), + getFloat80(-0.5), + getFloat80(+0.5), + getFloat80(+127.5), + getFloat80(+255.5), + getFloat80(+256), + getFloat80(+32767.5), + getFloat80(+65535.5), + getFloat80(+18446744073709551615), + getFloat80(-.infinity), + getFloat80(-.nan), + getFloat80(-.signalingNaN), + getFloat80(+.infinity), + getFloat80(+.nan), + getFloat80(+.signalingNaN), +]) { + expectNil(UInt8(exactly: $0)) } #endif // Float80 diff --git a/validation-test/stdlib/FixedPointConversion/Inputs/FixedPointConversion.swift.gyb b/validation-test/stdlib/FixedPointConversion/Inputs/FixedPointConversion.swift.gyb index 28382388f75c0..40dbfb0a597c2 100644 --- a/validation-test/stdlib/FixedPointConversion/Inputs/FixedPointConversion.swift.gyb +++ b/validation-test/stdlib/FixedPointConversion/Inputs/FixedPointConversion.swift.gyb @@ -1,6 +1,7 @@ % # FIXME(integers): add tests that perform the same checks in generic code. % # % # cd validation-test/stdlib/FixedPointConversion/ +% # % # ../../../utils/gyb --line-directive="" \ % # ./Inputs/FixedPointConversion.swift.gyb | ../../../utils/split_file.py % @@ -10,18 +11,18 @@ % from itertools import product % % # Generate a test-suite file for each integer type. -% for (configuration, ptrsize) in product(['Debug', 'Release'], [32, 64]): -% long_test = ', long_test' if (configuration, ptrsize) == ('Release', 32) else '' +% for (configuration, bitWidth) in product(['Debug', 'Release'], [32, 64]): % optimizations = '-Onone' if configuration == 'Debug' else '-O' % -% for self_type in all_integer_types(ptrsize): -% SelfName = self_type.stdlib_name -% selfMin = self_type.min -% selfMax = self_type.max +% for selfType in all_integer_types(bitWidth): +% SelfName = selfType.stdlib_name +% selfMin = selfType.min +% selfMax = selfType.max % -% test_suite = 'FixedPointConversion_' + configuration + str(ptrsize) + '_To' + SelfName +% testSuite = 'FixedPointConversion_{configuration}{bitWidth}_To{SelfName}'\ +% .format(**locals()) # TODO(python3): use f-string (PEP 498). % -// BEGIN ${test_suite}.swift +// BEGIN ${testSuite}.swift //===----------------------------------------------------------------------===// // // Automatically Generated From ./Inputs/FixedPointConversion.swift.gyb @@ -29,8 +30,8 @@ // //===----------------------------------------------------------------------===// // -// REQUIRES: executable_test${long_test} -// REQUIRES: PTRSIZE=${str(ptrsize)} +// REQUIRES: executable_test +// REQUIRES: PTRSIZE=${format(bitWidth)} // RUN: %target-run-simple-swift(${optimizations}) // END. // @@ -38,196 +39,298 @@ import StdlibUnittest -let ${test_suite} = TestSuite("${test_suite}") +let ${testSuite} = TestSuite( + "${testSuite}" +) % # Test conversion behaviors for all integer types. -% for other_type in all_integer_types(ptrsize): -% OtherName = other_type.stdlib_name -% otherMin = other_type.min -% otherMax = other_type.max +% for otherType in all_integer_types(bitWidth): +% OtherName = otherType.stdlib_name +% otherMin = otherType.min +% otherMax = otherType.max % //===----------------------------------------------------------------------===// -// MARK: ${OtherName}: (${str(otherMin)})...(${str(otherMax)}) +// MARK: ${OtherName}: (${format(otherMin, '+')})...(${format(otherMax, '+')}) //===----------------------------------------------------------------------===// -% intValues = [ -% selfMin, -% selfMax, -% selfMin - 1, -% selfMax + 1, -% otherMin, -% otherMax, -% 0, -% ] -% for intValue in sorted(set(intValues)): -% if otherMin <= intValue <= otherMax: -% -% intLiteral = str(intValue) -% -% if selfMin <= intValue <= selfMax: -% -${test_suite}.test("From${OtherName}(${intLiteral})_NeverTraps") { - let input = get${OtherName}(${intLiteral}) - let actual = ${SelfName}(input) - expectEqual(${intLiteral}, actual) +% otherValues = sorted( +% set( +% filter( +% lambda otherValue: (otherMin <= otherValue <= otherMax), +% [ +% selfMin, +% selfMax, +% selfMin - 1, +% selfMax + 1, +% otherMin, +% otherMax, +% 0, +% ] +% ) +% ) +% ) +% otherValues_NeverTraps = otherValues_NeverFails = list( +% filter( +% lambda otherValue: (selfMin <= otherValue <= selfMax), +% otherValues +% ) +% ) +% otherValues_AlwaysTraps = otherValues_AlwaysFails = list( +% filter( +% lambda otherValue: not (selfMin <= otherValue <= selfMax), +% otherValues +% ) +% ) +% +% if len(otherValues_NeverTraps) > 0: +% +${testSuite} +.test("From${OtherName}_NeverTraps") +.forEach(in: [ +% +% for otherValue in otherValues_NeverTraps: +% selfLiteral = otherLiteral = format(otherValue, '+') +% + (get${SelfName}(${selfLiteral}), get${OtherName}(${otherLiteral})), +% +% end # for +]) { + expectEqual($0.0, ${SelfName}($0.1)) } -${test_suite}.test("From${OtherName}(${intLiteral})_NeverFails") { - let input = get${OtherName}(${intLiteral}) - let actual = ${SelfName}(exactly: input) - expectEqual(${intLiteral}, actual) +% end # if +% +% if len(otherValues_NeverFails) > 0: +% +${testSuite} +.test("From${OtherName}_NeverFails") +.forEach(in: [ +% +% for otherValue in otherValues_NeverFails: +% selfLiteral = otherLiteral = format(otherValue, '+') +% + (get${SelfName}(${selfLiteral}), get${OtherName}(${otherLiteral})), +% +% end # for +]) { + expectEqual($0.0, ${SelfName}(exactly: $0.1)) } -% else: +% end # if +% +% if len(otherValues_AlwaysTraps) > 0: % -${test_suite}.test("From${OtherName}(${intLiteral})_AlwaysTraps") { - let input = get${OtherName}(${intLiteral}) - expectCrash { - let actual = ${SelfName}(input) - _blackHole(actual) - } +${testSuite} +.test("From${OtherName}_AlwaysTraps") +.forEach(in: [ +% +% for otherValue in otherValues_AlwaysTraps: +% otherLiteral = format(otherValue, '+') +% + get${OtherName}(${otherLiteral}), +% +% end # for +]) { + expectCrashLater() + _blackHole(${SelfName}($0)) } -${test_suite}.test("From${OtherName}(${intLiteral})_AlwaysFails") { - let input = get${OtherName}(${intLiteral}) - let actual = ${SelfName}(exactly: input) - expectNil(actual) +% end # if +% +% if len(otherValues_AlwaysFails) > 0: +% +${testSuite} +.test("From${OtherName}_AlwaysFails") +.forEach(in: [ +% +% for otherValue in otherValues_AlwaysFails: +% otherLiteral = format(otherValue, '+') +% + get${OtherName}(${otherLiteral}), +% +% end # for +]) { + expectNil(${SelfName}(exactly: $0)) } -% end # if -% end # if -% end # for intValue in ... -% end # for other_type in ... +% end # if +% +% end # for otherType in ... % % # Test conversion behaviors for all floating-point types. -% for float_type in all_floating_point_types(): -% FloatName = "Float" + str(float_type.bits) -% floatMax = int_max(bits=float_type.explicit_significand_bits, signed=False) -% floatMin = -floatMax +% for otherType in all_floating_point_types(): +% OtherName = 'Float{}'.format(otherType.bits) +% otherMax = int_max(bits=otherType.explicit_significand_bits, signed=False) +% otherMin = -otherMax % //===----------------------------------------------------------------------===// -// MARK: ${FloatName}: (${str(floatMin)})...(${str(floatMax)}) +// MARK: ${OtherName}: (${format(otherMin, '+')})...(${format(otherMax, '+')}) //===----------------------------------------------------------------------===// -% if FloatName == 'Float16': +% if OtherName == 'Float16': % #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { -% elif FloatName == 'Float80': +% elif OtherName == 'Float80': % #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) % end # if % -% floatValues = [ -% Decimal(selfMin), -% Decimal(selfMax), -% Decimal(selfMin - 1), -% Decimal(selfMax + 1), -% Decimal(floatMin), -% Decimal(floatMax), -% Decimal('-0.0'), -% Decimal('+0.0'), -% Decimal('-0.5'), -% Decimal('+0.5'), -% Decimal('-128.5'), -% Decimal('+127.5'), -% Decimal('+255.5'), -% Decimal('-32768.5'), -% Decimal('+32767.5'), -% Decimal('+65535.5'), -% ] -% for floatValue in sorted(floatValues): -% if floatMin <= floatValue <= floatMax: -% -% intValue = int(floatValue) -% intLiteral = str(intValue) -% floatLiteral = str(floatValue) -% -% if selfMin <= intValue <= selfMax: -% -${test_suite}.test("From${FloatName}(${floatLiteral})_NeverTraps") { - let input = get${FloatName}(${floatLiteral}) - let actual = ${SelfName}(input) - expectEqual(${intLiteral}, actual) -} - -% if floatValue == intValue: +% otherValues = sorted( +% map( +% lambda otherLiteral: Decimal(otherLiteral).normalize(), +% set( +% map( +% lambda otherValue: format(otherValue.normalize(), '+'), +% filter( +% lambda otherValue: (otherMin <= otherValue <= otherMax), +% [ +% Decimal(selfMin), +% Decimal(selfMax), +% Decimal(selfMin - 1), +% Decimal(selfMax + 1), +% Decimal(otherMin), +% Decimal(otherMax), +% Decimal('-0.0'), +% Decimal('+0.0'), +% Decimal('-0.5'), +% Decimal('+0.5'), +% Decimal('-128.5'), +% Decimal('+127.5'), +% Decimal('+255.5'), +% Decimal('-32768.5'), +% Decimal('+32767.5'), +% Decimal('+65535.5'), +% ] +% ) +% ) +% ) +% ) +% ) +% otherValues_NeverTraps = list( +% filter( +% lambda otherValue: (selfMin <= int(otherValue) <= selfMax), +% otherValues +% ) +% ) +% otherValues_NeverFails = list( +% filter( +% lambda otherValue: (otherValue == int(otherValue)) and \ +% (selfMin <= int(otherValue) <= selfMax), +% otherValues +% ) +% ) +% otherValues_AlwaysTraps = list( +% filter( +% lambda otherValue: not (selfMin <= int(otherValue) <= selfMax), +% otherValues +% ) +% ) +% otherValues_AlwaysFails = list( +% filter( +% lambda otherValue: (otherValue != int(otherValue)) or \ +% not (selfMin <= int(otherValue) <= selfMax), +% otherValues +% ) +% ) +% signs = ['-', '+'] +% nonFinites = ['infinity', 'nan', 'signalingNaN'] % -${test_suite}.test("From${FloatName}(${floatLiteral})_NeverFails") { - let input = get${FloatName}(${floatLiteral}) - let actual = ${SelfName}(exactly: input) - expectEqual(${intLiteral}, actual) -} - -% else: +% if len(otherValues_NeverTraps) > 0: % -${test_suite}.test("From${FloatName}(${floatLiteral})_AlwaysFails") { - let input = get${FloatName}(${floatLiteral}) - let actual = ${SelfName}(exactly: input) - expectNil(actual) -} - -% end # if -% else: +${testSuite} +.test("From${OtherName}_NeverTraps") +.forEach(in: [ +% +% for otherValue in otherValues_NeverTraps: +% selfLiteral = format(int(otherValue), '+') +% otherLiteral = format(otherValue, '+') % -${test_suite}.test("From${FloatName}(${floatLiteral})_AlwaysTraps") { - let input = get${FloatName}(${floatLiteral}) - expectCrash { - let actual = ${SelfName}(input) - _blackHole(actual) - } + (get${SelfName}(${selfLiteral}), get${OtherName}(${otherLiteral})), +% +% end # for +]) { + expectEqual($0.0, ${SelfName}($0.1)) } -${test_suite}.test("From${FloatName}(${floatLiteral})_AlwaysFails") { - let input = get${FloatName}(${floatLiteral}) - let actual = ${SelfName}(exactly: input) - expectNil(actual) +% end # if +% +% if len(otherValues_NeverFails) > 0: +% +${testSuite} +.test("From${OtherName}_NeverFails") +.forEach(in: [ +% +% for otherValue in otherValues_NeverFails: +% selfLiteral = format(int(otherValue), '+') +% otherLiteral = format(otherValue, '+') +% + (get${SelfName}(${selfLiteral}), get${OtherName}(${otherLiteral})), +% +% end # for +]) { + expectEqual($0.0, ${SelfName}(exactly: $0.1)) } -% end # if -% end # if -% end # for floatValue in ... -% -% nonFinites = [ -% '-.infinity', -% '+.infinity', -% '-.nan', -% '+.nan', -% '-.signalingNaN', -% '+.signalingNaN', -% ] -% for nonFinite in nonFinites: -% -${test_suite}.test("From${FloatName}(${nonFinite})_AlwaysTraps") { - let input = get${FloatName}(${nonFinite}) - expectCrash { - let actual = ${SelfName}(input) - _blackHole(actual) - } +% end # if +% +${testSuite} +.test("From${OtherName}_AlwaysTraps") +.forEach(in: [ +% +% for otherValue in otherValues_AlwaysTraps: +% otherLiteral = format(otherValue, '+') +% + get${OtherName}(${otherLiteral}), +% +% end # for +% +% for (sign, nonFinite) in product(signs, nonFinites): +% + get${OtherName}(${sign}.${nonFinite}), +% +% end # for +]) { + expectCrashLater() + _blackHole(${SelfName}($0)) } -${test_suite}.test("From${FloatName}(${nonFinite})_AlwaysFails") { - let input = get${FloatName}(${nonFinite}) - let actual = ${SelfName}(exactly: input) - expectNil(actual) +${testSuite} +.test("From${OtherName}_AlwaysFails") +.forEach(in: [ +% +% for otherValue in otherValues_AlwaysFails: +% otherLiteral = format(otherValue, '+') +% + get${OtherName}(${otherLiteral}), +% +% end # for +% +% for (sign, nonFinite) in product(signs, nonFinites): +% + get${OtherName}(${sign}.${nonFinite}), +% +% end # for +]) { + expectNil(${SelfName}(exactly: $0)) } -% end # for nonFinite in ... -% -% if FloatName == 'Float16': +% if OtherName == 'Float16': } #endif // Float16 -% elif FloatName == 'Float80': +% elif OtherName == 'Float80': % #endif // Float80 % end # if -% end # for float_type in ... +% +% end # for otherType in ... % runAllTests() -% end # for self_type in ... -% end # for (configuration, ptrsize) in ... +% end # for selfType in ... +% +% end # for (configuration, bitWidth) in ...