Type checking questions

Aaron Tomb aarontomb at gmail.com
Wed Nov 2 21:21:51 GMT 2011


Hi Thorkil,

I wrote most of the current type checking implementation, so I hope I
can answer your question.

The key thing to know is that I wrote the checker primarily to inspect
the types of various expressions in order to do program analysis,
rather than as a complete checker. You can think of it as calculating
the answer to "assuming this expression is type correct, what is its
type?".

It would definitely be nice for it to be a complete type checker, and
perhaps to include various types of checking beyond what's mandated by
the standard. But that's not implemented yet.

As to the question of how to implement checkCompatibleTypes, I think
that you're right: to work correctly, it'll need to take some extra
NodeInfo parameters. Hopefully the right NodeInfo instances to use are
clear at its call sites, but I don't recall offhand.

Does that help?

Thanks,
Aaron

On Wed, Nov 2, 2011 at 2:07 PM, Thorkil Naur <naur at post11.tele.dk> wrote:
> Hello Benedikt,
>
> I have started to play with language-c and noted the following:
>
> 1.  In the language-c-0.4.2 package that I downloaded from hackage, the
>    following files, mentioned in the README, are not included:
>
>      src/README
>      examples
>      test(/harness)
>
>    The files are present in the darcs repository, so this is not a
>    pressing issue.
>
> 2.  The type checker disagrees with gcc. For example:
>
>      $ echo "int u(){} int u;" > t1.c
>      $ ./TypeCheck t1.c
>      t1.c: success
>      $ gcc -c t1.c
>      t1.c:1: error: ‘u’ redeclared as different kind of symbol
>      t1.c:1: note: previous definition of ‘u’ was here
>      $
>
>    Apparently, the failure to detect this problem is in the
>    (presumably) missing details of
>
>      checkCompatibleTypes :: Type -> Type -> Either TypeMismatch ()
>      checkCompatibleTypes _ _ = Right ()
>
>    in Language/C/Analysis/TravMonad.hs.
>
> 3.  To be able to produce a TypeMismatch, checkCompatibleTypes would
>    seem to need a couple of NodeInfo's, which I don't understand how
>    it could manage to get hold of.
>
> 4.  And, if I just uses the useless undefNode to report TypeMismatch'es
>    in checkCompatibleTypes, I get a problem when reporting them:
>
>      *** Exception: No match in record selector posFile
>
>    This happens in showErrorInfo in Language/C/Data/Error.hs which is
>    not prepared to handle ErrorInfo's with Position's that are
>    NoPosition (or one of the other non-Position variants).
>
> I hope that you (and cc: the language-c mailing list) are the right
> audience for this and will be able to comment.
>
> Thanks and best regards
> Thorkil
>
> _______________________________________________
> Language-c mailing list
> Language-c at projects.haskell.org
> http://projects.haskell.org/cgi-bin/mailman/listinfo/language-c
>



More information about the Language-c mailing list