Skip to documentation
SLOP

tiny.smt.Model

Reference tiny.smt Model

Defined in bitvec.

The values a satisfying assignment gives: one per named constant, and one entry per encoded application of each uninterpreted function.

API (10)

Actions

Public operations.

Fields and members

Public fields and members.

No direct callersNo direct callsbitvecModel
Static calls · unresolved targets: unknown · external targets: unknown.

Source

Source: lib/smt/src/bitvec.zig:211

zig
/// The values a satisfying assignment gives: one per named constant, and one entry per encoded/// application of each uninterpreted function. A caller reads a constant's value from it with `get`/// or prints it with `write` after `Encoder.model` returns one for a satisfiable answer. The model/// owns every name and value in it, and its owner frees them all with `deinit`.pub const Model = struct {    allocator: std.mem.Allocator,    /// The named constants and their values, in the order the constants were built. Two constants    /// built with one name give two entries, and `get` returns the first.    entries: std.ArrayList(ModelEntry) = .empty,    /// The model of each uninterpreted function with an encoded application, one per function name.    functions: std.ArrayList(FunctionModel) = .empty,    /// Returns an empty model that allocates with `allocator`. A caller makes one to build an    /// expected model by hand, and `Encoder.model` makes one. The call allocates nothing.    pub fn init(allocator: std.mem.Allocator) Model {        return .{ .allocator = allocator };    }    /// Frees every name, every value and every function model. The owner calls it once when done    /// with the values. A value returned by `get` and a pointer returned by `getFunction` are    /// invalid afterward.    pub fn deinit(self: *Model) void {        for (self.entries.items) |*entry| {            self.allocator.free(entry.name);            entry.value.deinit(self.allocator);        }        self.entries.deinit(self.allocator);        for (self.functions.items) |*function| {            function.deinit(self.allocator);        }        self.functions.deinit(self.allocator);        self.* = undefined;    }    /// Adds the constant `name` with value `value`. `Encoder.model` calls it once per named    /// constant. The call copies `name` and takes ownership of `value`, and on failure it frees    /// `value`.    pub fn append(self: *Model, name: []const u8, value: ModelValue) !void {        var owned_value = value;        errdefer owned_value.deinit(self.allocator);        const owned_name = try self.allocator.dupe(u8, name);        errdefer self.allocator.free(owned_name);        try self.entries.append(self.allocator, .{ .name = owned_name, .value = owned_value });    }    /// Returns the value of the first constant named `name`, or `null` when the model has none. A    /// caller reads with it a constant's value after a satisfiable answer, as every encoder test    /// does. An array value's cells stay owned by the model, so the caller does not free them. The    /// lookup checks each entry in turn.    pub fn get(self: *const Model, name: []const u8) ?ModelValue {        for (self.entries.items) |entry| {            if (std.mem.eql(u8, entry.name, name)) return entry.value;        }        return null;    }    /// Adds an entry with argument values `arguments` and result value `result` to the model of the    /// function `name`, and creates that function's model on first use. `Encoder.model` calls it    /// once per encoded application. The call takes ownership of `arguments` and `result`, and on    /// failure it frees them.    pub fn appendFunctionApplication(self: *Model, name: []const u8, arguments: []ModelValue, result: ModelValue) !void {        var owned_result = result;        errdefer {            for (arguments) |*argument| {                argument.deinit(self.allocator);            }            self.allocator.free(arguments);            owned_result.deinit(self.allocator);        }        const function = try self.functionModel(name);        try function.entries.append(self.allocator, .{ .arguments = arguments, .result = owned_result });    }    /// Returns the model of the function `name`, or `null` when no application of it was encoded. A    /// caller checks the values an uninterpreted function took with it. The model keeps ownership,    /// and the pointer is valid until the model changes or is freed.    pub fn getFunction(self: *const Model, name: []const u8) ?*const FunctionModel {        for (self.functions.items) |*function| {            if (std.mem.eql(u8, function.name, name)) return function;        }        return null;    }    /// Writes one `name: value` line per constant, then per function a `name:` line followed by one    /// indented `(arguments) -> result` line per entry, with each value in the syntax of    /// `ModelValue.write`. A caller prints a model for a person to read with it. The call returns    /// only the writer's errors.    pub fn write(self: *const Model, writer: *std.Io.Writer) std.Io.Writer.Error!void {        for (self.entries.items) |entry| {            try writer.print("{s}: ", .{entry.name});            try entry.value.write(writer);            try writer.writeAll("\n");        }        for (self.functions.items) |function| {            try writer.print("{s}:\n", .{function.name});            for (function.entries.items) |entry| {                try writer.writeAll("  (");                for (entry.arguments, 0..) |argument, index| {                    if (index > 0) try writer.writeAll(", ");                    try argument.write(writer);                }                try writer.writeAll(") -> ");                try entry.result.write(writer);                try writer.writeAll("\n");            }        }    }    fn functionModel(self: *Model, name: []const u8) !*FunctionModel {        for (self.functions.items) |*item| {            if (std.mem.eql(u8, item.name, name)) return item;        }        const owned_name = try self.allocator.dupe(u8, name);        errdefer self.allocator.free(owned_name);        try self.functions.append(self.allocator, .{ .name = owned_name });        return &self.functions.items[self.functions.items.len - 1];    }};

Source: lib/smt/src/root.zig:121

zig
pub const Model = bitvec.Model;
Called byCallsNo direct callsbitvec.EncodermodelModelappend
Static calls · unresolved targets: 1 · external targets: 3.
Called byCallsNo direct callersprivate sourcelib.smt.src.bitvec.ModelfunctionModelModelappendFunctionApplication
Static calls · unresolved targets: 1 · external targets: 3.
Called byCallsNo direct callsbitvec.EncodermodelModeldeinit
Static calls · unresolved targets: 0 · external targets: 4.
Called byCallsNo direct callsbitvec.EncodermodelModelinit
Static calls · unresolved targets: 0 · external targets: 0.

Audit

Definitions8
Public names16
Members3
Version26.7.0
Revisiondaab053ee433