cogent icon indicating copy to clipboard operation
cogent copied to clipboard

Dargent ignores field if not in layout.

Open gteege opened this issue 5 years ago • 1 comments

The code

type R = {a: U32, b: U32} layout record {a: 4B at 0B }
f: R -> R
f x = x{a=5}

compiles successfully but creates a C datatype

struct t1 { unsigned int data[1U]; } ;

i.e., the b field is silently ignored. When the field is used afterwards, the compiler crashes:

type R = {a: U32, b: U32} layout record {a: 4B at 0B }
f: R -> R
f x = x{a=5,b=7}

causes the error message

cogent -g put-nonlayout-field.cogent 
Parsing...
Resolving dependencies...
Typechecking...
Desugaring and typing...
Normalising...ANF
Re-typing NF...
Simplifying...
Skipped
Monomorphising...
Re-typing monomorphic AST...
Generating C code...
  > Writing to file: ./put-nonlayout-field.h
cogent: Map.!: given key is not an element in the map
CallStack (from HasCallStack):
  error, called at libraries/containers/Data/Map/Internal.hs:610:17 in containers-0.6.0.1:Data.Map.Internal

gteege avatar Nov 12 '19 14:11 gteege

@ccapitalK Your implementation should fix this, right?

zilinc avatar Nov 12 '19 23:11 zilinc