Skip to content

Conversation

@FindHao
Copy link
Member

@FindHao FindHao commented Oct 26, 2025

Summary

This PR fixes a critical bug where the main #loc directive was stored with key "1", which caused a collision with #loc1 when both exist in the same IR file. The fix changes the storage key for the main #loc from "1" to "" (empty string).

Problem

In TTIR/TTGIR files, location directives can appear in two forms:

  • Main directive: #loc = loc("file.py":10:5) (no number suffix)
  • Numbered directives: #loc1 = loc("file.py":20:10), #loc2 = loc("file.py":30:15), etc.

Previously, the main #loc was stored with key "1", which conflicts with #loc1. When both exist, #loc1 would overwrite the main #loc entry, causing incorrect source mapping.

Solution

  • Change the storage key for main #loc from "1" to "" (empty string)
  • Update extract_code_locations() to map bare #loc references to "0" (preserved for backward compatibility)
  • This ensures main #loc and #loc1 are stored separately without collision

Changes

File: tritonparse/ir_parser.py

  • Line 55: locations["1"]locations[""]

Impact

  • Backward compatibility: Maintained - existing code continues to work
  • Bug fix: Resolves incorrect source mappings when both #loc and #loc1 exist
  • Foundation: Prepares for future alias pattern support (PR2)

Testing

Existing tests pass. The change is minimal and focused on the key conflict issue.

Related PRs

  • Next: PR2 will add comprehensive alias parsing support building on this fix
  • Next: PR3 will add frontend UI visualization for location information

Change main #loc storage key from "1" to "" (empty string) to avoid
collision with #loc1. This resolves the issue where #loc1 would
overwrite the main #loc entry when both exist in the IR file.

The main #loc directive appears as `#loc = loc(...)` without a number,
while numbered directives appear as `#loc1 = loc(...)`, `#loc2 = loc(...)`, etc.
Using "" as the key for the main directive prevents conflicts.
@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 26, 2025
@meta-codesync
Copy link

meta-codesync bot commented Oct 27, 2025

@FindHao has imported this pull request. If you are a Meta employee, you can view this in D85571534.

@meta-codesync
Copy link

meta-codesync bot commented Oct 27, 2025

@FindHao merged this pull request in 156ec6b.

@FindHao FindHao deleted the findhao/pr1-new-variable-loc-info branch October 30, 2025 03:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. Merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants