Skip to content

Commit 62dd8cb

Browse files
committed
Limiting remaining shared_ptr use
1 parent 1a59fad commit 62dd8cb

34 files changed

Lines changed: 533 additions & 373 deletions

File tree

src/cpp_names.ml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -514,16 +514,9 @@ let lookup_method_this_pos n =
514514
| None -> None
515515

516516
(** Check if a method's receiver is a pointer type (coinductive/shared_ptr)
517-
rather than a value type. Returns true if the method's eponymous
518-
inductive is coinductive. For non-method refs, returns false. *)
519-
let method_receiver_is_ptr n =
520-
match is_registered_method n with
521-
| Some (epon_ref, _) -> Table.is_coinductive epon_ref
522-
| None ->
523-
(* Check local method_candidates: they include a GlobRef at element 2
524-
which is the eponymous type. For local candidates without eponymous info,
525-
default to false (value type). *)
526-
false
517+
rather than a value type. All inductives (including coinductives)
518+
are value types, so this always returns false. *)
519+
let method_receiver_is_ptr _n = false
527520

528521
(** Helper module for tracking variable names *)
529522
(** Set of [Id.t] names for tracking variable identifiers. *)

src/cpp_print.ml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,11 +1025,12 @@ and pp_cpp_expr env args t =
10251025
( str "template ",
10261026
str "<" ++ pp_list (pp_cpp_type false []) filtered_tys ++ str ">" )
10271027
in
1028-
(* Coinductive types are shared_ptr → use arrow.
1029-
Value types → use dot. unique_ptr pattern match fields
1030-
are auto-dereferenced at binding time, so variables holding
1031-
inductives are always value types (T or const T&). *)
1032-
let use_arrow = method_receiver_is_ptr n in
1028+
(* All inductives (including coinductives) are value types, so use
1029+
dot access. Exception: [this] is always a pointer, so method
1030+
bodies use arrow. *)
1031+
let use_arrow =
1032+
match this_arg with CPPthis -> true | _ -> false
1033+
in
10331034
let accessor = if use_arrow then "->" else "." in
10341035
(* Parenthesize deref expressions for correct precedence. *)
10351036
let obj_pp =
@@ -1073,7 +1074,9 @@ and pp_cpp_expr env args t =
10731074
let body_derefs_var =
10741075
let found = ref false in
10751076
let rec scan_expr = function
1076-
| CPPderef (CPPvar id) when String.equal (Id.to_string id) "_self" ->
1077+
| CPPderef (CPPvar _) ->
1078+
(* Dereferencing a simple variable (shared_ptr, pointer) is safe
1079+
for by-value capture — the pointer/smart-pointer is copied. *)
10771080
()
10781081
| CPPderef _ -> found := true
10791082
| e ->

0 commit comments

Comments
 (0)