Skip to content

Fix build non-determinism in J2ObjC code generator.#2807

Open
copybara-service[bot] wants to merge 1 commit into
masterfrom
test_951131076
Open

Fix build non-determinism in J2ObjC code generator.#2807
copybara-service[bot] wants to merge 1 commit into
masterfrom
test_951131076

Conversation

@copybara-service

Copy link
Copy Markdown

Fix build non-determinism in J2ObjC code generator.

When transpiling Java code to Objective-C via J2ObjC (rule J2objcTranspile), build output could differ across runs due to two issues:

  1. Unordered HashSet instances were used for collecting types, forward declarations, and variables in HeaderImportCollector, ObjectiveCImplementationGenerator, ObjectiveCHeaderGenerator, and VariableRenamer. Using HashSet on TypeElement, VariableElement, TypeMirror, and Import resulted in non-deterministic iteration order based on identity hash codes.
  2. When relative line directives (-g:relative) were enabled, temporary extraction directory paths (/tmp/<random_temp_dir>/...) were emitted into #line directives because /tmp/ paths failed startsWith(cwdPath).

This CL replaces HashSet with LinkedHashSet across these generator passes and updates TypeImplementationGenerator.getSourceFilePath() to strip temporary directory prefixes when -g:relative is set.

When transpiling Java code to Objective-C via J2ObjC (rule J2objcTranspile), build output could differ across runs due to two issues:
1. Unordered HashSet instances were used for collecting types, forward declarations, and variables in HeaderImportCollector, ObjectiveCImplementationGenerator, ObjectiveCHeaderGenerator, and VariableRenamer. Using HashSet on TypeElement, VariableElement, TypeMirror, and Import resulted in non-deterministic iteration order based on identity hash codes.
2. When relative line directives (-g:relative) were enabled, temporary extraction directory paths (/tmp/<random_temp_dir>/...) were emitted into #line directives because /tmp/ paths failed startsWith(cwdPath).

This CL replaces HashSet with LinkedHashSet across these generator passes and updates TypeImplementationGenerator.getSourceFilePath() to strip temporary directory prefixes when -g:relative is set.

PiperOrigin-RevId: 951131076
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant