Skip to content

copilot-bluespec: Special floating-point values are translated to syntactically invalid Bluespec code #696

Description

@RyanGlScott

Description

copilot-bluespec currently generates syntactically invalid Bluespec code for special floating-point values, such as negative zero, infinity, and NaN values. For instance, it compiles infinity values to Infinity, which is not a valid Bluespec floating-point value.

Type

  • Bug: incorrect generated code.

Additional context

None.

Requester

  • Ryan Scott (Galois)

Method to check presence of bug

Take the following Copilot specification, which defines a stream containing an infinity value:

-- Infinity.hs
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE NoImplicitPrelude #-}
moduleMain (main) whereimportLanguage.CopilotimportCopilot.Compile.Bluespec (compile)
inf::StreamDouble
inf = constant (1/0)
spec::Spec
spec = trigger "trig" true [arg inf]
main::IO()
main =do
spec' <- reify spec
compile "Infinity" spec'

Compile this to Bluespec code:

$ runghc NegativeZero.hs

Then attempt to compile the generated Bluespec code. This will fail with a syntax error:

$ bsc -sim -g mkInfinity -u Infinity.bs
<snip>
compiling Infinity.bs
Error: "Infinity.bs", line 27, column 26: (T0003)
Unbound constructor `Infinity'

Expected result

The generated Bluespec program should compile.

Desired result

The generated Bluespec program should compile.

Proposed solution

Add special cases to copilot-bluespec's constFP, to handle floating-point values ensuring that they are correctly translated to Bluespec code.

Add test cases to copilot-bluespec demonstrating correct translation for various special floating-point values.

Further notes

Activity

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

Metadata

Metadata

Assignees

Labels

CR:Status:ClosedAdmin only: Change request that has been completedCR:Type:BugAdmin only: Change request pertaining to error detected

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions