concretizer: make _condtion_id_counter an iterator
This commit is contained in:
		 Todd Gamblin
					Todd Gamblin
				
			
				
					committed by
					
						 Tamara Dahlgren
						Tamara Dahlgren
					
				
			
			
				
	
			
			
			 Tamara Dahlgren
						Tamara Dahlgren
					
				
			
						parent
						
							9bb0375443
						
					
				
				
					commit
					66376ab971
				
			| @@ -463,7 +463,7 @@ def __init__(self): | |||||||
| 
 | 
 | ||||||
|         # id for dummy variables |         # id for dummy variables | ||||||
|         self.card = 0 |         self.card = 0 | ||||||
|         self._condition_id_counter = 0 |         self._condition_id_counter = itertools.count() | ||||||
| 
 | 
 | ||||||
|         # Caches to optimize the setup phase of the solver |         # Caches to optimize the setup phase of the solver | ||||||
|         self.target_specs_cache = None |         self.target_specs_cache = None | ||||||
| @@ -557,12 +557,11 @@ def conflict_rules(self, pkg): | |||||||
|                 clauses = [x for x in clauses if x.name not in to_be_filtered] |                 clauses = [x for x in clauses if x.name not in to_be_filtered] | ||||||
| 
 | 
 | ||||||
|                 # Emit facts based on clauses |                 # Emit facts based on clauses | ||||||
|                 cond_id = self._condition_id_counter |                 condition_id = next(self._condition_id_counter) | ||||||
|                 self._condition_id_counter += 1 |                 self.gen.fact(fn.conflict(condition_id, pkg.name)) | ||||||
|                 self.gen.fact(fn.conflict(cond_id, pkg.name)) |  | ||||||
|                 for clause in clauses: |                 for clause in clauses: | ||||||
|                     self.gen.fact(fn.conflict_condition( |                     self.gen.fact(fn.conflict_condition( | ||||||
|                         cond_id, clause.name, *clause.args |                         condition_id, clause.name, *clause.args | ||||||
|                     )) |                     )) | ||||||
|                 self.gen.newline() |                 self.gen.newline() | ||||||
| 
 | 
 | ||||||
| @@ -702,14 +701,13 @@ def package_dependencies_rules(self, pkg, tests): | |||||||
|         """Translate 'depends_on' directives into ASP logic.""" |         """Translate 'depends_on' directives into ASP logic.""" | ||||||
|         for _, conditions in sorted(pkg.dependencies.items()): |         for _, conditions in sorted(pkg.dependencies.items()): | ||||||
|             for cond, dep in sorted(conditions.items()): |             for cond, dep in sorted(conditions.items()): | ||||||
|                 global_condition_id = self._condition_id_counter |                 condition_id = next(self._condition_id_counter) | ||||||
|                 self._condition_id_counter += 1 |  | ||||||
|                 named_cond = cond.copy() |                 named_cond = cond.copy() | ||||||
|                 named_cond.name = named_cond.name or pkg.name |                 named_cond.name = named_cond.name or pkg.name | ||||||
| 
 | 
 | ||||||
|                 # each independent condition has an id |                 # each independent condition has an id | ||||||
|                 self.gen.fact(fn.dependency_condition( |                 self.gen.fact(fn.dependency_condition( | ||||||
|                     global_condition_id, dep.pkg.name, dep.spec.name |                     condition_id, dep.pkg.name, dep.spec.name | ||||||
|                 )) |                 )) | ||||||
| 
 | 
 | ||||||
|                 for t in sorted(dep.type): |                 for t in sorted(dep.type): | ||||||
| @@ -723,13 +721,13 @@ def package_dependencies_rules(self, pkg, tests): | |||||||
|                         continue |                         continue | ||||||
| 
 | 
 | ||||||
|                     # there is a declared dependency of type t |                     # there is a declared dependency of type t | ||||||
|                     self.gen.fact(fn.dependency_type(global_condition_id, t)) |                     self.gen.fact(fn.dependency_type(condition_id, t)) | ||||||
| 
 | 
 | ||||||
|                 # if it has conditions, declare them. |                 # if it has conditions, declare them. | ||||||
|                 conditions = self.spec_clauses(named_cond, body=True) |                 conditions = self.spec_clauses(named_cond, body=True) | ||||||
|                 for cond in conditions: |                 for cond in conditions: | ||||||
|                     self.gen.fact(fn.required_dependency_condition( |                     self.gen.fact(fn.required_dependency_condition( | ||||||
|                         global_condition_id, cond.name, *cond.args |                         condition_id, cond.name, *cond.args | ||||||
|                     )) |                     )) | ||||||
| 
 | 
 | ||||||
