All functions and forms provided by racket/base and racket check their arguments to ensure that the arguments conform to contracts and other constraints. For example, vector-ref checks its arguments to ensure that the first argument is a vector, that the second argument is an exact integer, and that the second argument is between 0 and one less than the vector’s length, inclusive.
Functions provided by racket/unsafe/ops are unsafe. They have certain constraints, but the constraints are not checked, which allows the system to generate and execute faster code. If arguments violate an unsafe function’s constraints, the function’s behavior and result is unpredictable, and the entire system can crash or become corrupted.
All of the exported bindings of racket/unsafe/ops are protected in the sense of protect-out, so access to unsafe operations can be prevented by adjusting the code inspector (see Code Inspectors).
17.1 Unsafe Numeric Operations🔗ℹChanged in version 7.0.0.13 of package base: Allow zero or more arguments for unsafe-fx+ and unsafe-fx* and allow one or more arguments for unsafe-fx-.
Changed in version 7.0.0.13 of package base: Allow zero or more arguments for unsafe-fxand, unsafe-fxior, and unsafe-fxxor.
Changed in version 8.8.0.5: Added unsafe-fxrshift/logical.
Added in version 8.5.0.6 of package base.
Added in version 7.9.0.6 of package base.
Changed in version 8.15.0.12: Changed unsafe-fx-/wraparound to accept a single argument.
Changed in version 7.0.0.13 of package base: Allow one or more argument, instead of allowing just two.
Changed in version 7.0.0.13 of package base: Allow zero or more arguments for unsafe-fl+ and unsafe-fl* and one or more arguments for unsafe-fl- and unsafe-fl/.
Changed in version 7.0.0.13 of package base: Allow one or more argument, instead of allowing just two.
Added in version 7.8.0.7 of package base.
Added in version 7.8.0.7 of package base.
For
flonums: Unchecked (potentially) versions of
flsin,
flcos,
fltan,
flasin,
flacos,
flatan,
fllog,
flexp,
flsqrt, and
flexpt. Currently, some of these bindings are simply aliases for the corresponding safe bindings.
Changed in version 7.7.0.8 of package base: Changed unsafe-fl->fx to truncate.
17.2 Unsafe Character Operations🔗ℹAdded in version 7.0.0.14 of package base.
17.3 Unsafe Compound-Data Operations🔗ℹUnsafe variant of
consthat produces a pair that claims to be a list—
without checking whether
restis a list.
As their oxymoronic names should suggest, there is no generally correct way to use these functions. They may be useful nevertheless, as a last resort, in settings where pairs are used in a constrained way and when making correct assumptions about Racket’s implementation (including limits on the compiler’s optimizations).
Some pitfalls of using unsafe-set-immutable-car! and unsafe-set-immutable-cdr!:
Functions that consume a pair may take advantage of immutability, such as computing a list’s length once and expecting the list to retain that length, or checking a list against a contract and expecting the contract to hold thereafter.
The result of list? for a pair may be cached internally, so that changing the cdr of a pair from a list to a non-list or vice versa may cause list? to produce the wrong value—for the mutated pair or for another pair that reaches the mutated pair.
The compiler may reorder or even optimize away a call to car or cdr on the grounds that pairs are immutable, in which case a unsafe-set-immutable-car! or unsafe-set-immutable-cdr! may not have an effect on the use of car or cdr.
Added in version 7.9.0.18 of package base.
A vector’s size can never be larger than a fixnum, so even vector-length always returns a fixnum.
Changed in version 6.11.0.2 of package base: Added unsafe-vector*-cas!.
Changed in version 8.11.1.9: Added unsafe-vector-copy, unsafe-vector*-copy, unsafe-vector-set/copy, unsafe-vector*-set/copy, unsafe-vector-append, and unsafe-vector*-append.
Added in version 7.7.0.6 of package base.
Added in version 7.7.0.6 of package base.
Changed in version 7.5.0.15 of package base: Added unsafe-bytes-copy!.
Added in version 7.7.0.6 of package base.
Added in version 8.5.0.7 of package base.
Changed in version 6.11.0.2 of package base: Added unsafe-struct*-cas!.
Similar to
struct-info, but without an inspector check, returning only the first result, and without support for
impersonators.
Added in version 8.8.0.3 of package base.
Each unsafe ...-first and ...-next procedure may return, instead of a number index, an internal representation of a view into the hash structure, enabling faster iteration. The result of these ...-first and ...-next functions should be given as pos to the corresponding unsafe accessor functions.
If the pos provided to an accessor function for a mutable hash was formerly a valid hash index but is no longer a valid hash index for hash, and if bad-index-v is not provided, then the exn:fail:contract exception is raised. No behavior is specified for a pos that was never a valid hash index for hash. Note that bad-index-v argument is technically not useful for the unsafe-immutable-hash-iterate- functions, since an index cannot become invalid for an immutable hash.
Added in version 6.4.0.6 of package base.
Changed in version 7.0.0.10: Added the optional bad-index-v argument.
Changed in version 8.0.0.10: Added ephemeron variants.
Added in version 7.2.0.10 of package base.
17.4 Unsafe Extflonum Operations🔗ℹUnchecked (potentially) versions of
extflsin,
extflcos,
extfltan,
extflasin,
extflacos,
extflatan,
extfllog,
extflexp,
extflsqrt, and
extflexpt. Currently, some of these bindings are simply aliases for the corresponding safe bindings.
Changed in version 7.7.0.8 of package base: Changed unsafe-fl->fx to truncate.
17.5 Unsafe Impersonators and Chaperones🔗ℹIf proc is itself an impersonator that is derived from impersonate-procedure* or chaperone-procedure*, beware that replacement-proc will not be able to call it correctly. Specifically, the impersonator produced by unsafe-impersonate-procedure will not get passed to a wrapper procedure that was supplied to impersonate-procedure* or chaperone-procedure* to generate proc.
Finally, unlike impersonate-procedure, unsafe-impersonate-procedure does not specially handle impersonator-prop:application-mark as a prop.
The unsafety of unsafe-impersonate-procedure is limited to the above differences from impersonate-procedure. The contracts on the arguments of unsafe-impersonate-procedure are checked when the arguments are supplied.
is equivalent to
Similarly, with the same assumptions about
f, the following two procedures
wrap-f1and
wrap-f2are almost equivalent; they differ only in the error message produced when their arguments are functions that return multiple values (and that they update different global variables). The version using
unsafe-impersonate-procedurewill signal an error in the
letexpression about multiple return values, whereas the one using
impersonate-proceduresignals an error from
impersonate-procedureabout multiple return values.
Added in version 6.4.0.4 of package base.
Like
unsafe-impersonate-procedure, but creates a
chaperone. Since
wrapper-procwill be called in lieu of
proc,
wrapper-procis assumed to return a chaperone of the value that
procwould return.
Added in version 6.4.0.4 of package base.
Like
impersonate-vector, but instead of going through interposition procedures, all accesses to the impersonator are dispatched to
replacement-vec.
The result of unsafe-impersonate-vector is an impersonator of vec.
Added in version 6.9.0.2 of package base.
Added in version 6.9.0.2 of package base.
17.6 Unsafe Assertions🔗ℹThe compiler may take advantage of its liberty to pick convenient or efficient behavior in place of a call to unsafe-assert-unreachable. For example, the expression
may be compiled to code equivalent to
(lambda (x) (unsafe-car x))
because choosing to make (unsafe-assert-unreachable) behave the same as (unsafe-car x) makes both branches of the if the same, and then pair? test can be eliminated.
Added in version 8.0.0.11 of package base.
17.7 Unsafe Undefined🔗ℹThe constant unsafe-undefined is used internally as a placeholder value. For example, it is used by letrec as a value for a variable that has not yet been assigned a value. Unlike the undefined value exported by racket/undefined, however, the unsafe-undefined value should not leak as the result of a safe expression, and it should not be passed as an optional argument to a procedure (because it may count as “no value provided”). Expression results that potentially produce unsafe-undefined can be guarded by check-not-unsafe-undefined, so that an exception can be raised instead of producing an undefined value.
The unsafe-undefined value is always eq? to itself.
Added in version 6.0.1.2 of package base.
Changed in version 6.90.0.29: Procedures with optional arguments sometimes use the unsafe-undefined value internally to mean “no argument supplied.”
The unsafe “undefined” constant.
See above for important constraints on the use of unsafe-undefined.
The same as
check-not-unsafe-undefined, except that the error message (if any) is along the lines of “
sym: undefined; assignment before initialization.”
Chaperones
vif it is a structure (as viewed through some
inspector). Every access of a field in the structure is checked to prevent returning
unsafe-undefined. Similarly, every assignment to a field in the structure is checked (unless the check disabled as described below) to prevent assignment of a field whose current value is
unsafe-undefined.
When a field access would otherwise produce unsafe-undefined or when a field assignment would replace unsafe-undefined, the exn:fail:contract exception is raised.
The chaperone’s field-assignment check is disabled whenever (continuation-mark-set-first #f prop:chaperone-unsafe-undefined) returns unsafe-undefined. Thus, a field-initializing assignment—one that is intended to replace the unsafe-undefined value of a field—should be wrapped with (with-continuation-mark prop:chaperone-unsafe-undefined unsafe-undefined ....).
The property value should be a list of symbols used as field names, but the list should be in reverse order of the structure’s fields. When a field access or assignment would produce or replace unsafe-undefined, the exn:fail:contract:variable exception is raised if a field name is provided by the structure property’s value, otherwise the exn:fail:contract exception is raised.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4