anchor.diff:      FieldNames = [ Name || {id, _, Name} <- Fields ],
       UniqueFields = lists:usort(FieldNames),
       Candidates = [RecName || {_, _, {app_t, _, {id, _, RecName}, _}} <- ets:lookup(record_fields, hd(FieldNames))],
  -    TypesAndFields = [case ets:lookup(record_types, RecName) of
  -                          [{RecName, _, RecFields}] ->
  +    TypesAndFields = [case lookup_type(RecName) of
  +                          {_, {record_t, RecFields}} ->
                                 {RecName, [Field || {field_t, _, {id, _, Field}, _} <- RecFields]};
  -                          [] ->
  +                          _ -> %% impossible?
                                 error({no_definition_for, RecName, in, Candidates})
                         end
                         || RecName <- Candidates],
  
positive.code:     ets:new(record_types, [public, named_table, set]),
      %% A relation from field names to types
      ets:new(record_fields, [public, named_table, bag]),
      [begin
           ets:insert(record_types, {Name, Args, Fields}),
           [ets:insert(record_fields, {FieldName, FieldType, {app_t, Attrs, Id, Args}})
            || {field_t, _, {id, _, FieldName}, FieldType} <- Fields]
       end
       || {type_def, Attrs, Id={id, _, Name}, Args, {record_t, Fields}} <- Defs].
  
  destroy_record_types() ->
      ets:delete(record_types),
      ets:delete(record_fields).
  
  create_field_constraints() ->
      %% A relation from uvars to constraints
  
negative.code:          || {RecordType, FieldName, FieldType, When} <- Constraints],
      SolvedConstraints =
          [begin
              RecId = {id, Attrs, RecName} = record_type_name(RecType),
              case lookup_type(RecName) of
                  {Formals, {record_t, Fields}} ->
                       FieldTypes = [{Name, Type} || {field_t, _, {id, _, Name}, Type} <- Fields],
                       {id, _, FieldString} = FieldName,
                       case proplists:get_value(FieldString, FieldTypes) of
  