|                 # add constraints on the dependency from dep spec. |                 # add constraints on the dependency from dep spec. | ||||||
| @@ -751,7 +749,7 @@ def package_dependencies_rules(self, pkg, tests): | |||||||
|                     clauses = self.spec_clauses(dep.spec) |                     clauses = self.spec_clauses(dep.spec) | ||||||
|                     for clause in clauses: |                     for clause in clauses: | ||||||
|                         self.gen.fact(fn.imposed_dependency_condition( |                         self.gen.fact(fn.imposed_dependency_condition( | ||||||
|                             global_condition_id, clause.name, *clause.args |                             condition_id, clause.name, *clause.args | ||||||
|                         )) |                         )) | ||||||
| 
 | 
 | ||||||
|                 self.gen.newline() |                 self.gen.newline() | ||||||
| @@ -821,21 +819,22 @@ def external_packages(self): | |||||||
|                 )) |                 )) | ||||||
| 
 | 
 | ||||||
|             for local_idx, spec in enumerate(external_specs): |             for local_idx, spec in enumerate(external_specs): | ||||||
|                 global_id = self._condition_id_counter |                 condition_id = next(self._condition_id_counter) | ||||||
|                 self._condition_id_counter += 1 |  | ||||||
| 
 | 
 | ||||||
|                 # Declare the global ID associated with this external spec |                 # Declare the global ID associated with this external spec | ||||||
|                 self.gen.fact(fn.external_spec(global_id, pkg_name)) |                 self.gen.fact(fn.external_spec(condition_id, pkg_name)) | ||||||
| 
 | 
 | ||||||
|                 # Local index into packages.yaml |                 # Local index into packages.yaml | ||||||
|                 self.gen.fact(fn.external_spec_index(global_id, pkg_name, local_idx)) |                 self.gen.fact( | ||||||
|  |                     fn.external_spec_index(condition_id, pkg_name, local_idx)) | ||||||
| 
 | 
 | ||||||
|                 # Add conditions to be satisfied for this external |                 # Add conditions to be satisfied for this external | ||||||
|                 self.possible_versions[spec.name].add(spec.version) |                 self.possible_versions[spec.name].add(spec.version) | ||||||
|                 clauses = self.spec_clauses(spec, body=True) |                 clauses = self.spec_clauses(spec, body=True) | ||||||
|                 for clause in clauses: |                 for clause in clauses: | ||||||
|                     self.gen.fact( |                     self.gen.fact( | ||||||
|                         fn.external_spec_condition(global_id, clause.name, *clause.args) |                         fn.external_spec_condition( | ||||||
|  |                             condition_id, clause.name, *clause.args) | ||||||
|                     ) |                     ) | ||||||
|                 self.gen.newline() |                 self.gen.newline() | ||||||
| 
 | 
 | ||||||
| @@ -1335,7 +1334,8 @@ def setup(self, driver, specs, tests=False): | |||||||
|             specs (list): list of Specs to solve |             specs (list): list of Specs to solve | ||||||
| 
 | 
 | ||||||
|         """ |         """ | ||||||
|         self._condition_id_counter = 0 |         self._condition_id_counter = itertools.count() | ||||||
|  | 
 | ||||||
|         # preliminary checks |         # preliminary checks | ||||||
|         check_packages_exist(specs) |         check_packages_exist(specs) | ||||||
| 
 | 
 | ||||||
| @@ -1499,7 +1499,7 @@ def node_flag_source(self, pkg, source): | |||||||
|     def no_flags(self, pkg, flag_type): |     def no_flags(self, pkg, flag_type): | ||||||
|         self._specs[pkg].compiler_flags[flag_type] = [] |         self._specs[pkg].compiler_flags[flag_type] = [] | ||||||
| 
 | 
 | ||||||
|     def external_spec_selected(self, global_id, pkg, idx): |     def external_spec_selected(self, condition_id, pkg, idx): | ||||||
|         """This means that the external spec and index idx |         """This means that the external spec and index idx | ||||||
|         has been selected for this package. |         has been selected for this package. | ||||||
|         """ |         """ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user