Skip to content

Linking: temporary publicity #2766

@acl-cqc

Description

@acl-cqc

Linking operates only on Public functions; so we have to make functions Public to use linking, and then we are gonna have those functions lying around still public when we have no more wish to link them. A particular case is following ReplaceTypes that do linearization (arrays, bools). There are a number of possibilities:

  • After we've finished (e.g. linearization), go and hide any functions that were inserted. This requires finding them via...
    • name being the mangled form of __discard, so beginning $__discard or something like that, which is a bit, ugh.
    • Add some kind of state mechanism for the ReplaceTypes callback to record the functions as it generates them.
      • Inside the callback - I guess via a RefCell since the callback is Fn not FnMut (and should be, for exactly the same reason as why RefCell is a bad idea: a single ReplaceTypes can operate on multiple Hugrs, etc. etc.)
      • Into ReplaceTypes... feat!: Allow making (and sharing) new FuncDecls in linearization #2108 started on this but it's pretty hard/nasty so I'm not clear I want to go that way
  • Record the set of functions in the Hugr before we start; any not in that set, must have been new....
    • We could add this as a general facility to ReplaceTypes
      • Perhaps an fn ReplaceTypes::set_hide_new_funcs(&mut self, FuncsToHide) (an enum with variants None, maybe-default OnlyDefns, All) - so ReplaceTypes snapshots the module children before it starts, then after it's done goes through the module-children and hides appropriate ones not in the snapshot. One nice feature is that (with default None) this is a non-breaking change.
      • Or, we make ReplaceTypes return the new functions/module-children added. (Just does a snapshot before and then filters out.) Breaking as ReplaceTypes returns a bool atm (could become an Option<Vec<Node>>.)
      • The latter would be easy enough for any caller to ReplaceTypes to do the snapshotting itself! I think the only caller is ReplaceBoolPass (tket2) so we could just do it there.
  • Or, tag new functions created during ReplaceTypes via metadata, and then look for that at the end (same variations: ReplaceTypes hides them; ReplaceTypes return them; just do it all in the caller). One question here is lining up the metadata set by the hugr-core linearization handlers with the later hiding (is there one metadata that says this or is it configurable).
  • A more general facility (not specific to ReplaceTypes) is to add a new variants of enum Visibility. (This is a bunch of code: we have distinct enum Visibilitys in hugr-core, hugr-model and capnp.) E.g. Visibility::Tag(String), and then NameLinkingPolicy gains consider_as_public(&must self, String).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions