CozySynthesizer / cozy

The collection synthesizer
https://cozy.uwplse.org
Apache License 2.0
209 stars 18 forks source link

C++ code generator cannot cope with Set<String> #18

Closed seizethedave closed 6 years ago

seizethedave commented 6 years ago

This spec:

WordBag:
    state words : Set<String>

    op addWord(w : String)
        assume not (w in words);
        words.add(w);

    query containsPassword()
        "password" in words

Produces this error:

D-69-91-185-110:cozy dgrant$ cozy  --simple --c++ out.h specs/test5.ds
Checking assumptions...
Done!
Adding new query _query37...
Adding new query _query38...

_var31 : Bag<String> = words

WordBag:
  state _var31 : Bag<String>
  query containsPassword():
    ('password' in _var31)
  query _query37(w : String):
    ((_var31 + [w]) - _var31)
  query _query38(w : String):
    (_var31 - (_var31 + [w]))
  op addWord(w : String):
    var _name63 : Bag<String> = _query38(w);
    var _name64 : Bag<String> = _query37(w);
    for _var39 in _name63:
      _var31.remove(_var39);
    for _var39 in _name64:
      _var31.add(_var39);

Code generation failed!
Implementation was dumped to /tmp/failed_codegen.py
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.5/bin/cozy", line 11, in <module>
    load_entry_point('Cozy', 'console_scripts', 'cozy')()
  File "/Users/dgrant/Dev/cozy/cozy/cozy/main.py", line 151, in run
    out.write(codegen.CxxPrinter(use_qhash=args.use_qhash).visit(impl, state_map, share_info, abstract_state=ast.spec.statevars))
  File "/Users/dgrant/Dev/cozy/cozy/cozy/common.py", line 149, in visit
    return getattr(self, visit_func)(x, *args, **kwargs)
  File "/Users/dgrant/Dev/cozy/cozy/cozy/codegen/cxx.py", line 899, in visit_Spec
    s += self.declare_field(name, t, indent=INDENT)
  File "/Users/dgrant/Dev/cozy/cozy/cozy/codegen/cxx.py", line 822, in declare_field
    field_decl=self.visit(type, name),
  File "/Users/dgrant/Dev/cozy/cozy/cozy/common.py", line 149, in visit
    return getattr(self, visit_func)(x, *args, **kwargs)
  File "/Users/dgrant/Dev/cozy/cozy/cozy/codegen/cxx.py", line 68, in visit_TBag
    return self.visit_TNativeList(t, name)
  File "/Users/dgrant/Dev/cozy/cozy/cozy/codegen/cxx.py", line 72, in visit_TNativeList
    return "std::vector< {} > {}".format(self.visit(t.t, ""), name)
  File "/Users/dgrant/Dev/cozy/cozy/cozy/common.py", line 149, in visit
    return getattr(self, visit_func)(x, *args, **kwargs)
  File "/Users/dgrant/Dev/cozy/cozy/cozy/codegen/cxx.py", line 80, in visit_Type
    raise NotImplementedError(t)
NotImplementedError: TString()
seizethedave commented 6 years ago

This ended up being a few issues:

  1. TString wasn't being emitted
  2. the <string> header wasn't being emitted. (This now happens whether or not the spec uses Strings.)
  3. String literal expressions weren't being emitted.