VLSI DV Interview Puzzles · All levels

Type Override vs Instance Override Specificity

Both type and instance overrides are configured. Predict concrete type for each create path.

Puzzle

Difficulty: Medium · Puzzle 1 of 6 · Topic: Factory Override Puzzles

Both type and instance overrides are configured. Predict concrete type for each create path.

Code

systemverilog
class base_item extends uvm_sequence_item;
  `uvm_object_utils(base_item)
  function new(string name="base_item"); super.new(name); endfunction
endclass

class ecc_item extends base_item;
  `uvm_object_utils(ecc_item)
  function new(string name="ecc_item"); super.new(name); endfunction
endclass

class poison_item extends base_item;
  `uvm_object_utils(poison_item)
  function new(string name="poison_item"); super.new(name); endfunction
endclass

initial begin
  base_item::type_id::set_type_override(ecc_item::get_type());
  base_item::type_id::set_inst_override(
    poison_item::get_type(),
    "uvm_test_top.env.agentA.seqr.main_phase"
  );
  base_item a, b;
  a = base_item::type_id::create("a", null, "uvm_test_top.env.agentA.seqr.main_phase");
  b = base_item::type_id::create("b", null, "uvm_test_top.env.agentB.seqr.main_phase");
  $display("a=%s b=%s", a.get_type_name(), b.get_type_name());
end

Hint

Factory picks the most specific matching rule for each create request.

Step-by-step solution

diagram
1) Create at agentA path exactly matches instance override, so returns `poison_item`.
2) Create at agentB has no matching instance override; type override applies.
3) Result prints `a=poison_item b=ecc_item`.

Answer

Answer: Instance-path match wins for `a`, so `a=poison_item`; `b` falls back to type override, so `b=ecc_item`.

Why candidates get it wrong

Override call order is not enough; path specificity determines precedence at create-time.

Interviewer follow-up

How would wildcard instance paths affect this result?

Related topics