@@ -730,11 +730,33 @@ let lval_base_resolving_visitor
730
730
(int_of_node nb.id) (int_of_node referent_id));
731
731
htab_put cx.ctxt_lval_to_referent nb.id referent_id
732
732
in
733
+
734
+ (*
735
+ * The point here is just to tickle the reference-a-name machinery in
736
+ * lookup that makes sure that all and only those items referenced get
737
+ * processed by later stages. An lval that happens to be an item will
738
+ * mark the item in question here.
739
+ *)
740
+ let reference_any_name lv =
741
+ let rec lval_is_name lv =
742
+ match lv with
743
+ Ast. LVAL_base {node = Ast. BASE_ident _ }
744
+ | Ast. LVAL_base {node = Ast. BASE_app _ } -> true
745
+ | Ast. LVAL_ext (lv', Ast. COMP_named (Ast. COMP_ident _))
746
+ | Ast. LVAL_ext (lv', Ast. COMP_named (Ast. COMP_app _))
747
+ -> lval_is_name lv'
748
+ | _ -> false
749
+ in
750
+ if lval_is_name lv && lval_is_item cx lv
751
+ then ignore (lookup_by_name cx (! scopes) (lval_to_name lv))
752
+ in
753
+
733
754
lookup_lval lv;
755
+ reference_any_name lv;
734
756
inner.Walk. visit_lval_pre lv
735
757
in
736
758
{ inner with
737
- Walk. visit_lval_pre = visit_lval_pre }
759
+ Walk. visit_lval_pre = visit_lval_pre };
738
760
;;
739
761
740
762
@@ -868,7 +890,8 @@ let resolve_recursion
868
890
869
891
let pattern_resolving_visitor
870
892
(cx :ctxt )
871
- (inner :Walk.visitor ) : Walk.visitor =
893
+ (inner :Walk.visitor )
894
+ : Walk.visitor =
872
895
873
896
let not_tag_ctor nm id : unit =
874
897
err (Some id) " '%s' is not a tag constructor" (string_of_name nm)
@@ -934,6 +957,43 @@ let pattern_resolving_visitor
934
957
{ inner with Walk. visit_stmt_pre = visit_stmt_pre }
935
958
;;
936
959
960
+ let export_referencing_visitor
961
+ (cx :ctxt )
962
+ (inner :Walk.visitor )
963
+ : Walk.visitor =
964
+ let visit_mod_item_pre id params item =
965
+ begin
966
+ match item.node.Ast. decl_item with
967
+ Ast. MOD_ITEM_mod (view , items ) ->
968
+ let is_defining_mod =
969
+ (* auto-ref the default-export cases only if
970
+ * the containing mod is 'defining', meaning
971
+ * not-native / not-use
972
+ *)
973
+ not (Hashtbl. mem cx.ctxt_required_items item.id)
974
+ in
975
+ let reference _ item =
976
+ Hashtbl. replace cx.ctxt_node_referenced item.id () ;
977
+ in
978
+ let reference_export e _ =
979
+ match e with
980
+ Ast. EXPORT_ident ident ->
981
+ let item = Hashtbl. find items ident in
982
+ reference ident item
983
+ | Ast. EXPORT_all_decls ->
984
+ if is_defining_mod
985
+ then Hashtbl. iter reference items
986
+ in
987
+ Hashtbl. iter reference_export view.Ast. view_exports
988
+ | _ -> ()
989
+ end ;
990
+ inner.Walk. visit_mod_item_pre id params item
991
+ in
992
+ { inner with Walk. visit_mod_item_pre = visit_mod_item_pre }
993
+
994
+
995
+ ;;
996
+
937
997
let process_crate
938
998
(cx :ctxt )
939
999
(crate :Ast.crate )
@@ -957,6 +1017,7 @@ let process_crate
957
1017
Walk. empty_visitor))
958
1018
|]
959
1019
in
1020
+
960
1021
let passes_1 =
961
1022
[|
962
1023
(scope_stack_managing_visitor scopes
@@ -966,20 +1027,38 @@ let process_crate
966
1027
Walk. empty_visitor)));
967
1028
|]
968
1029
in
1030
+
969
1031
let passes_2 =
970
1032
[|
971
1033
(scope_stack_managing_visitor scopes
972
1034
(pattern_resolving_visitor cx
973
- Walk. empty_visitor))
1035
+ Walk. empty_visitor));
1036
+ export_referencing_visitor cx Walk. empty_visitor
974
1037
|]
975
1038
in
1039
+
976
1040
log cx " running primary resolve passes" ;
977
1041
run_passes cx " resolve collect" path passes_0 (log cx " %s" ) crate;
978
1042
resolve_recursion cx node_to_references recursive_tag_groups;
979
1043
log cx " running secondary resolve passes" ;
980
1044
run_passes cx " resolve bind" path passes_1 (log cx " %s" ) crate;
981
1045
log cx " running tertiary resolve passes" ;
982
- run_passes cx " resolve patterns" path passes_2 (log cx " %s" ) crate
1046
+ run_passes cx " resolve patterns" path passes_2 (log cx " %s" ) crate;
1047
+
1048
+ iflog cx
1049
+ begin
1050
+ fun _ ->
1051
+ Hashtbl. iter
1052
+ begin
1053
+ fun n _ ->
1054
+ if referent_is_item cx n
1055
+ then
1056
+ log cx " referenced: %a"
1057
+ Ast. sprintf_name
1058
+ (Hashtbl. find cx.ctxt_all_item_names n)
1059
+ end
1060
+ cx.ctxt_node_referenced;
1061
+ end
983
1062
;;
984
1063
985
1064
(*
0 commit comments