o
    qoi\                     @   s   d Z ddlmZ ddlmZ ddlmZ ddlm	Z	 ddlm
Z
 ddlmZ ejZejZde	jd	d
fddZedde	jdede	jf d	d
fddZd
S )zChanges callables to symbol references for non-auto_config codegen.

N.B. Please see codegen/auto_config for the auto_config version!!
    )Callable)daglish)config)code_ir)import_manager_wrapper)make_symbolic_referencestaskreturnNc                 C   s   t | j D ]9\}}t|tjr7| jt	| | jt
| |j D ]}|D ]}| j| q,q(qt|rA| j| qdS )zPass that just adds imports for symbols.

  It can be useful to run this pass early, so that other naming passes don't
  generate names which conflict with imports.

  Args:
    task: Codegen task.
  N)r   iteratetop_level_callall_fixture_functions
isinstance
config_lib	Buildableimport_manageraddtypeget_callable__argument_tags__valuesis_plain_symbol_or_enum_value)r   value_arg_tagstag r   a/home/ubuntu/.local/lib/python3.10/site-packages/fiddle/_src/codegen/newcg_symbolic_references.pyimport_symbols#   s   
r   )format_historyr   .c                   s>   dt jf fdd}j D ]}|t j|| qdS )a  Replaces callables and Buildables with symbolic versions.

  Args:
    task: Codegen task.
    format_history: Function used to format history for a buildable. Set to
      get_history_comments.format_history_for_buildable (or a functools.partial
      variant) to populate histories.
  statec              	      s   t | tjrctt| j}tt| j}| j}|	| } |
 D ].\}}fdd|D }|| jvrFtd| d| d| j dtj|| j| d| j|< q%tj||gt|  | dS t| rnt| jS |	| S )	Nc                    s   g | ]} j |qS r   )r   r   ).0r   )r   r   r   
<listcomp>V   s    zPreplace_callables_and_configs_with_symbols.<locals>.traverse.<locals>.<listcomp>zTagged field 'z' of z  is not found in its arguments: z. This is likely because the tagged field doesn't yet have a value. Consider assigning a value to the field first or removing field tags from your config, for example using `fdl.clear_tags`.)tag_symbol_expressionsitem_to_tag)symbol_expressionpositional_arg_expressionsarg_expressionshistory_comments)r   r   r   r   r   r   r   r   r   map_childrenitems__arguments__
ValueErrorr   WithTagsCallSymbolOrFixtureCallordered_argumentsr   )r   r   ir_for_buildable_typeir_for_symbolall_tagsargr   tag_exprr   r   r   r   traverseK   s<   



z<replace_callables_and_configs_with_symbols.<locals>.traverseN)r   Stater   r   replace_withMemoizedTraversalrun)r   r   r5   fnr   r4   r   *replace_callables_and_configs_with_symbols;   s   #r;   )__doc__typingr   fiddler   fiddle._srcr   r   fiddle._src.codegen.auto_configr   r   r   ac_make_symbolic_referencesr   noop_history_commentsCodegenTaskr   HistoryCommentsr;   r   r   r   r   <module>   s*   