1
1
//! Bundles of hugr modules along with the extension required to load them.
2
2
3
3
use derive_more:: { Display , Error , From } ;
4
- use itertools:: Itertools ;
5
4
use std:: io;
6
5
7
6
use crate :: envelope:: { read_envelope, write_envelope, EnvelopeConfig , EnvelopeError } ;
8
- use crate :: extension:: { ExtensionId , ExtensionRegistry , PRELUDE_REGISTRY } ;
7
+ use crate :: extension:: { ExtensionRegistry , PRELUDE_REGISTRY } ;
9
8
use crate :: hugr:: { HugrView , ValidationError } ;
10
9
use crate :: { Hugr , Node } ;
11
10
@@ -23,24 +22,25 @@ pub struct Package {
23
22
impl Package {
24
23
/// Create a new package from a list of hugrs.
25
24
///
26
- /// Collects the extensions used in the modules and stores them in top-level
27
- /// `extensions` attribute.
25
+ /// The hugr extensions are not automatically added to the package. Make
26
+ /// sure to manually include any non-standard extensions to
27
+ /// [`Package::extensions`].
28
28
pub fn new ( modules : impl IntoIterator < Item = Hugr > ) -> Self {
29
29
let modules: Vec < Hugr > = modules. into_iter ( ) . collect ( ) ;
30
- let mut extensions = ExtensionRegistry :: default ( ) ;
31
- for module in & modules {
32
- extensions. extend ( module. extensions ( ) ) ;
33
- }
34
30
Self {
35
31
modules,
36
- extensions,
32
+ extensions : ExtensionRegistry :: default ( ) ,
37
33
}
38
34
}
39
35
40
36
/// Create a new package containing a single HUGR.
37
+ ///
38
+ /// The hugr extensions are not automatically added to the package. Make
39
+ /// sure to manually include any non-standard extensions to
40
+ /// [`Package::extensions`].
41
41
pub fn from_hugr ( hugr : Hugr ) -> Self {
42
42
Package {
43
- extensions : hugr . extensions ( ) . clone ( ) ,
43
+ extensions : ExtensionRegistry :: default ( ) ,
44
44
modules : vec ! [ hugr] ,
45
45
}
46
46
}
@@ -51,19 +51,6 @@ impl Package {
51
51
pub fn validate ( & self ) -> Result < ( ) , PackageValidationError > {
52
52
for hugr in self . modules . iter ( ) {
53
53
hugr. validate ( ) ?;
54
-
55
- let missing_exts = hugr
56
- . extensions ( )
57
- . ids ( )
58
- . filter ( |id| !self . extensions . contains ( id) )
59
- . cloned ( )
60
- . collect_vec ( ) ;
61
- if !missing_exts. is_empty ( ) {
62
- return Err ( PackageValidationError :: MissingExtension {
63
- missing : missing_exts,
64
- available : self . extensions . ids ( ) . cloned ( ) . collect ( ) ,
65
- } ) ;
66
- }
67
54
}
68
55
Ok ( ( ) )
69
56
}
@@ -126,18 +113,6 @@ impl AsRef<[Hugr]> for Package {
126
113
#[ derive( Debug , Display , From , Error ) ]
127
114
#[ non_exhaustive]
128
115
pub enum PackageValidationError {
129
- /// Error raised while processing the package extensions.
130
- #[ display( "The package modules use the extension{} {} not present in the defined set. The declared extensions are {}" ,
131
- if missing. len( ) > 1 { "s" } else { "" } ,
132
- missing. iter( ) . map( |id| id. to_string( ) ) . collect:: <Vec <_>>( ) . join( ", " ) ,
133
- available. iter( ) . map( |id| id. to_string( ) ) . collect:: <Vec <_>>( ) . join( ", " ) ,
134
- ) ]
135
- MissingExtension {
136
- /// The missing extensions.
137
- missing : Vec < ExtensionId > ,
138
- /// The available extensions.
139
- available : Vec < ExtensionId > ,
140
- } ,
141
116
/// Error raised while validating the package hugrs.
142
117
Validation ( ValidationError < Node > ) ,
143
118
}
0 commit comments