Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NO_TRANSLATION_FOR #2878

Open
kleinreact opened this issue Jan 22, 2025 · 1 comment
Open

NO_TRANSLATION_FOR #2878

kleinreact opened this issue Jan 22, 2025 · 1 comment

Comments

@kleinreact
Copy link
Member

kleinreact commented Jan 22, 2025

The following topEntity

topEntity :: Unsigned 8 -> Unsigned 8
topEntity = fromInteger . toInteger . g . fromInteger . toInteger
 where
  g :: Natural -> Natural
  g x = x + 1

produces

** GENERATED BY CLASH 1.9.0. DO NOT MODIFY.
*/
`default_nettype none
`timescale 100fs/100fs
module topEntity
    ( // Inputs
      input wire [7:0] x

      // Outputs
    , output wire [7:0] result
    );
  wire signed [63:0] c$app_arg;
  wire signed [63:0] c$app_arg_0;

  assign c$app_arg = NO_TRANSLATION_FOR:GHC.Num.Integer.integerFromNatural;

  assign c$app_arg_0 = $unsigned({{(64-8) {1'b0}},x});

  assign result = $unsigned(c$app_arg[0+:8]);

endmodule

and a similar NO_TRANSLATION_FOR, if targeting VHDL.

I would expect a dubious primitive warning here, as for Integer, or an error, but not Clash silently producing invalid HDL.

@kleinreact kleinreact changed the title NO_TRANSLATION_FOR:GHC.Num.Integer.integerFromNatural NO_TRANSLATION_FOR Jan 22, 2025
@christiaanb
Copy link
Member

christiaanb commented Jan 22, 2025

Ah, this is an unfortunate interaction between

  1. a fall-through case I added a long time ago for netlist-generation not breaking on arguments that would be unused: 0c6c63d#diff-edc71942970da8c1935b90eadabf16b3fe0e29dd87f42e261c5279c89cfbb539R195
  2. A GHC 9 upgrade https://github.com/clash-lang/clash-compiler/blame/d9e2a53fe81eb23616d9fbd2e7944845c5c6f6c4/clash-ghc/src-ghc/Clash/GHC/Evaluator/Primitive.hs#L1892-L1898
  3. A primitive being added that was then only tested when applied to a constant so we would get compile-time reduction 211f8f3#diff-f9de82a65e58cf9f5d5b4806db49fb6e31eb292b9adfb0538441ac502c673a04R10-R14

I guess we should add a BlackBox that produces error for a negative integer, and bitcoerces otherwise.

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

No branches or pull requests

2 participants