Documentation
¶
Overview ¶
Copyright Consensys Software Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
SPDX-License-Identifier: Apache-2.0
Copyright Consensys Software Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
SPDX-License-Identifier: Apache-2.0
Index ¶
- type Constraint
- func (p Constraint[F, E]) Accepts(tr trace.Trace[F], sc schema.AnySchema[F]) (bit.Set, schema.Failure)
- func (p Constraint[F, E]) Bounds(module uint) util.Bounds
- func (p Constraint[F, E]) Consistent(schema schema.AnySchema[F]) []error
- func (p Constraint[F, E]) Contexts() []schema.ModuleId
- func (p Constraint[F, E]) Lisp(mapping schema.AnySchema[F]) sexp.SExp
- func (p Constraint[F, E]) Name() string
- func (p Constraint[F, E]) Substitute(mapping map[string]F)
- type Failure
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Constraint ¶
type Constraint[F field.Element[F], E term.Evaluable[F]] struct { // A unique identifier for this constraint. This is primarily useful for // debugging. Handle string // Evaluation Context for this constraint which must match that of the // constrained expression itself. Context schema.ModuleId // The expressions whose values are being constrained to be within the given // bound(s). Sources []E // The number of bits permitted for all values of the corresponding expression. // For example, with a bitwidth of 8, the maximum permitted value is 255. Bitwidths []uint }
Constraint restricts all values for a given expression to be within a range [0..n) for some bound n. Any bound is supported, and the system will choose the best underlying implementation as needed.
func NewConstraint ¶
func NewConstraint[F field.Element[F], E term.Evaluable[F]](handle string, context schema.ModuleId, exprs []E, bitwidths []uint) Constraint[F, E]
NewConstraint constructs a new Range constraint
func (Constraint[F, E]) Accepts ¶
func (p Constraint[F, E]) Accepts(tr trace.Trace[F], sc schema.AnySchema[F]) (bit.Set, schema.Failure)
Accepts checks whether a range constraint holds on every row of a table. If so, return nil otherwise return an error.
func (Constraint[F, E]) Bounds ¶
func (p Constraint[F, E]) Bounds(module uint) util.Bounds
Bounds determines the well-definedness bounds for this constraint for both the negative (left) or positive (right) directions. For example, consider an expression such as "(shift X -1)". This is technically undefined for the first row of any trace and, by association, any constraint evaluating this expression on that first row is also undefined (and hence must pass).
func (Constraint[F, E]) Consistent ¶
func (p Constraint[F, E]) Consistent(schema schema.AnySchema[F]) []error
Consistent applies a number of internal consistency checks. Whilst not strictly necessary, these can highlight otherwise hidden problems as an aid to debugging.
func (Constraint[F, E]) Contexts ¶
func (p Constraint[F, E]) Contexts() []schema.ModuleId
Contexts returns the evaluation contexts (i.e. enclosing module + length multiplier) for this constraint. Most constraints have only a single evaluation context, though some (e.g. lookups) have more. Note that all constraints have at least one context (which we can call the "primary" context).
func (Constraint[F, E]) Lisp ¶
func (p Constraint[F, E]) Lisp(mapping schema.AnySchema[F]) sexp.SExp
Lisp converts this schema element into a simple S-Expression, for example so it can be printed.
func (Constraint[F, E]) Name ¶
func (p Constraint[F, E]) Name() string
Name returns a unique name for a given constraint. This is useful purely for identifying constraints in reports, etc.
func (Constraint[F, E]) Substitute ¶
func (p Constraint[F, E]) Substitute(mapping map[string]F)
Substitute any matchined labelled constants within this constraint
type Failure ¶
type Failure[F any] struct { // Handle of the failing constraint Handle string // Enclosing context Context schema.ModuleId // Constraint expression Expr term.Evaluable[F] // Range restriction Bitwidth uint // Row on which the constraint failed Row uint }
Failure provides structural information about a failing type constraint.
func (*Failure[F]) RequiredCells ¶
RequiredCells identifies the cells required to evaluate the failing constraint at the failing row.