Skip to content

Conversation

@acl-cqc
Copy link
Contributor

@acl-cqc acl-cqc commented Sep 16, 2025

Follows #2529, which is approved, but will merge both without any intervening release.

  • Add insert_link_hugr and insert_link_view taking a node under which to add the entrypoint
  • Add reachability analysis, used for private functions (a change in behaviour from feat: Add method to link Hugr modules (linking pt3 of >=4) #2529), and for public functions when using the new insert_link_xxx
  • Extend NameLinkingPolicy to allow setting how to handle to new names in the source Hugr

closes #2517

Questions remain from previous PR about factory methods for NameLinkingPolicy and whether tests need to be more systematic about covering all the policy variants.

@codecov
Copy link

codecov bot commented Sep 16, 2025

Codecov Report

❌ Patch coverage is 93.65079% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.63%. Comparing base (c0102f2) to head (5ada90b).

Files with missing lines Patch % Lines
hugr-core/src/hugr/linking.rs 93.65% 8 Missing and 4 partials ⚠️
Additional details and impacted files
@@                Coverage Diff                @@
##           acl/link_hugr    #2555      +/-   ##
=================================================
+ Coverage          83.61%   83.63%   +0.01%     
=================================================
  Files                266      266              
  Lines              51951    52054     +103     
  Branches           47370    47520     +150     
=================================================
+ Hits               43441    43533      +92     
- Misses              6133     6140       +7     
- Partials            2377     2381       +4     
Flag Coverage Δ
python 91.53% <ø> (-0.14%) ⬇️
rust 82.87% <93.65%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@acl-cqc acl-cqc changed the title feat: Add insert_link_hugr to add entrypoint subtree AND link feat: (WIP) Add insert_link_hugr to add entrypoint subtree AND link Sep 16, 2025
/// [`OnMultiDefn::NewFunc`] of [`OnNewFunc::RaiseError`]
///
/// [`FuncDefn`]: crate::ops::FuncDefn
/// [`on_new_names`]: NameLinkingPolicy::get_on_new_names
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I should either change the links to be called `get_on_new_names` or write `on_new_names` has been set to ...

github-merge-queue bot pushed a commit that referenced this pull request Nov 18, 2025
Respin of #2531, marking the node/edge enums in the new StaticGraph as
`non-exhaustive` and adding Consts + LoadConstants.

(Lukas originally planned to make something like this to reflect
references from Terms to functions, and non-exhaustive allows extending
this StaticGraph for that purpose - if we do go that way, however, I
have a different plan, can describe if relevant. Rather I think
non-exhaustive is just a reasonable allowance for future extension to
new use-cases hopefully without damaging existing use-cases.)

This is taken from #2555, i.e. which uses it (although there it is still
called CallGraph in hugr-core).

Naming: could be ModuleGraph ?? Other ideas welcome.

I will add a test with some Consts + use of `out_edges` (tho will be
supplied in #2555 !)
@acl-cqc acl-cqc changed the title feat: (WIP) Add insert_link_hugr to add entrypoint subtree AND link feat: insert_link_hugr adds entrypoint subtree and links, with reachability Nov 21, 2025
@acl-cqc acl-cqc force-pushed the acl/insert_link_callgraph branch from 4ce1890 to 46b988c Compare November 21, 2025 20:33
@acl-cqc acl-cqc force-pushed the acl/insert_link_callgraph branch from 46b988c to d0de271 Compare November 22, 2025 08:54
@acl-cqc acl-cqc marked this pull request as ready for review November 25, 2025 11:03
@acl-cqc acl-cqc requested a review from a team as a code owner November 25, 2025 11:03
@acl-cqc acl-cqc requested review from ss2165 and removed request for a team November 25, 2025 11:03
Copy link
Member

@ss2165 ss2165 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

partial review, more to come

///
/// # Errors
///
/// If other's entrypoint is its module-root (recommend using [Self::link_module] instead)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this line be above # Errors ?

/// If other's entrypoint is its module-root (recommend using [Self::link_module] instead)
///
/// If other's entrypoint calls (perhaps transitively) the function containing said entrypoint
/// (an exception is made if the called+containing function is public and is being replaced
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove parentheses for readability

///
/// If other's entrypoint calls a public [`FuncDefn`] in `other` which has the same name
/// and signature as a public [`FuncDefn`] in `self` and [`on_multi_defn`] is
/// [`OnMultiDefn::NewFunc`] of [`OnNewFunc::RaiseError`]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// [`OnMultiDefn::NewFunc`] of [`OnNewFunc::RaiseError`]
/// [`OnMultiDefn::NewFunc`] or [`OnNewFunc::RaiseError`]

/// [`on_new_names`]: NameLinkingPolicy::get_on_new_names
/// [`on_multi_defn`]: NameLinkingPolicy::get_on_multiple_defn
/// [`on_sig_conflict`]: NameLinkingPolicy::get_signature_conflict
#[allow(clippy::type_complexity)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a where block might let you remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite - error: equality constraints are not yet supported in where clauses rust-lang/rust#20041

Ah, but parametrizing by HugrNode type rather than HugrView type does! Done

Comment on lines +1332 to +1335
let reached = mb.declare("foo", endo_sig(usize_t()).into()).unwrap();
// This would conflict signature, but is not reached:
let unreached = mb
.declare("bar", inout_sig(vec![], usize_t()).into())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
let reached = mb.declare("foo", endo_sig(usize_t()).into()).unwrap();
// This would conflict signature, but is not reached:
let unreached = mb
.declare("bar", inout_sig(vec![], usize_t()).into())
let reached = mb.declare("reached", endo_sig(usize_t()).into()).unwrap();
// This would conflict signature, but is not reached:
let unreached = mb
.declare("unreached", inout_sig(vec![], usize_t()).into())

@ss2165 ss2165 self-requested a review November 28, 2025 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants