-
Notifications
You must be signed in to change notification settings - Fork 154
bsc Internal Compiler error #221
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
Comments
NB this also crashes with bsc v2018_08_gx3 |
As @nanavati says in the duplicate #242 , this source isn't legal because it contains a partially-applied type synonym, and BSC should report that as a user error (not an internal error). The example has this type:
And it'd like to declare an instance for the typeclass
But this isn't supported. So the example tries to use a type synonym:
However, this also doesn't work because type synonyms have no substance, they are merely syntactic sugar. They don't represent type functions (although maybe that's an improvement to consider?). The error |
So... let me see if I understand this correctly. In a sense type synonyms are just "macros" that are expanded in place? So
actually expands out to
But the typeclass |
Yes, they are just macros, and it should be safe for BSC to substitute them away entirely before doing actual typecheck. However, the example does not expand as you've described. BSC only ever expands While it should be safe for BSC to expand away all type synonyms as a first pass, I believe that BSC does not do this. I believe that BSC makes some attempt to keep the synonyms around until the last minute, so that other error messages can be better reported in terms of the original names. So there are places in BSC's source code that apply type synonyms when necessary. I would guess that the internal error occurs because the substitution code does not expect to encounter a partially-applied synonym; the code expects that an earlier step has checked for this case and warned about it. I believe that BSC does check for this in ordinary definitions, but has perhaps not been properly looking for it in instance definitions. The fix for this bug may simply be to improve the current check to also apply to the types of typeclass instance definitions. (FYI, there are some places where BSC ought to be expanding away type synonyms but currently is not, because we discovered that some library code had been relying on erroneous matching of the synonym structure! We discovered this when we attempted to fix BSC to properly expand the synonyms, but we backed it out until we could figure out how to not affect users of the library. I don't think that was ever resolved. See the |
I just hit this again, so here's a shorter reproducer I found: package Test where
import Assert
type Identity a = a
struct W a = { unW :: a Bool } deriving (Bits)
type X = W Identity
assertSize :: (IsModule m c) => m Empty
assertSize = do
let x = valueOf (SizeOf (X))
staticAssert (x == 1) "SizeOf X" This fails with:
|
The following
causes
bsc ZipCrash.bs
to crash withThe text was updated successfully, but these errors were encountered: