Skip to content

Use native igraph object as ground truth #787

@krlmlr

Description

@krlmlr

Converting from R to C

  • No work needs to be done, the native igraph object is stored as an external pointer in the igraph_t_idx_env part of the data structure.
  • When the R graph object is destroyed, it will be garbage-collected eventually. This triggers the finalizer of the external pointer object, which can be made to call destructors in igraph/C.

Converting from C to R

  • We keep the native igraph_t object and store it as an external pointer in the igraph_t_idx_env part of the data structure.
  • We also keep all the information needed to recreate the native igraph_t object in the igraph_t_idx_n, igraph_t_idx_directed, igraph_t_idx_from and igraph_t_idx_to components
  • The native igraph_t object may be lost, e.g., during serialization. In this case, we recreate the native igraph_t object from the igraph_t_idx_n, igraph_t_idx_directed, igraph_t_idx_from and igraph_t_idx_to components

Attributes

All attributes are still handled only from R for now. But because the native igraph_t object may cache R-level attributes, we need to be especially careful about this.

Implementation steps

  • Ensure that all indices into unclass(g) use igraph_t_idx_*, no magic numbers (chore: Ensure we're always using named indexes to access the internal data structure #784)
  • Fix problems in fix: revdepcheck results #789
    • This PR contains the results from checking all reverse dependencies against 6222e73. This is the commit where all indexes in the internal list have been shifted. It seems like our code (or perhaps even other packages) are relying on those indexes. We need to understand what causes the failures, and fix them.
  • Implement accessors (getters + setters) for igraph_t_idx_n, igraph_t_idx_directed, igraph_t_idx_from and igraph_t_idx_to in C
  • Don't use igraph_t_idx_* from R, at all (we can keep using igraph_attr_idx_*)
    • create R wrappers for accessors from previous step if needed
  • Store native igraph_t as external pointer in igraph_t_idx_env
    • the native igraph_t is an external pointer stored in unclass(graph)[[igraph_t_idx_env]]$igraph
  • Rewrite C-level accessors to refer to native igraph_t
    • fallback to recreating native igraph_t from igraph_t_idx_n, igraph_t_idx_directed, igraph_t_idx_from and igraph_t_idx_to if the external pointer is gone
    • use unserialize(serialize(graph, NULL)) to test
  • Avoid populating igraph_t_idx_oi...igraph_t_idx_is in R
  • Implement ALTREP for igraph_t_idx_from and igraph_t_idx_to (requires R 4.0)
  • Double-check immutability (INOUT in functions.yaml)
  • Double-check attribute handling

Follow-up to #783.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions