Ejemplo n.º 1
0
    def _register_task(
        self, tasks, output_type, rule: TaskRule, union_rules: "OrderedDict[Type, OrderedSet[Type]]"
    ) -> None:
        """Register the given TaskRule with the native scheduler."""
        func = Function(self._to_key(rule.func))
        self._native.lib.tasks_task_begin(tasks, func, self._to_type(output_type), rule.cacheable)
        for selector in rule.input_selectors:
            self._native.lib.tasks_add_select(tasks, self._to_type(selector))

        if rule.name:
            self._native.lib.tasks_add_display_info(tasks, rule.name.encode())

        def add_get_edge(product, subject):
            self._native.lib.tasks_add_get(tasks, self._to_type(product), self._to_type(subject))

        for the_get in rule.input_gets:
            if union.is_instance(the_get.subject_declared_type):
                # If the registered subject type is a union, add Get edges to all registered union members.
                for union_member in union_rules.get(the_get.subject_declared_type, []):
                    add_get_edge(the_get.product, union_member)
            else:
                # Otherwise, the Get subject is a "concrete" type, so add a single Get edge.
                add_get_edge(the_get.product, the_get.subject_declared_type)

        self._native.lib.tasks_task_end(tasks)
Ejemplo n.º 2
0
 def _register_task(self, output_constraint, rule):
     """Register the given TaskRule with the native scheduler."""
     func = rule.func
     self._native.lib.tasks_task_begin(self._tasks,
                                       Function(self._to_key(func)),
                                       output_constraint)
     for selector in rule.input_selectors:
         selector_type = type(selector)
         product_constraint = self._to_constraint(selector.product)
         if selector_type is Select:
             self._native.lib.tasks_add_select(self._tasks,
                                               product_constraint)
         elif selector_type is SelectVariant:
             key_buf = self._to_utf8_buf(selector.variant_key)
             self._native.lib.tasks_add_select_variant(
                 self._tasks, product_constraint, key_buf)
         elif selector_type is SelectDependencies:
             self._native.lib.tasks_add_select_dependencies(
                 self._tasks, product_constraint,
                 self._to_constraint(selector.dep_product),
                 self._to_utf8_buf(selector.field),
                 self._to_ids_buf(selector.field_types))
         else:
             raise ValueError(
                 'Unrecognized Selector type: {}'.format(selector))
     for get in rule.input_gets:
         self._native.lib.tasks_add_get(self._tasks,
                                        self._to_constraint(get.product),
                                        TypeId(self._to_id(get.subject)))
     self._native.lib.tasks_task_end(self._tasks)
Ejemplo n.º 3
0
    def _register_task(self, output_type, rule, union_rules):
        """Register the given TaskRule with the native scheduler."""
        func = Function(self._to_key(rule.func))
        self._native.lib.tasks_task_begin(self._tasks, func,
                                          self._to_type(output_type),
                                          rule.cacheable)
        for selector in rule.input_selectors:
            self._native.lib.tasks_add_select(self._tasks,
                                              self._to_type(selector))

        def add_get_edge(product, subject):
            self._native.lib.tasks_add_get(self._tasks, self._to_type(product),
                                           self._to_type(subject))

        for the_get in rule.input_gets:
            union_members = union_rules.get(the_get.subject_declared_type,
                                            None)
            if union_members:
                # If the registered subject type is a union, add Get edges to all registered union members.
                for union_member in union_members:
                    add_get_edge(the_get.product, union_member)
            else:
                # Otherwise, the Get subject is a "concrete" type, so add a single Get edge.
                add_get_edge(the_get.product, the_get.subject_declared_type)

        self._native.lib.tasks_task_end(self._tasks)
Ejemplo n.º 4
0
 def _register_task(self, output_constraint, rule):
   """Register the given TaskRule with the native scheduler."""
   func = Function(self._to_key(rule.func))
   self._native.lib.tasks_task_begin(self._tasks, func, output_constraint, rule.cacheable)
   for selector in rule.input_selectors:
     selector_type = type(selector)
     product_constraint = self._to_constraint(selector.product)
     if selector_type is Select:
       self._native.lib.tasks_add_select(self._tasks, product_constraint)
     else:
       raise ValueError('Unrecognized Selector type: {}'.format(selector))
   for get in rule.input_gets:
     self._native.lib.tasks_add_get(self._tasks,
                                    self._to_constraint(get.product),
                                    TypeId(self._to_id(get.subject)))
   self._native.lib.tasks_task_end(self._tasks)
Ejemplo n.º 5
0
 def with_fork_context(self, func):
     """See the rustdocs for `scheduler_fork_context` for more information."""
     res = self._native.lib.scheduler_fork_context(self._scheduler, Function(self._to_key(func)))
     return self._raise_or_return(res)