Skip to content

feat: support field-specific binary constraint files#1483

Open
DavePearce wants to merge 3 commits intomainfrom
1480-feat-support-field-specific-binary-constraint-files
Open

feat: support field-specific binary constraint files#1483
DavePearce wants to merge 3 commits intomainfrom
1480-feat-support-field-specific-binary-constraint-files

Conversation

@DavePearce
Copy link
Collaborator

@DavePearce DavePearce commented Feb 9, 2026

Note

Medium Risk
Changes the serialization/registration path for schemas (GOB) and introduces deep-clone behavior used in parallel tests; failures would surface as decode panics or subtle cross-test/state interference.

Overview
Adds GOB registrations for schema.AnySchema[word.BigEndian] wrappers around MacroHirProgram/MicroHirProgram, and removes the custom HIR constraint binary encoding in favor of relying on standard GOB behavior.

Introduces deep-cloning utilities: binfile.BinaryFile.Clone() (round-trips through MarshalBinary/UnmarshalBinary) and SchemaStack.Clone() (GOB round-trip per schema layer), and updates parallel test execution to use a per-test cloned schema stack to avoid shared mutable state between runs.

Written by Cursor Bugbot for commit d9f90e4. This will update automatically on new commits. Configure here.

@DavePearce DavePearce linked an issue Feb 9, 2026 that may be closed by this pull request
// are not found at the Constraint level.
type Constraint struct {
constraint schema.Constraint[word.BigEndian]
Constraint schema.Constraint[word.BigEndian]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing gob registrations after removing custom encoding

High Severity

Removing the custom GobEncode/GobDecode methods from Constraint while making the field exported means gob now relies on default interface encoding for the Constraint field. However, three concrete types — Assertion, FunctionCall, and InterleavingConstraint — are never registered via gob.Register in the init() function of schema.go. The old custom encoding in encoding.go handled all types manually with tags, so registration wasn't needed. Now, serializing any binary file containing these constraint types will fail at runtime. Additionally, Ite, Negate, and VectorAccess are also unregistered and will cause failures when encountered within nested interface fields of registered constraint types.

Fix in Cursor Fix in Web

This replaces the manual HIR encoding with GOB encoding.
This adds support for SchemaStack.Clone() which essentially clones a
schema by encoding it into bytes and then decoding it.
This alters the testing mechanism to clone the schema stack inbetween
test runs.  The purpose of this is to ensure that each test is run with
a fresh stack to protect against any unexpected aliasing issues.

However, at this time, it fails because various components need to be
registered with relevant interfaces.
@DavePearce DavePearce force-pushed the 1480-feat-support-field-specific-binary-constraint-files branch from 1b2b4cf to d9f90e4 Compare February 9, 2026 21:05
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

var (
binfile util.Option[binfile.BinaryFile]
abstractSchemas = cloneSchemas(p.abstractSchemas)
concreteSchemas = cloneSchemas(p.concreteSchemas)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concrete schema clone panics due to unregistered gob types

High Severity

cloneSchemas(p.concreteSchemas) will always panic because the concrete types behind AnySchema[F] for MIR and AIR schemas (e.g., UniformSchema[F, mir.Module[F]]) are never registered with gob.Register. Only *MacroHirProgram and *MicroHirProgram are registered (for word.BigEndian abstract schemas). Since encodeSchema panics on error, calling Clone() with any concrete schemas crashes immediately.

Additional Locations (1)

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: support field-specific binary constraint files

1 participant

Comments