Id define()

in glean/rts/stacked.h [124:149]


  Id define(Pid type, Fact::Clause clause, Id max_ref = Id::invalid()) override {
    // TODO: We probably want to look up in stacked first but the current
    // interface doesn't support doing that without two lookups.

    // If the clause references a local fact then it can't possibly exist in the
    // global Lookup so don't bother looking it up there.
    if (max_ref < mid) {
      auto id = base->idByKey(type, clause.key());
      if (id && id < mid) {
        // NOTE: We assume that 'value' has been typechecked. If it is empty then
        //       it must be the only inhabitant of its type (which must be () or
        //       similar). This means that there is no need to check against the
        //       value stored in the database as that must be empty, too.
        if (clause.value_size != 0) {
          bool found = base->factById(id, [&](auto, auto found) {
            if (clause.value() != found.value()) {
              id = Id::invalid();
            }
          });
          assert(found);
        }
        return id;
      }
    }
    return stacked->define(type, clause, max_ref);
  }