anchor.diff:  let trie_empty = Trie (None, StrEmpty)
   let subtrie_empty = ProperSubtrie trie_empty
   
  -let rec trie_descend_exact (keys: list<string>) (tr: trie<'a>) : option<trie<'a>> =
  -  match keys with
  +type result<'a> = path*'a
  +type oresult<'a> = option<result<'a>>
  +
  +let extend_result_path (prefix: string) (pth, res) : result<'a> =
  +  (prefix :: pth, res)
  +
  +let rec trie_descend_exact (pth: path) (tr: trie<'a>) : option<trie<'a>> =
  +  match pth with
     | [] -> Some tr
  -  | id :: keys ->
  +  | id :: pth ->
       match tr with
       | Trie (vopt, subtries) ->
  -      match btree_find_trie_exact subtries id with
  -      | None -> None
  -      | Some subtrie -> trie_descend_exact keys subtrie
  -and resolve_subtrie (tr: btree<subtrie<'a>>) (k: string) (subtrie: subtrie<'a>) : option<trie<'a>> =
  +      bind_opt (btree_find_trie_exact subtries id)
  +        (fun subtrie -> trie_descend_exact pth subtrie)
  +
  +and resolve_subtrie_aliases (tr: btree<subtrie<'a>>) (k: string) (subtrie: subtrie<'a>) : option<trie<'a>> =
     match subtrie with
     | Alias (hd, tl) ->
  -    bind_opt (btree_find_trie_exact tr hd) (fun tr' -> trie_descend_exact tl tr')
  +    bind_opt (btree_find_trie_exact tr hd)
  +      (fun tr' -> trie_descend_exact tl tr')
     | ProperSubtrie st -> Some st
  +
   and btree_find_trie_exact (tr: btree<subtrie<'a>>) (k: string) : option<trie<'a>> =
  -  bind_opt (btree_find_exact tr k) (resolve_subtrie tr k)
  -
  -let trie_find_exact (keys: list<string>) (tr: trie<'a>) : option<'a> =
  -  bind_opt (trie_descend_exact keys tr) (function | Trie (vopt, _) -> vopt)
  -
  -let trie_insert (tr: trie<'a>) (keys: list<string>) (v: 'a) : trie<'a> =
  -  let rec aux keys tr =
  +  bind_opt (btree_find_exact tr k) (resolve_subtrie_aliases tr k)
  +
  +let trie_find_exact (pth: path) (tr: trie<'a>) : option<'a> =
  +  bind_opt (trie_descend_exact pth tr)
  +    (function | Trie (vopt, _) -> vopt)
  +
  +let trie_insert (tr: trie<'a>) (pth: path) (v: 'a) : trie<'a> =
  +  let rec aux pth tr =
       match tr with
       | Trie (vopt, subtries) ->
  -      match keys with
  +      match pth with
         | [] ->
           Trie (Some v, subtries)
  -      | id :: keys ->
  +      | id :: pth ->
           match dflt subtrie_empty (btree_find_exact subtries id) with
           | Alias _ -> failwith "Inserting under module alias"
           | ProperSubtrie subtrie ->
  -          Trie (vopt, btree_insert subtries id (ProperSubtrie (aux keys subtrie))) in
  -  aux keys tr
  -
  -let rec trie_flatten (tr: trie<'a>) (acc: list<'a>) =
  +          Trie (vopt, btree_insert subtries id (ProperSubtrie (aux pth subtrie))) in
  +  aux pth tr
  +
  +let rec trie_flatten (rev_path_prefix: path) (tr: trie<'a>) (acc: list<result<'a>>) =
     match tr with
     | Trie (vopt, subtries) ->
       let helper k subtr acc =
  -      match resolve_subtrie subtries k subtr with
  +      match resolve_subtrie_aliases subtries k subtr with
         | None -> acc
  -      | Some subtrie -> trie_flatten subtrie acc in
  +      | Some subtrie -> trie_flatten (k :: rev_path_prefix) subtrie acc in
       let acc = btree_fold subtries helper acc in
       match vopt with
       | None -> acc
  -    | Some v -> v :: acc
  -
  -let trie_find_prefix (keys: list<string>) (tr: trie<'a>) =
  -  let rec aux (keys: list<string>) (tr: trie<'a>) (acc: list<'a>) =
  -    match keys with
  -    | [] -> trie_flatten tr acc
  -    | id :: keys ->
  +    | Some v -> (List.rev rev_path_prefix, v) :: acc
  +
  +let trie_find_prefix (pth: path) (tr: trie<'a>) =
  +  let rec aux (rev_path_prefix: path) (pth: path) (tr: trie<'a>) (acc: list<result<'a>>) =
  +    match pth with
  +    | [] -> trie_flatten rev_path_prefix tr acc
  +    | id :: pth ->
         match tr with
         | Trie (vopt, subtries) ->
  -        let matching_subtries : list<subtrie<'a>> = btree_find_prefix subtries id in
  -        List.foldBack (fun subtr acc ->
  -                       match resolve_subtrie subtries id subtr with
  +        let matching_subtries : list<string*subtrie<'a>> = btree_find_prefix subtries id in
  +        List.foldBack (fun (complete_id, subtr) acc ->
  +                       match resolve_subtrie_aliases subtries id subtr with
                          | None -> acc
  -                       | Some subtrie -> aux keys subtrie acc)
  +                       | Some subtrie ->
  +                         aux (complete_id :: rev_path_prefix) pth subtrie acc)
                         matching_subtries acc in
  -  aux keys tr []
  +  aux [] pth tr []
   
   let trie_add_alias (tr: trie<'a>) key path =
     match path with
  
positive.code: 
  (** * Tries * **)
  
  type subtrie<'a> =
  | Alias of string * list<string>
  | ProperSubtrie of trie<'a>
  and trie<'a> =
  | Trie of option<'a> * btree<subtrie<'a>>
  
negative.code: type candidate =
  | Lid of lid
  
  let pth_of_candidate (c: candidate) =
    match c with
    | Lid l -> List.map FStar.Ident.text_of_id (FStar.Ident.ids_of_lid l)
  
  